Components
Switch
An on/off switch with a sliding knob.
<Switch label="Wi-Fi" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/switch.jsonimport { Switch } from "@/components/switch"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
An on/off switch with a sliding knob. It's a button with role="switch", so screen readers announce it as on or off.
import { Switch } from "@/components/switch";
export function WifiSetting() {
return <Switch label="Wi-Fi" defaultChecked onChange={(on) => console.log(on)} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | The label. | |
defaultChecked | boolean | false | Starting state. |
checked | boolean | Controls the state. | |
onChange | (checked: boolean) => void | Called when it flips. | |
color | string | "#16a34a" | Track colour when on. |
disabled | boolean | false | Disables it. |
className | string | Classes for the wrapper. |
With reduced motion, the knob moves without sliding.