Animated Add to Cart & Action Morph Button for React
State-transitioning React button that morphs smoothly between Idle, Loading, Success, and Error states with zero layout shift and live region announcements.
Live vector preview rendered straight from the same 120 Hz spring engine—no heavy GIF compression artifacts, zero layout shift.
Customization playground
Tune outline, fill, accent, text colour, and shadow direction live above. The snippet updates automatically for copy-and-paste.
Customize
<ActionMorph />Installation
Install directly into your project source with the Kipluo CLI (React/Tailwind v4) or add the matching Flutter package.
Install
$ npx kipluo add action-morphWorking code example
import { ActionMorph } from "@/components/kipluo/action-morph";
export function AddToCartButton({ sku }: { sku: string }) {
return (
<ActionMorph
label="Add to cart"
pendingLabel="Adding…"
doneLabel="Added to bag"
onAction={async () => {
await fetch(`/api/cart/${sku}`, { method: "POST" });
}}
/>
);
}What Action Morph does
- Animates width, icon swap, and micro-bounce through spring physics when moving from idle -> pending -> success or error without jumping surrounding content.
- Handles rapid repeated clicks gracefully by coalescing or rejecting spam during pending work while announcing state changes via aria-live.
- Works cleanly for Add to Cart, Save Changes, Checkout, and Copy/Submit flows in both Playful, Minimal, and Mono themes.
Accessibility & sound behavior
Keyboard & screen readers: A real button. State changes are announced through a polite live region.
Reduced motion: Automatically respects prefers-reduced-motion: reduce by snapping spring targets immediately without jarring travel.
Sound cues: A boop on click, a two-note chime on success, a muted bonk on error. Ignored clicks stay silent. Disable per instance with sound={false} or globally via setSoundEnabled(false).
API reference
action(signal: AbortSignal) => Promise<void>- The work to run. Receives a signal that aborts on unmount. Default
Simulated save. interrupt"ignore" | "restart"- What a click does while the action is running. Default
"ignore". successFornumber- How long the success state shows, in ms. Default
1400. labelsPartial<Record<ActionMorphState, string>>- Text for each state.
soundboolean- Plays this component's sounds. The global switch setSoundEnabled(false) silences every component. Default
true.
Framework compatibility
| Platform / Tool | Status | Details |
|---|---|---|
| React 18 & 19 | Full support | Zero peer runtime lock-in beyond @kipluo/core. |
| Next.js App Router | Full support | Ships with 'use client' boundaries; SSR-safe hydration. |
| Vite / Remix / Astro | Full support | Standard ESM TypeScript source files you own. |
| Tailwind CSS v4 & shadcn/ui | Native | Inherits CSS variables and installs via shadcn registry or CLI. |
| Flutter (Dart) | Native package | Matching spring physics, themes, and PCM audio in packages/flutter/kipluo. |
Build it yourself: related tutorials
All tutorials →How to Create an Animated Add-to-Cart Button
Build a state-transitioning Add to Cart button in React with Idle, Loading, Success, and Error states, smooth width morphing, spam protection, and aria-live announcements.
How to Handle Interrupted Animations in React
Learn why rapid clicks, mid-flight drags, and unmounts break React animations—and how velocity-preserving springs and proper cleanup make them unbreakable.
How to Implement Spring Physics Without a Heavy Animation Library
Write a rock-solid 45-line semi-implicit Euler spring engine in TypeScript with fixed 120 Hz sub-stepping, zero dependencies, and true velocity preservation.
Related components
- Open component →Success CheckFree
A success moment: the circle draws itself, the check draws in, a ripple rings out and the badge bounces. Replaying mid-way restarts cleanly.
- Open component →Inline Confirm PillFree
Single action pill that morphs smoothly in-place into a compact [Cancel | Confirm] split with a shrinking grace-period bar before it commits.
- Open component →Favorite ToggleFree
A heart that fills from the bottom, squashes, pops and throws a gravity-driven particle burst. Rapid toggles never stack bursts.
- Open component →Copy FeedbackFree
Copies text with a spring pop and stroke-drawn check mark. Rapid clicks cleanly reset the timer without stacking bursts.
- Open component →Confetti BurstFree
Confetti with real physics: launch speed, gravity, air drag, flutter and tumble, drawn on one canvas. Capped so spam stays cheap; the loop stops when the last piece lands.
- Open component →Shake InputFree
An input that shakes once when validation fails: a single spring impulse, so repeated failures never stack. The error slides in and focus stays in the field.