Skip to content
Klarhimmel UI

Switch

npx shadcn add @klarhimmel/switch

Examples

  • Basic

  • Off, and disabled

DetailsAbout, usage, props and more

An on/off control for settings that apply right away. Built on Radix 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>
  );
}

Import

Import

import { Switch } from '@/components/klarhimmel/ui/switch';
Files
switch.tsx, in components/klarhimmel/ui/. With it: theme, utils.
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.

Props

PropTypeDefaultDescription
namestring-
defaultCheckedbooleanfalseControlled or uncontrolled state.
checkedboolean-Controlled or uncontrolled state.
onCheckedChange(checked: boolean) => void-Called when the state changes.
valuestring'on'
requiredboolean-
native attributesButtonHTMLAttributes-Every native attribute of the element passes through, className included.

Accessibility

KeyDoes
SpaceTurns it on or off
TabMoves focus