Animated Switch

A precise switch, engineered with motion physics. Beauty in every pixel. Seamless by default. Use the live controls below to explore controlled/uncontrolled modes, stress tests, and why extra className that alters sizing will break the switch's internal geometry.

Built-in spring motionFine-tuned physics (stiffness:500)Pixel-perfect handle movement
Basic
Features

Controlled & uncontrolled modes

Supports both controlled and uncontrolled state management approaches.

Real-time onValueChange callbacks

Emits value updates instantly through callback events.

Custom onIcon & offIcon

Allows custom icons for both active and inactive states.

Motion layout + spring (stiffness: 500, damping: 35)

Smooth physical motion powered by a configurable spring animation.

Smooth precise translation from left: 4px to left: 44px

Provides a precise and fluid knob translation across the track.

Installation
Works with npm, pnpm, yarn, and bun

$npx libravelui@latest add animated-switch

Anatomy
import { AnimatedSwitch } from "@/components/ui/motion/animated-switch";<AnimatedSwitch />
Testing Playground
Custom Icon
Broken — example of dangerous className
This demonstrates what happens if you apply sizing/padding classes that alter the switch's internal geometry. **Do not do this in production.**
Result

Offset handle Clipping Unnatural motion

The handle expects exact container geometry (4px → 44px). Changing width/height/padding displaces it.

Props

Loading types…