ui · Primitive
Switch
@devalok/shilp-sutra/ui/switchView in Storybook Hand-curated previews ship in rolling waves. See it live in Storybook →
Reference
Props
checked: boolean
onCheckedChange: (checked: boolean) => void
error: boolean (shows red border/bg)
disabled: boolean
size: "sm" | "md" | "lg"
color: "accent" | "success" | "warning"
thumbIcon: ReactNode (icon rendered inside the thumb)
Defaults
size="md", color="accent"
Example
<Switch checked={enabled} onCheckedChange={setEnabled} />
<Switch size="lg" color="success" thumbIcon={<IconCheck size={14} />} />
Composability
- Radix Switch primitive —
checked/onCheckedChange/defaultCheckedstandard control model. - FormField: Switch does NOT auto-consume FormField state (same as Checkbox/Radio — form-library convention for toggles). Pass
errorexplicitly when needed. - thumbIcon slot: Any ReactNode renders inside the thumb circle — commonly used for check/X glyphs that animate with the thumb position.
- Label pairing: Manual — pair with
<Label htmlFor="x" />+<Switch id="x" />, or wrap both in a<label>for click-to-toggle. - Pair with FormHelperText (outside FormField wiring) for custom validation messages.
Gotchas
- Use error prop for validation states (matches Checkbox API)
erroroverridescolor— when error is true, checked state always uses error-9- Switch does NOT auto-consume FormField — pass
errorexplicitly inside a FormField
Changes
v0.29.0
- Added
sizeprop:"sm"(18px track) |"md"(24px, default) |"lg"(28px track) - Added
colorprop:"accent"(default) |"success"|"warning"for checked-state color - Added
thumbIconprop — renders any ReactNode inside the thumb circle (e.g., check icon)
v0.18.0
- Changed Migrated to Framer Motion spring thumb animation
- Fixed Added visible border on unchecked state (
border-surface-border-strong) — was borderless, making unchecked state hard to see
v0.4.2
- Fixed
React.ComponentRefchanged toReact.ElementReffor consistency
v0.3.0
- Added
SwitchPropstype export - Added
errorprop (matches Checkbox API)
v0.1.0
- Added Initial release