Skip to content

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
import { SpringToggle } from "@/app/lib/components/spring-toggle";
example 1
<SpringToggle checked={on} onChange={setOn} />
<SpringToggle checked={false} onChange={() => {}} disabled />

API

Props

PropTypeDefault
checked*

Whether the toggle is on

boolean—
onChange*

Called when the user clicks the toggle

(checked: boolean) => void—
disabled

Disables the toggle and suppresses all glow and spring motion

booleanfalse
className

Additional class names applied to the outermost wrapper

string""
aria-label

Accessible name when there is no visible label to point at

string—
aria-labelledby

Id of the visible label element that names this switch

string—
idstring—

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.