Action Button
A button for one async action. Its arrow floats apart as a glass droplet; press it and the droplet melts into the body, and stays.
glass-action-button-basic.tsx
Use it for
- One async commit whose result belongs on the button: Deploy, Publish, Add to cart, Subscribe.
- Actions that stay done: the merged "Deployed ✓" is the new state of the page.
Not for
- Plain links and instant actions: use GlassButton.
- Toggling back and forth between two states: use GlassTabs.
- More than one per screen: the droplet is the kit's one gooey effect, keep it special.
Installation
Coming soon
npm install @vitrumui/reactNo dependencies
Usage
app.tsx
import { GlassActionButton } from '@vitrumui/react/action-button'
<GlassActionButton
material="tinted"
className="bg-neutral-900 text-white"
pendingLabel="Deploying"
successLabel="Deployed"
onAction={deploy} // return the promise
>
Deploy
</GlassActionButton>The flow
- Idle. The arrow floats apart from the body as a separate glass droplet.
- Press. The droplet stretches back on a gooey bridge and melts into the body.
- Pending. One body; the label morphs to
pendingLabeland a spinner turns where the arrow was, until the promise fromonActionsettles. - Success. Still one body:
successLabeland a check that draws itself in. It stays merged, unless you setresetAfter. - Error. If
onActionthrows, the droplet splits off again andonActionErrorgets the error.
Examples
Coming soon
API reference
| Prop | Type | Default |
|---|---|---|
childrenThe idle label, and the button's accessible name. | ReactNode | — |
onActionRequired. Runs on press; return a promise to stay pending until it settles. | () => unknown | — |
onActionErrorCalled when | (error) => void | — |
pendingLabelLabel while | ReactNode | children |
successLabelLabel after it succeeds. | ReactNode | children |
resetAfterMilliseconds before splitting off again after a success. | number | 0 |
iconThe droplet's idle icon. | ReactNode | arrow |
materialAs on GlassButton. | 'clear' | 'tinted' | 'clear' |
sizeHeight 32, 40 or 48 px. | 'sm' | 'md' | 'lg' | 'md' |
…restPassed to the | button attributes | — |
Accessibility
- A real
<button>; Enter and Space run the action. - Pending sets
aria-busy, and pending or done setsaria-disabledinstead ofdisabled, so focus stays on the button. - A
role="status"region announces the pending and success labels. - With reduced motion the droplet and labels switch without animation.