#342
Morphing toggle
A sun icon that morphs into a moon: a mask circle slides over the disc to bite it into a crescent while the rays rotate and shrink away.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Morphing toggle" pattern (@codeatlasdev/ui demo #342, motion/micro) in my app.
Call get_demo({ ids: ["#342"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Theme switch, mute toggle or any two-state icon button where the icon itself should show the state change.
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={2400}`
- `role="switch"` with `aria-checked={dark}` and `aria-label="Dark mode"`
- `<mask id="{uid}-bite">` holds a black `circle` that `.tg__bite` moves from `translate(10px, -10px)` to `translate(0, 0)`
- `.tg__btn--dark .tg__rays` goes to `transform: rotate(45deg) scale(0.4)` and `opacity: 0`
- `.tg__btn--dark .tg__icon` rotates to `transform: rotate(-35deg)`
- `.tg__btn--still` sets `transition: none` under reduced motion
Exact motion (do not approximate):
- transform (bite mask, icon rotation, rays), opacity (rays): 420ms, cubic-bezier(0.2, 0, 0, 1)
- opacity (rays): 280ms, 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={2400}`
- `role="switch"` with `aria-checked={dark}` and `aria-label="Dark mode"`
- `<mask id="{uid}-bite">` holds a black `circle` that `.tg__bite` moves from `translate(10px, -10px)` to `translate(0, 0)`
- `.tg__btn--dark .tg__rays` goes to `transform: rotate(45deg) scale(0.4)` and `opacity: 0`
- `.tg__btn--dark .tg__icon` rotates to `transform: rotate(-35deg)`
- `.tg__btn--still` sets `transition: none` under reduced motion
Related
Loading source.