A shadcn-compatible button that runs its own promise: the label pinches into a ball, the rim drains as progress, then the ball squashes into a traced check or a calm error.
Click meTap me
Invoice INV-0231
Northwind Studio · due Nov 14
Draft
Design retainer
€960.00
Usability review
€280.00
Total €1,240.00
action-button · , lively
action-button-demo.tsx
When to use
Use it for any action that waits on the network. Return a promise from onClick and the button handles pending, success and error itself, replacing the spinner, disabled flag and toast.
When not to use
For an action that finishes instantly (open a menu, toggle a panel) use a plain button. For copying text use Copy Button.
Use it for any action that waits on the network: Save, Send, Invite, Refund, Export, Run, Pay. It takes the shadcn Button props (variant, size, asChild), so import { Button } can become ActionButton without changing the JSX, and it replaces the spinner, the disabled flag and the toast you would otherwise wire by hand. Return a promise from onClick and the button shows pending, then success or error, by itself. For an action that finishes instantly (open a menu, toggle a panel) use a plain button; for copying text use copy-button.
The motion follows the three beats. Pressing charges: the button sinks under the finger. On release the label's letters tighten and fade while a 20 px ball grows out of the label's line, and in morph the button closes into a circle around it. The ball then acts: its 2 px rim spins as an open arc, or fills clockwise to progress. It settles when the promise ends: on success the rim closes, the ball squashes and a check traces inside it; on error the arc stops, turns destructive and closes calmly, the ball kicks once (never a shake) and a cross traces. After successDuration or errorDuration the ball folds back into the returning label. calm keeps the letters still and crossfades the ball in place; playful adds a slow 2–3 % breath while pending.
import { ActionButton } from "@/components/ui/action-button"export function SaveProfile({ save }: { save: () => Promise<void> }) { return ( <ActionButton onClick={save} successLabel="Saved" announce={{ pending: "Saving profile", success: "Profile saved", error: "Could not save" }} > Save changes </ActionButton> )}
The promise returned by onClick drives the flow; a handler that returns nothing behaves like a normal button, and event.preventDefault() skips the flow. A click while pending is ignored, so a request is never sent twice. Pass progress (0 to 1) when you know how far the action is:
Pick a layout with preset. The look and the motion are the same in all three:
morph (default): the button closes into a circle around the ball and grows back. Margins keep its footprint, so neighbours never move; collapse="start" closes toward the inline start instead of the centre.
inline: the width never changes; the ball takes the icon slot and the label dims while pending. For table rows, toolbars and dialog footers. Without an icon the ball sits centred and the label fades; its letters never tighten, so the width holds.
icon: an icon-only button (size="icon") whose icon pinches into the ball. Give it an aria-label and a tooltip.
asChild renders your link with the button's behaviour; the link's text is the label. The link variant keeps the flow but always behaves as inline. Set the character app-wide with MotionKitProvider, or per button with temperament.
The default demo above is the footer of an invoice drawer: the total, a Preview button and "Send invoice". A scripted upload fills the rim, the check traces, the label returns as "Sent" and the status badge follows. At 320 px the total moves above the buttons and the circle stays centred in the button's footprint.
inline in a data table: each row has its own "Retry sync". The warehouse row fails, so its rim turns destructive, a cross traces and the label returns as "Retry" with a 1 px destructive rim. The other rows never move.
A native <button> (or your asChild element). While pending it has aria-busy="true" and aria-disabled="true" instead of the disabled attribute, so focus is never lost mid-flow; clicks are ignored until the promise settles.
The label stays in the DOM while the ball shows, so the accessible name does not change during the flow. successLabel / errorLabel replace it only once the ball has returned.
A polite live region next to the button announces the pending, success and error texts (announce); it sits outside the busy button so screen readers do not hold it back.
The ball, the rim and the marks are aria-hidden. The error is shown by the cross, the destructive rim and the announcement together, never by colour alone.
The ball and its rim use the variant's foreground colour; the check and cross are cut in the button's fill. In inline the dimmed label keeps 62 % opacity, AA on every variant. Disabled is muted-foreground on muted, without opacity.
Focus shows a 3 px ring halo that follows the morphing width. sm (32 px) extends its hit area to 40 px without growing.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") there is no sink, no letter tightening and no width change: morph keeps its width. The label crossfades to the ball, the rim is a still 70 % ring (or the progress, which still fills), the check or cross fades in instead of tracing, and the label fades back. aria-busy and the announcement carry the state; every still frame is a finished button.
At rest nothing runs. The only loop is the open arc's rotation while pending (one turn per 1.3 s, a transform on a motion value), and it pauses off screen and in hidden tabs.
The morph width is measured once when the flow starts and once when the label returns, then animated on one spring with the margins and the radius; no layout reads happen inside a frame.
Peers: motion, @radix-ui/react-slot (about 1 kB gzip) and class-variance-authority (about 1 kB gzip). Nothing is lazy-loaded.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-slot, motion.
Dependencies
@radix-ui/react-slot · peer
class-variance-authority
motion · peer
Triggers
click, press, a loading state, an app event
Reduced motion
No sink, pinch or width change: the label crossfades to the ball, the rim is a still 70% ring (or the progress), the check or cross fades in, and the state is announced.
Keyboard
Tab
Moves focus to the button; it stays focused while the action runs
Space / Enter
Runs the action (the button sinks while the key is down); ignored while pending
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)