Switch
An on/off toggle whose knob swells into a clear lens while it crosses the track.
Latest changeImprovedv1.3.8A color prop for the track while on. The examples are now the switch in a few colours, nothing else.
- v1.3.8ImprovedA
colorprop for the track while on. The examples are now the switch in a few colours, nothing else. - v1.3.3ImprovedExamples: a settings list with a disabled switch, the three sizes and the label on either side.
- v1.3.0NewThe switch of the first previews: its knob swells into clear glass as it crosses the track.
- All changes →
switch.tsx
Use it for
- A setting that takes effect at once: Wi-Fi, notifications, dark mode.
Not for
- A choice that is saved later with a form: use Checkbox.
- More than two states: use Tabs.
Installation
npx shadcn@latest add https://onemorethink.dev/r/switch.jsonNo dependenciesOr copy the files by hand →
Usage
app.tsx
import { Switch } from '@/components/liquid-glass/controls/Switch'
const [on, setOn] = useState(false)
<Switch label="Notifications" description="Banners and sounds" checked={on} onChange={setOn} />Tap to flip, or hold the knob and drag it across. Needs three and UI SDK, like Slider.
API reference
| Prop | Type | Default |
|---|---|---|
checkedOn or off. | boolean | false |
onChangeCalled with the new state. | (checked: boolean) => void | — |
labelText beside the switch; an empty string leaves the switch alone. | string | 'Notifications' |
descriptionA second, quieter line under the label. | string | — |
nameSubmits with the form around it under this name. | string | — |
labelSideWhich side the label sits on. | 'left' | 'right' | 'right' |
sizeTrack height 22, 28 or 36 px. | 'sm' | 'md' | 'lg' | 'md' |
colorThe track while on: a hex, | string | '#3291FF' |
themeOverrides the page theme for this switch. | 'light' | 'dark' | — |
disabledDimmed and not interactive. | boolean | false |
lensScaleSize of the travelling lens relative to the resting knob. | number | 1.55 |
refraction / knobBounceHow far the lens bends the track; how much the knob overshoots. | number | 26 / 0.3 |
Accessibility
- A
<button role="switch">witharia-checked: Space and Enter flip it. - The
labelis a real<label>tied to the button. - With reduced motion the knob simply jumps.