#346
Add to cart fly
Tapping Add to cart sends a dot flying from the button to the bag, then the badge count bumps with an overshoot.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Add to cart fly" pattern (@codeatlasdev/ui demo #346, motion/micro) in my app.
Call get_demo({ ids: ["#346"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: E-commerce add actions, saving to a list or any action whose result lives somewhere else on screen.
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={2400}`
- `@keyframes cart-fly` moves the dot `translate(40px, -26px)` at 60% and `translate(72px, -4px)` at 100% while fading out
- `setTimeout` of `520` ms after the click increments `count`, matching the flight length
- `@keyframes cart-bump` scales the badge `1` to `1.5` and back
- `announce(`Cart: ${count} items`)` tells assistive tech; the bag is `role="img"` with the count in its label
- `{#key flight}` remounts the dot so each add flies again; nothing flies when reduced
Exact motion (do not approximate):
- transform, opacity (flying dot): 520ms, cubic-bezier(0.4, 0, 0.2, 1)
- transform: scale (badge bump): 360ms, cubic-bezier(0.175, 0.885, 0.32, 1.275)
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}`
- `@keyframes cart-fly` moves the dot `translate(40px, -26px)` at 60% and `translate(72px, -4px)` at 100% while fading out
- `setTimeout` of `520` ms after the click increments `count`, matching the flight length
- `@keyframes cart-bump` scales the badge `1` to `1.5` and back
- `announce(`Cart: ${count} items`)` tells assistive tech; the bag is `role="img"` with the count in its label
- `{#key flight}` remounts the dot so each add flies again; nothing flies when reduced
Related
Loading source.