Command Palette

Search for a command to run...

0GitHub stars
Components

Status Button

Button that shows loading and success feedback for async actions.

Loading…
Dependencies (2)
Registry (2)

Features

  • Works from an async click handler, or follows a status you control from form state.

Installation

pnpm dlx shadcn@latest add @ncdai/status-button

Usage

import { StatusButton } from "@/components/status-button"
<StatusButton onClick={save} successLabel="Saved">
  Save
</StatusButton>

Return a promise from onClick. The button shows a spinner while the promise is pending, then the success label, then returns to idle. If the promise rejects, the button returns to idle right away.

Controlled

When a form owns the submission, pass status and onStatusChange instead of onClick. The button still returns to idle on its own, and onStatusChange receives "idle" when that happens.

import { StatusButton, type ButtonStatus } from "@/components/status-button"
 
const [status, setStatus] = useState<ButtonStatus>("idle")
<StatusButton
  type="submit"
  status={status}
  onStatusChange={setStatus}
  successLabel="Sent"
>
  Send
</StatusButton>

API reference

StatusButton

Extends Button with loading and success states.

Prop

Type

See shadcn/ui documentation for more information.

Examples

Form submission

Loading…

Accessibility

  • Keeps focus while busy, so keyboard focus is not lost when the action finishes.
  • Announces loading and success to screen readers.
  • With prefers-reduced-motion, states swap without animation.

License and usage

  • Free to use and modify in both personal and commercial projects.
  • Attribution is appreciated but not required.
  • Released under the MIT License.

Was this helpful?

Command Palette

Search for a command to run...

Chat