Switch

A switch whose thumb stretches 3/16 and lands softly.

switch.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/switch.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/switch.json

3

Turn on the motion

npx @prequelui/cli@latest animate switch

The 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.

switch.tsx
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.
spring 300 / 25stretch 26 pxtravel 20 pxcolour 200 ms

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

PropTypeDefault
checkedboolean—
defaultCheckedbooleanfalse
onCheckedChange(checked: boolean) => void—
disabledbooleanfalse
classNamestring—

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026