Spring toggle
Toggle switch with spring-physics overshoot on the thumb. Track fills with cursor-mapped pastel colour when on. The border glows only while you point at it.
- Spring Physics
- requestAnimationFrame
- pastelColour
spring-toggle
Notifications
Dark mode
Beta features
Click to toggle. Move your cursor near the track.
Usage
Drop it in
import { SpringToggle } from "@/app/lib/components/spring-toggle";<SpringToggle checked={on} onChange={setOn} />
<SpringToggle checked={false} onChange={() => {}} disabled />API
Props
| Prop | Type | Default |
|---|---|---|
checked*Whether the toggle is on | boolean | — |
onChange*Called when the user clicks the toggle | (checked: boolean) => void | — |
disabledDisables the toggle and suppresses all glow and spring motion | boolean | false |
classNameAdditional class names applied to the outermost wrapper | string | "" |
aria-labelAccessible name when there is no visible label to point at | string | — |
aria-labelledbyId of the visible label element that names this switch | string | — |
id | string | — |
Read from the component's source at build time. * required.
Accessibility
Works with
- Cursor
- Reacts to where the pointer is, not just whether it's over the element.
- Touch
- Follows your finger while it's down, then settles a moment after you lift.
- Keyboard
- Focus lights it up the way the cursor does. Every action has a key.
- Reduced motion
- Nothing moves or springs. Colour still answers, without drifting.