Stateful Button
FreeNewSampleIdle, loading, success and error in one control. Width animates between labels so layouts never jump, and screen readers hear every outcome.
- buttons
- feedback
- forms
Customize
These controls show a few ways to adapt it. The source is fully editable.
Install
Not published yetnpx shadcn@latest add @uicoolkit/stateful-buttonInstall commands go live when this item ships to the registry.
Dependencies
- motion
Use with an agent
Copy a prompt with this component, your current preview settings and links to its docs.
Add the UICoolKit "Stateful Button" component (stateful-button) to this project. Docs: https://uicoolkit.com/components/stateful-button Agent docs: https://uicoolkit.com/components/stateful-button.md Install: npx shadcn@latest add @uicoolkit/stateful-button Preview settings to match: accent Ember, radius 12px, motion on. Use the documented props and className hooks rather than editing internals, and wire it to this app's real state. (Note: this is a sample item from the UICoolKit website shell and is not published yet.)
<StatefulButton
action={saveChanges}
labels={{ idle: "Save changes", success: "Saved" }}
/>| Prop | Type | Default |
|---|---|---|
actionRuns on click. Resolving shows success; rejecting shows error. | () => Promise<unknown> | — |
statusControl the state from your own data instead. | "idle" | "loading" | "success" | "error" | — |
labelsReplace the label or icon for any state. | Partial<Record<Status, ReactNode>> | — |
classNameMerged onto the root after defaults, so consumer styles win. | string | — |
motionDisable animation or tune duration, easing and spring values. Reduced motion is honored by default. | boolean | MotionOptions | true |
Every part accepts className, and consumer classes are merged last so they win. Control state from your own data, replace any content, and tune or disable motion.
<StatefulButton
className="rounded-none border-2 border-black bg-yellow-300 font-mono"
motion={{ duration: 0.2 }}
/>- Native <button>; loading sets aria-busy and keeps focus in place.
- Outcome text is announced through a polite live region.
- With reduced motion, labels swap instantly and the width change is skipped.
An original UICoolKit component, designed and built from scratch.
Free items are MIT licensed. Pro items are licensed per purchase.