Stateful Button
ProNewKeeps its footprint as an async action moves through pending, success and retry states.
Installation
pnpm dlx shadcn@latest add @viewport/stateful-button
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| action* | () => Promise<unknown>Runs on press. Resolve for the success state; reject or throw for the error state. | — |
| loadingText | stringLabel while the action runs. | "Saving" |
| successText | stringLabel after the action resolves. | "Saved" |
| errorText | stringLabel after the action rejects. | "Try again" |
| resetAfter | numberMilliseconds before success or error returns to the idle label. | 2000 |
Accessibility
- Stays focusable while busy and sets aria-busy, so keyboard users keep their place.
- Loading, success and error are announced through a polite live region.
- State changes are immediate under reduced motion.