Action Button
nexvyn/action-buttonFreeComponent
An async-aware button with an idle → pending → success/error state machine, promise tracking, abort support, and live screen-reader announcements.
Live preview
live · rendered by the registry
Rendered by nexvyn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.nexvyn.dev/r/action-button.jsonSource
1'use client'23import * as React from 'react'4import { useReducedMotion } from 'motion/react'5import { cn } from '@/lib/utils'6import { Button, type ButtonProps } from '@/components/ui/button'78export type ActionButtonState = 'idle' | 'pending' | 'success' | 'error'910export interface ActionButtonProps extends Omit<11 ButtonProps,12 'loading' | 'loadingLabel' | 'loadingIndicator' | 'onClick'13> {14 /**15 * Controlled state. If provided, the component becomes fully controlled16 * and ignores the result of `onAction`.17 */18 state?: ActionButtonState19 /**20 * Default state for uncontrolled mode.21 */22 defaultState?: ActionButtonState23 /**24 * A callback that returns a promise. The component tracks the promise lifecycle25 * (idle → pending → success/error → idle). Receives an AbortSignal.26 */27 onAction?: (signal: AbortSignal) => Promise<void>28 /**29 * Callback fired whenever internal state changes (uncontrolled mode).30 */31 onStateChange?: (state: ActionButtonState) => void32 /**33 * Minimum time (ms) to show the pending state. Prevents flicker for fast operations.34 * Defaults to 0 (no minimum). Opt-in only.35 */36 minPendingMs?: number37 /**38 * Time (ms) before resetting from success/error back to idle.39 * Defaults to 2000ms. Set to 0 to disable auto-reset.40 */41 resetDelayMs?: number42 /** Label content shown in idle state. */43 idleLabel?: React.ReactNode44 /** Label content shown in pending state. */45 pendingLabel?: React.ReactNode46 /** Label content shown in success state. */47 successLabel?: React.ReactNode48 /** Label content shown in error state. */49 errorLabel?: React.ReactNode50 /** Icon shown in idle state. */51 idleIcon?: React.ReactNode52 /** Icon shown in pending state. Defaults to a spinner. */53 pendingIcon?: React.ReactNode54 /** Icon shown in success state. Defaults to a checkmark. */55 successIcon?: React.ReactNode56 /** Icon shown in error state. Defaults to an × glyph. */57 errorIcon?: React.ReactNode58 /**59 * Full control over rendering each state. Overrides individual label/icon props.60 * The returned node is rendered inside the button.61 */62 renderState?: (state: ActionButtonState) => React.ReactNode63 /**64 * Accessible live-region announcement per state.65 * Provide either a static string or a function.66 */67 announcements?: Partial<Record<ActionButtonState, string>>68 /** onClick passthrough — fires only in idle state. Does not track async. */69// … truncated
What it pulls in
npm packages
Files it writes
More from nexvyn
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | nexvyn | Components | Free | 1 dep | |
| Adaptive Actionsadaptive-actions | nexvyn | Components | Free | 1 dep | |
| AI Inputai-input | nexvyn | Components | Free | 1 dep · 2 files | |
| Badgebadge | nexvyn | Components | Free | 2 deps · 2 files | |
| Bars Themebars-theme | nexvyn | Components | Free | 1 dep · 3 files | |
| Bounce Sidebarbounce-sidebar | nexvyn | Components | Free | 1 dep · 2 files | |
| Breadcrumbsbreadcrumbs | nexvyn | Components | Free | 1 dep · 2 files | |
| Buttonbutton | nexvyn | Components | Free | 3 deps · 3 files |
