---
title: "Stateful Button"
description: "Free React stateful button: idle, loading, success and error states swap with a blur while the width morphs to fit. Framer Motion, Tailwind, shadcn install."
category: "Components"
parent: "https://beui.dev/components/motion/button"
publishedAt: "2026-05-17"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/components/motion/button/stateful"
markdown: "https://beui.dev/components/motion/button/stateful.md"
license: "MIT"
---

# Stateful Button

> Free React stateful button: idle, loading, success and error states swap with a blur while the width morphs to fit. Framer Motion, Tailwind, shadcn install.

## Install

```bash
npx shadcn@latest add @beui/button-stateful
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

### Stateful Button usage

Idle → loading → success / error with blur-swap slots and morphing width.

```tsx
"use client";

import { ArrowRight } from "lucide-react";
import { useState } from "react";
import { type ButtonState, StatefulButton } from "@/components/motion/button";

export function ButtonStatefulPreview() {
  const [okState, setOkState] = useState<ButtonState>("idle");
  const [errState, setErrState] = useState<ButtonState>("idle");

  const run = (target: "ok" | "err") => {
    const setter = target === "ok" ? setOkState : setErrState;
    setter("loading");
    setTimeout(() => {
      setter(target === "ok" ? "success" : "error");
      setTimeout(() => setter("idle"), 1800);
    }, 1400);
  };

  return (
    <div className="flex flex-col items-center justify-center gap-3">
      <StatefulButton
        state={okState}
        variant="primary"
        size="md"
        onClick={() => run("ok")}
        loadingText="Saving"
        successText="Saved"
        icon={<ArrowRight className="h-4 w-4" />}
      >
        Save changes
      </StatefulButton>
      <StatefulButton
        state={errState}
        variant="secondary"
        size="md"
        onClick={() => run("err")}
        loadingText="Submitting"
        errorText="Failed"
      >
        Submit
      </StatefulButton>
    </div>
  );
}
```

## API Reference

### StatefulButton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `size` | `"sm" \| "md" \| "lg" \| "icon"` | — | No | Height and padding; "icon" is a square icon-only button. Default: "md" |
| `labels` | `Partial<{ loading: string; success: string; error: string; }>` | — | No | Override any built-in string. |
| `variant` | `"outline" \| "primary" \| "secondary" \| "ghost"` | — | No | Visual style: filled, card, ghost or outline. Default: "primary" |
| `pressScale` | `number` | — | No | Scale while pressed. Default 0.97: subtle, so the press reads as feedback, not a squash. |
| `ripple` | `boolean` | — | No | Spawn a Material-style ripple from the press point. Off by default. |
| `sound` | `boolean` | — | No | Play a soft press sound. Off by default; a `SoundProvider` can mute it app-wide. |
| `icon` | `ReactNode` | — | No | Trailing icon shown only while idle. |
| `state` | `"success" \| "loading" \| "idle" \| "error"` | `idle` | No | Which state to show. Loading also disables the button. Default: "idle" |
| `loadingText` | `ReactNode` | — | No | Text shown while loading. Default: "Loading" |
| `successText` | `ReactNode` | — | No | Text shown on success. Default: "Done" |
| `errorText` | `ReactNode` | — | No | Text shown on error. Default: "Try again" |

## More in Button

- [Metallic Button](https://beui.dev/components/motion/button/metallic.md)
- [Base Button](https://beui.dev/components/motion/button/base.md)
- [Magnetic Button](https://beui.dev/components/motion/button/magnetic.md)

## Source

- Registry detail: https://beui.dev/r/button-stateful
- Raw source: https://beui.dev/r/button-stateful/raw
- GitHub: https://github.com/starc007/ui-components
