Install
Pull Switch from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { Switch } from "@brika/clay";import { Switch } from "@brika/clay/components/switch";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
'use client';
import { Switch } from '@brika/clay/components/switch';
/** Uncontrolled switch in its default on state. */
export default function SwitchDefaultDemo() {
return <Switch defaultChecked />;
}Switch, every way
Controlled
Controlled switch with live state label next to it.
Disabled
Disabled switch states, both checked and unchecked.
Label
Switch paired with a Label, clicking the label text also toggles the switch.
Settings Row
Settings row pattern, switch with a title and description label.
Accessibility
- Carries
role="switch"witharia-checked, AT announces "on" / "off" state. - Pair with a
<Label>, clicking the label also toggles the switch. - Disabled switches carry
aria-disabledand are removed from the tab order. - Use
Switchfor binary on/off settings; useCheckboxfor multi-select form fields.
Theme tokens
Every CSS variable Switch reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Switch
without touching component code.
Switch tokens
11 tokens--switch-checked-containercolorvar(--primary)components.switch.checkedContainerTrack background when the switch is on (`data-[state=checked]`).
--switch-unchecked-containercolorvar(--input)components.switch.uncheckedContainerTrack background when the switch is off (`data-[state=unchecked]`). Dark mode applies an 80% opacity automatically.
--switch-focus-bordercolorvar(--ring)components.switch.focusBorderBorder color drawn on the track when keyboard focus lands on the switch (`focus-visible`). Pairs with `focus-ring` to render the focus halo.
--switch-focus-ringcolorvar(--ring)components.switch.focusRingColor of the 3px focus halo painted around the switch on `focus-visible`. Rendered at 50% opacity to soften the outer glow.
--switch-track-widthsize2.5remcomponents.switch.trackWidthSwitch track width. Fits two thumb diameters + padding + border.
--switch-track-heightsize1.5remcomponents.switch.trackHeightSwitch track height. Leaves room for thumb + padding + border.
--switch-radiusradius9999pxcomponents.switch.radiusSwitch track corner radius. Default is fully rounded.
--switch-border-widthborder-width0pxcomponents.switch.borderWidthBorder width on the switch. Set non-zero for outline-style variants.
--switch-border-styleborder-stylesolidcomponents.switch.borderStyleBorder style on the switch (`solid`, `dashed`, `double`, `none`).
--switch-durationdurationvar(--motion-standard-duration)components.switch.durationTransition duration for switch state changes.
--switch-easingeasingvar(--motion-standard-easing)components.switch.easingTransition easing for switch state changes.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.switch, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"switch": {
"radius": "9999px"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-switch-…) — see the
chips on each token row.
API reference
Props specific to Switch. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.
- sizedefault
'default''sm' | 'default'Preset size for the switch track and thumb.