Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Stateful Button

ProNew

Keeps 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

PropTypeDefault
action*() => Promise<unknown>

Runs on press. Resolve for the success state; reject or throw for the error state.

—
loadingTextstring

Label while the action runs.

"Saving"
successTextstring

Label after the action resolves.

"Saved"
errorTextstring

Label after the action rejects.

"Try again"
resetAfternumber

Milliseconds 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.