Animated Switch
An interactive, iOS-style "squish" switch built on Base UI Switch primitives. Press feedback stretches the thumb toward its travel direction, then releases into a short spring transition.
Features
- Purposeful Press Feedback — The thumb subtly stretches on pointer-down and resets on release, cancellation, or lost capture.
- Responsive Motion — Uses Sona's shared feedback spring, so its timing stays consistent with other interactive components.
- Standard Sizes — Out-of-the-box support for
sm,md, andlgsizes. - Base UI Integration — Fully keyboard-navigable and accessible with standard button attributes.
- RSC Safe — Renders cleanly as a static element on the server and hydrates client-side animations.
- Reduced Motion — Uses an immediate state change when the user requests less motion.
Playground
Test sizes and interactions live.
Installation
Usage
Examples
Sizes
Animated Switch supports three pre-configured sizes: sm, md, and lg.
sm
md
lg
Controlled State
Wire up the switch using the checked and onCheckedChange props to control it via external react state.
Controlled State: OFF
Disabled
Toggle the disabled prop to deactivate interaction while preserving styles.
Disabled Off
Disabled On
Props
| Property | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Controlled checked state. |
defaultChecked | boolean | false | Initial checked state for uncontrolled usage. |
onCheckedChange | (checked: boolean) => void | — | Callback fired when the checked state changes. |
disabled | boolean | false | Whether the switch is disabled. |
size | "sm" | "md" | "lg" | "md" | The size of the switch. |
className | string | — | Additional classes for the switch track. |