Action button

Free

Buttons that show their own work, so the page needs no toast: Save to Saving to Saved, Upload that fills its own glass, and Generate that becomes its own Stop with the elapsed time.

npx shadcn@latest add @pixilui/action-button

Preview

Save becomes Saving, then a drawn check, at a width that never moves.
Show

When to use

Use it when

  • An action that takes a moment and lands: save, send, publish, approve. Use ActionButton.
  • Sending a file, where the progress belongs on the button that started it. Use ActionButtonUpload.
  • Starting work a person may want to stop: generating, summarizing, running an eval. Use ActionButtonGenerate.

Use something else when

  • Work that runs longer than a minute or in the background: show it in a run timeline, not on a button.
  • A destructive action: use Confirm button.
  • Copying text: use Copy button, which has its own drawn check.

Installation

Terminal
npx shadcn@latest add @pixilui/action-button

Adds action-button.tsx with button.tsx, and installs clsx and tailwind-merge. First PixilUI item in this app? Add the registry once, as in Installation.

Usage

example.tsx
import { ActionButton } from "@/components/pixilui/action-button";

<ActionButton onAction={onAction} onError={onError} />

Never wider than its container. Pass block to fill a narrow form. The timer uses tabular figures, so it never jitters.

API reference

PropTypeDefault
onActionRequired() => void | Promise<void>–The work. Return a promise and the button shows Saving until it settles, then Saved.
variantButtonVariant"primary"Visual weight, as on Button. primary is the default: this is usually the surface's main action.
sizeButtonSize–Height, as on Button: xs 24, sm 28, md 32 (default), lg 36, xl 44.
labelstring"Save changes"The label at rest.
pendingLabelstring"Saving"The label while the work runs, beside the ring.
doneLabelstring"Saved"The label once the work lands, beside the drawn check.
resetAfternumberSAVE_RESET_MSHow long the done label shows before the button returns to rest, in ms.

Keyboard

TabMoves focus to the button; focus stays on it while the work runs and when it lands.
EnterRuns the action (or opens the file picker, or starts and stops the generation).
SpaceSame as Enter, on release.

Accessibility

  • A native button. While the work runs it sets aria-busy and aria-disabled, never disabled, so focus survives.
  • The label itself changes (Saving, Uploaded, Stop generating), so a screen reader hears the state when it reads the button again.
  • The upload's file input is hidden and out of the tab order; the button opens it.
  • data-status is idle, pending, uploading, running, done or error, for styling and tests.

Motion

  • Each label cross-fades: the old leaves 5px up in 110ms, the new arrives from 5px below out of a 2px blur in 200ms, 70ms later.
  • Saved and Uploaded draw their check in 260ms; the button returns to rest after resetAfter.
  • The upload fill grows across the glass as report is called and fades when done.
  • Generate swaps the accent for the glass in 150ms; the running label shimmers, linear, and the timer counts each second.
  • reserve holds the widest label of each form, so the width never animates. Reduced motion: labels change at once, no draw, shimmer or eased fill.

PixilUI Pro opens Thu 10 Dec. The first 20 licenses are $99.