#348
Spring switch
A switch whose thumb stretches to 1.3 on press and overshoots into place on release.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Spring switch" pattern (@codeatlasdev/ui demo #348, motion/micro) in my app.
Call get_demo({ ids: ["#348"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Settings switches where the thumb should feel physical rather than slide linearly.
Keep these library parts, with the props and tokens the demo uses:
- MotionStage from "@codeatlasdev/ui"
Behaviour to keep:
- `MotionStage` from `@codeatlasdev/ui` with `loop={2800}`
- `role="switch"` with `aria-checked={on}` and `aria-labelledby` pointing at the visible label
- `.sw__track--press .sw__thumb` is `transform: scaleX(1.3)` while pressed
- `.sw__track--on .sw__thumb` is `transform: translateX(20px)`
- `transition: transform 420ms cubic-bezier(0.175, 0.885, 0.32, 1.275)` overshoots the landing
- `.sw__track--still` sets `transition: none` under reduced motion
Exact motion (do not approximate):
- transform: translateX, scaleX (thumb): 420ms, cubic-bezier(0.175, 0.885, 0.32, 1.275)
- background (track): 240ms, cubic-bezier(0.2, 0, 0, 1)
Reduced motion: the demo handles it; keep that branch.
Keyboard: operable; keep the focus order and key handling.
Change only the copy and the data. Use the theme tokens (--ca-*), never raw colours. Library parts
- MotionStage
@codeatlasdev/ui
How it is built
- `MotionStage` from `@codeatlasdev/ui` with `loop={2800}`
- `role="switch"` with `aria-checked={on}` and `aria-labelledby` pointing at the visible label
- `.sw__track--press .sw__thumb` is `transform: scaleX(1.3)` while pressed
- `.sw__track--on .sw__thumb` is `transform: translateX(20px)`
- `transition: transform 420ms cubic-bezier(0.175, 0.885, 0.32, 1.275)` overshoots the landing
- `.sw__track--still` sets `transition: none` under reduced motion
Related
Loading source.