Switch
A switch whose knob lifts into a lens as it slides. Drag it, flick it or tap it.
Installation#
$ pnpm dlx shadcn@latest add @liquikit/switchNeeds the @liquikit registry in your components.json. Set it up once.
Usage#
import { Switch } from "@/components/liquikit/switch"<Switch defaultChecked aria-label="Wi-Fi" />Wrap it in a label, or give it an aria-label, so it has an accessible name.
Examples#
Controlled#
Pass checked and onCheckedChange to keep the state yourself.
Airplane mode is off
Sizes#
The track takes any width and height. The knob and the lens scale with it.
API Reference#
Switch
| Prop | Type | Default |
|---|---|---|
theme | "light" | "dark"Light or dark glass. Falls back to the nearest | — |
lens | Partial<LensProfile>Overrides for the lens profile, such as | — |
liquid | numberHow far the glass squashes and stretches as it moves. | — |
onCheckedChange | (checked: boolean, eventDetails?: BaseSwitch.Root.ChangeEventDetails) => voidCalled with the new state when the switch flips. | — |
width | numberWidth of the track, in pixels. | 74 |
height | numberHeight of the track, in pixels. | 28 |
Also takes every prop of Base UI's switch, plus className and style.