A switch whose thumb stretches 3/16 and lands softly.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/switch.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/switch.json
Turn on the motion
npx @prequelui/cli@latest animate switchThe CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { Switch } from "@/components/prequelui/switch";
export default function Demo() {
return (
<label className="flex items-center gap-3 text-[13.5px]">
<Switch defaultChecked onCheckedChange={(checked) => console.log(checked)} />
Enable notifications
</label>
);
}import { Switch } from "@/components/prequelui/switch";
export function Variant() {
return (
<Switch tempo={1.2}>
…
</Switch>
);
}Animation
The thumb does not simply travel: it stretches in the direction of the press and settles back to its resting width as it lands. The track changes colour in the same 200 ms so the state is never ambiguous.
- Thumb spring: 300 / 25; travel 20 px on a 44 px track.
- The thumb widens to 26 px while pressed, then returns to 20 px.
- The track colour crossfades in 200 ms.
- Reduced motion jumps the thumb and keeps the colour change.
API Reference
Every part takes exactly the props of the Switch primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.
Switch
| Prop | Type | Default |
|---|---|---|
| checked | boolean | — |
| defaultChecked | boolean | false |
| onCheckedChange | (checked: boolean) => void | — |
| disabled | boolean | false |
| className | string | — |