Mark Yo

Stateful Button

Buttons

About

A button that morphs its label and icon through idle, loading, success and error states, with the text rolling in letter by letter and the button width easing to fit.

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

Code

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

Usage.tsx

"use client";

import StatefulButton from "@/components/ui/button-stateful";
import { useState } from "react";

type DemoState = "idle" | "loading" | "success" | "error";

export default function StatefulButtonDemo() {
  const [state, setState] = useState<DemoState>("idle");

  const run = () => {
    setState("loading");
    window.setTimeout(() => {
      setState("success");
      window.setTimeout(() => setState("idle"), 1600);
    }, 1400);
  };

  return (
    <div className="flex min-h-[320px] w-full items-center justify-center">
      <StatefulButton
        state={state}
        onClick={run}
        loadingText="Saving"
        successText="Saved"
        errorText="Try again"
      >
        Save changes
      </StatefulButton>
    </div>
  );
}

Dependencies

More by Mark Yo

View all
  • Loader

    Loader

    67
  • Pricing Table

    Pricing Table

    24
  • Bento Grid

    Bento Grid

    10
  • Wallet Card

    Wallet Card

    4
  • Expandable Tabs

    Expandable Tabs

    4
  • Image Gallery

    Image Gallery

    3
  • CTA Section

    CTA Section

    3
  • Bar Chart

    Bar Chart

    1

More in Buttons

View all
  • Button

    Button

    20
  • Button

    Button

    3
  • Button Group

    Button Group

    18
  • Button

    Button

    149
  • Icon Label Subtext Button

    Icon Label Subtext Button

    69
  • Button

    Button

    9
  • Button

    Button

    37
  • Texture Button

    Texture Button

    113