Default
Flip it: the marker fills the track and the paper coin slides across. The label toggles it too.
An on/off switch drawn as one clean felt pill: the terracotta marker fills the track when it is on, and a paper coin for a thumb slides across. Radix Switch underneath.
npx shadcn@latest add @wobko/switchFirst time here? Add the registry to components.json first. How to install
Flip it: the marker fills the track and the paper coin slides across. The label toggles it too.
Default and sm, off and on, invalid (red pencil outline that stays red when it is on) and disabled (dashed pencil, graphite fill). The thumb's side and the fill carry the state, so it never rests on color alone.
The usual settings page: a title and a line of help on the left, the switch at the end. Hovering anywhere on a row lights its switch (the row is a `group/field`).
With a name (and optional value) a switch submits like a native checkbox: on gives "on" or its value, off sends nothing. Controlled here, so the summary follows it.
Official `switch-demo`: a switch and its label. Flip it and the marker fills the track while the paper coin slides across; the label toggles it too. Only the id is prefixed, so it stays unique on a page with other examples.
Radix Switch.Root (a <button role="switch">, plus Radix's hidden checkbox inside a form) with the track drawn behind it and the thumb (data-slot="switch-thumb") inside. On, hover, focus and pressed follow the element's state in CSS, so a click never redraws anything.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "sm" | "default" | 44 x 24 px or 36 x 20 px (calm density always uses the small one). The thumb and its travel follow the size through two custom properties. |
| checked | boolean | - | Controlled state. |
| defaultChecked | boolean | - | Initial state when uncontrolled. |
| onCheckedChange | (checked: boolean) => void | - | Called on click, Space and Enter. |
| disabled | boolean | false | Dashed pencil track on a graphite wash. Not focusable, no hover. |
| aria-invalid | boolean | "true" | "false" | - | true draws the outline in red pencil, and keeps it red on top of the fill when the switch is on. |
| name / value / required / form | string | boolean | - | Forwarded to Radix's hidden input: on submits "on" (or `value`), off submits nothing. |
| seed | string | number | - | Pins the hand: the same seed always draws the same track and coin. Default: derived from useId(). |
The files the CLI copies into your project.
Loading the source