Toggle
Motion-first toggle switch with sliding thumb animation, press squish effect, and iOS-style physics. Supports controlled and uncontrolled usage.
Input
Off
Disabled
Installation
Copy and paste
Copy the component source code and paste it into your project.
import { Toggle } from "driftkit";Props
| Name | Type | Required | Description |
|---|---|---|---|
checked | boolean | No | Controlled checked state. Use with onChange for controlled toggles. |
defaultChecked | boolean | No | Default checked state for uncontrolled usage. |
onChange | (checked: boolean) => void | No | Callback when toggle state changes. Receives the new checked state. |
size | "sm" | "md" | "lg" | No | Toggle size. Small (36x20px), medium (44x24px), large (56x30px). |
disabled | boolean | No | Disables the toggle and reduces opacity. Prevents interactions. |
🎮
Playground
Tune spring physics for this component
Live Preview
Spring Physics
300
30
1
Generated Code
const springConfig = {
"type": "spring",
"stiffness": 300,
"damping": 30,
"mass": 1
};
// Basic hover animation
<motion.div
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
transition={springConfig}
>
<Toggle />
</motion.div>
// Advanced with custom animations
<motion.div
animate={{
scale: [1, 1.02, 1],
y: [0, -4, 0]
}}
transition={{
...springConfig,
repeat: Infinity,
repeatDelay: 2
}}
>
<Toggle />
</motion.div>Stiffness: Controls animation speed. Higher values create snappier animations.
Damping: Controls resistance to motion. Lower values create more bounce and overshoot.
Mass: Controls the perceived weight. Higher values make animations slower with more momentum.
Source Code
View the source code on GitHub to see the full implementation.
View on GitHub