Switch
npx shadcn add @klarhimmel/switchCopy for AIExamples
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
Import
Import
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | - | |
defaultChecked | boolean | false | Controlled or uncontrolled state. |
checked | boolean | - | Controlled or uncontrolled state. |
onCheckedChange | (checked: boolean) => void | - | Called when the state changes. |
value | string | 'on' | |
required | boolean | - | |
native attributes | ButtonHTMLAttributes | - | Every native attribute of the element passes through, className included. |