ebnsina

Action Button

Buttons

About

A button that runs an async action and morphs in place to show working, success, or failure, keeping its size through every state.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Action Button to your project and fits it to your theme.

Code

How Action Button is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import ActionButton from "@/components/ui/action-button";

export default function ActionButtonErrorDemo() {
  // Fails the first time, works after: press it twice.
  let tries = 0;
  const save = () =>
    new Promise((resolve, reject) =>
      setTimeout(
        () => (++tries === 1 ? reject(new Error("Offline")) : resolve(null)),
        1000,
      ),
    );

  return (
    <div className="flex items-center justify-center p-10">
      <ActionButton
        action={save}
        pending="Saving…"
        done="Saved"
        failed="Couldn’t save"
        variant="secondary"
      >
        Save the translation
      </ActionButton>
    </div>
  );
}

Dependencies

More by ebnsina

View all
  • Countdown Timer

    Countdown Timer

    38
  • Video Player

    Video Player

    28
  • Hourglass Timer

    Hourglass Timer

    24
  • Alarm Clock

    Alarm Clock

    24
  • Voice Note

    Voice Note

    19
  • Sortable List

    Sortable List

    18
  • Sign In Auth Card

    Sign In Auth Card

    15
  • Split Button

    Split Button

    14

More in Buttons

View all
  • Texture Button

    Texture Button

    122
  • Button

    Button

    172
  • HeroUI Button Group

    HeroUI Button Group

    1
  • Button

    Button

    88
  • Native Button

    Native Button

    7
  • Button

    Button

    74
  • Button Group

    Button Group

    5
  • Button

    Button

    21