Toggle
Switches a setting that takes effect the moment it flips.
Configurations
Supported configurations for this component.
States
Interaction states covered by the API and the style contract.
Configurations
2 examplesStates
5 examplesAdd to your project
One command adds this component to your project.
Run the following command. New project? Run npx shadcn@latest init first to set up Tailwind and path aliases.
npx shadcn@latest add @aicanvas/••••••••••••Light and dark both come with the install and follow the dark class on <html>, the shadcn dark mode setup (next-themes with attribute="class").
Props
Every prop this component accepts. Any other prop is forwarded to the underlying element.
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | Controlled checked state; supplying it puts the switch in controlled mode. |
| defaultChecked | boolean | false | Initial checked state when uncontrolled. |
| onCheckedChange | (next: boolean) => void | - | Handler called with the next checked state whenever the switch toggles. |
| label | string | - | Optional text rendered beside the switch and linked to it via htmlFor. |
| size | 'sm'|'md'|'lg' | 'md' | Three rungs, 34x18 / 42x22 / 50x26, scaling the track, thumb travel and label together. Checkbox and Radio carry two rungs. |
| disabled | boolean | false | Disables interaction and dims the switch. |
| className | string | - | Extra classes merged onto the visual track. |
| style | React.CSSProperties | - | Inline styles merged onto the wrapper element. |
| id | string | - | Id for the input; falls back to a generated id and links the label. |