Action button
Action button
A button that runs a promise and shows it: the icon slot opens for a spinner, a check draws itself, failures shake, and the label morphs through each.
Dependencies
Interaction states
- idle — Resting state with optional leading icon and label.
- pending — Interaction disabled; spinner opens and label morphs to pending state.
- success — Self-drawing checkmark and affirmative feedback before auto-resetting.
- error — Error badge and horizontal WAAPI shake alerting the user.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/action-buttonFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Form submissions
Primary save/update actions that communicate network progress without modal overlays.
Deployments & builds
Triggering long-running workflows with clear pending feedback and auto-reset.
Destructive confirmations
Critical actions like purging data or deleting workspaces with affirmative feedback.
What it handles
- Promise-driven state machine — Pass an async action callback; the button manages idle, pending, success, and error states automatically.
- In-place character morphing — Labels transition using TextMorph, animating shared glyphs with spring physics.
- Self-drawing checkmark — On success, a crisp thin line checkmark draws itself with SVG strokeDashoffset easing.
- Tactile error shake — On failure, the button executes an organic horizontal shake via WAAPI to catch peripheral attention.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { ActionButton } from "@/components/action-button";
import { CloudUpload } from "lucide-react";
<ActionButton
icon={<CloudUpload size={14} />}
labels={{
idle: "Save changes",
pending: "Saving...",
success: "Saved!",
error: "Failed",
}}
action={async () => {
await saveSettings();
}}
/>Props
| Prop | Type | Description |
|---|---|---|
| action | () => Promise<unknown> | void | – · Async or sync callback executed on click. Drives status automatically. |
| status | "idle" | "pending" | "success" | "error" | – · Controlled status override. |
| labels | Partial<Record<ActionStatus, string>> | – · Custom labels per status state. |
| variant | "primary" | "secondary" | "destructive" | "outline" | "ghost" | "primary" · Visual style. |
| size | "sm" | "md" | "lg" | "md" · Button scale and typography. |
| resetAfter | number | 2000 · Duration in ms before auto-reverting from success/error to idle. |
Accessibility & motion
- Busy uses aria-disabled, not disabled, so focus stays on the button while it works. - A status region outside the button announces each state; the shake is WAAPI, the check a drawn stroke. - onError receives whatever the action threw.
pnpm dlx shadcn@4.21.5 add @cavemio/action-button