Status Button

A button that transitions through idle, loading, success, and failure states with optional controlled behavior.

@lucide/sveltemotion-svruned

Installation

pnpm dlx shadcn-svelte@latest add http://sveltekit-prerender/r/status-button.json

Usage

usage.svelte

Features

  • Works from an async click handler, or follows a status you control from form state
  • Keeps focus while busy, so keyboard focus is not lost when the action finishes
  • Announces loading and success to screen readers
  • Swaps states without motion when reduced motion is preferred

Examples

Basic async

Controlled status

Custom labels

Failed retry

Status styling

Upload progress

Props

StatusButton

Async button with loading, success, and failure transitions.

NameTypeDefaultDescription
childrenSnippet''The default label content shown while the button is idle.
onclick(event: MouseEvent) => void | Promise<void>undefinedAsync action that runs on click and automatically flips the button into the loading state.
statusButtonStatusundefinedControlled state override for external status management.
onStatusChange(status: ButtonStatus) => voidundefinedCalled whenever the button changes between idle, loading, success, and failed states.
onError(error: unknown) => voidundefinedCalled when the action rejects during an async click.
loadingLabelSnippetundefinedCustom content shown while the button is in the loading state.
successLabelSnippetundefinedCustom content shown while the button is in the success state.
successDurationnumber1500How long the success state remains visible before returning to idle.
failedLabelSnippetundefinedCustom content shown while the button is in the failed state.
failedDurationnumber2500How long the failed state remains visible before returning to idle.
classstring''Additional classes applied to the underlying button.
variantButtonVariantundefinedStyle variant passed through to the underlying button.