Klarhimmel UI

Switch

Stable

An on/off control for settings that apply right away. Built on Radix Switch.

npx shadcn add @klarhimmel/switch

When to use

  • Use for

    A setting that takes effect immediately.

  • Not for

    Choices that wait for a Save button. Use a checkbox.

  • Pairs with

    Settings lists, a visible label.

Preview

switch.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Switch } from '@/components/klarhimmel/ui/switch';

export default function Example() {
  return (
    <Theme theme="brand">
      <label className="flex items-center gap-3">
        <Switch defaultChecked /> Email me when something ships
      </label>
    </Theme>
  );
}

Install

Import

import { Switch } from '@/components/klarhimmel/ui/switch';
Lands in
components/klarhimmel/ui/switch.tsx, plus cn() and the theme item if they are missing. Import theme.css after Tailwind.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

API reference

PropTypeDefaultDescription
checked / defaultCheckedboolean-Controlled or uncontrolled state.
onCheckedChange(checked: boolean) => void-Called when the state changes.
disabledbooleanfalsePrevents interaction.
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
SpaceTurns it on or off
TabMoves focus