MorphStatusButton

Get this button for GPUI

A single button that morphs through idle, loading, success, and error states in place, with no layout shift.

Preview

Props

Variants

It fails sometimes

When the returned promise rejects, the button drops into its error state.

Install

npx shadcn@latest add @evilbuttons/morph-status-button

Usage

import { MorphStatusButton } from "@/components/evil-buttons/morph-status-button";

export function ButtonDemo() {
  return (
    <MorphStatusButton
      successLabel="Saved"
      onClick={async () => {
        await saveChanges();
      }}
    >
      Save changes
    </MorphStatusButton>
  );
}
<MorphStatusButton status={isPending ? "loading" : "idle"}>
  Save changes
</MorphStatusButton>

Props

The component spreads any <button> HTML attributes except onClick (which is overloaded to accept an async handler).

PropTypeDefaultDescription
childrenReact.ReactNode-Idle label. Falls back to label.
labelReact.ReactNode"Save changes"Idle label used when no children are provided.
loadingLabelReact.ReactNode"Working…"Label shown while the action is in flight.
successLabelReact.ReactNode"Done"Label shown after the action resolves.
errorLabelReact.ReactNode"It broke. Your fault."Label shown after the action rejects.
onClick(e) => void | Promise<unknown>-Click handler. Returning a promise triggers the auto state machine.
status"idle" | "loading" | "success" | "error"-Controlled status; disables promise-based transitions when set.
resetAfternumber1800Milliseconds to stay in success/error before resetting. Set to 0 to stay.
classNamestring-Extra classes passed to the button.

Good to know

  • Return a promise from onClick and it shows loading, then success or error.
  • Disabled and aria-busy while loading.

Search docs

Jump to a button documentation page