#344
Hold to confirm
A destructive button that only fires after a 1.2 second hold, filling a progress ring; releasing early cancels and drains the ring. Space and Enter work the same way.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Hold to confirm" pattern (@codeatlasdev/ui demo #344, motion/micro) in my app.
Call get_demo({ ids: ["#344"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Deleting data, sending money or any action that must be deliberate without a confirmation dialog.
Keep these library parts, with the props and tokens the demo uses:
- MotionStage, announce from "@codeatlasdev/ui"
Behaviour to keep:
- `MotionStage` from `@codeatlasdev/ui` with `loop={3400}`
- `const HOLD = 1200;` milliseconds to hold; progress is `(now - start) / HOLD` read in `requestAnimationFrame`
- `stroke-dashoffset={C * (1 - (m.reduced && !done ? 0 : progress))}` on the ring circle, with `C = 2 * Math.PI * R`
- `onkeydown` starts on Space or Enter (`!e.repeat`), `onkeyup` and `onblur` call `cancel`
- `onpointerup`, `onpointerleave` and `onpointercancel` call `cancel`, which sets `progress = 0`
- `announce('Project deleted')` tells assistive tech when the hold completes; Undo resets
Exact motion (do not approximate):
- stroke-dashoffset (progress ring): 1200ms, linear
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={3400}`
- `const HOLD = 1200;` milliseconds to hold; progress is `(now - start) / HOLD` read in `requestAnimationFrame`
- `stroke-dashoffset={C * (1 - (m.reduced && !done ? 0 : progress))}` on the ring circle, with `C = 2 * Math.PI * R`
- `onkeydown` starts on Space or Enter (`!e.repeat`), `onkeyup` and `onblur` call `cancel`
- `onpointerup`, `onpointerleave` and `onpointercancel` call `cancel`, which sets `progress = 0`
- `announce('Project deleted')` tells assistive tech when the hold completes; Undo resets
Related
Loading source.