A toggle for on/off settings.
$ pnpm dlx shadcn@latest add https://dashral.com/r/switch.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/switch.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
components.json
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/switchUsage
example.tsx
import { Switch } from "@/components/dashral/switch"
<Switch label="Email notifications" description="A summary every Monday." defaultChecked />Examples
Notification settings
Email and push per topic, saved as you go; pausing disables the rows and keeps what was picked.
API reference
Switch
Also takes every prop of Radix Switch(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
checked / defaultChecked | boolean | — |
onCheckedChange | (checked: boolean) => void | — |
label | ReactNodeBeside the control; clicking it works the control. | — |
description | ReactNodeA hint under the label. | — |
color | "primary" | "neutral" | "info" | "success" | "warning" | "destructive" | "highlight"The color when on, ticked or picked. | "primary" |
labelPosition | "end" | "start""start" puts the label first and the switch at the far end, as in a settings row. | "end" |
error | boolean | ReactNodeA message shows under the label. | — |
classNames | { root, label, description, error, switch }Classes for each part. | — |
Keyboard
| Keys | Action |
|---|---|
| SpaceorEnter | Toggle |
Accessibility
- role="switch" with aria-checked; the change should take effect immediately.
- Give it a label (or an aria-label); the description is linked through aria-describedby.
Motion
- The thumb springs across (--ease-spring).