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

    64
  • Pricing Table

    Pricing Table

    23
  • Bento Grid

    Bento Grid

    2
  • Expandable Tabs

    Expandable Tabs

    1
  • Animated Button

    Animated Button

  • Morphing Modal

    Morphing Modal

  • Morph Popover

    Morph Popover

  • Kbd

    Kbd

More in Buttons

View all
  • Button

    Button

    37
  • Button

    Button

    20
  • Texture Button

    Texture Button

    113
  • Icon Label Subtext Button

    Icon Label Subtext Button

    68
  • Astryx Chat Send Button

    Astryx Chat Send Button

    5
  • Button

    Button

    16
  • Minimal Button

    Minimal Button

    15
  • Button

    Button

    146