# V button 27

> Loading and success state button with animated icon swap

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/v-button-27).

- Page, with a live preview: https://shadcn.exchange/r/cnippet/v-button-27
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/cnippet/v-button-27-light-edef6e13c2ba8849.png
- Registry item: https://ui.cnippet.dev/r/v-button-27.json
- Categories: button
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.cnippet.dev/r/v-button-27.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `@cnippet/button`

## Files

### `registry/default/variants/v-button-27.tsx`

```tsx
"use client";

import { CheckIcon, CloudUploadIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/registry/default/ui/button";

type State = "idle" | "loading" | "success";

export function Pattern() {
  const [state, setState] = useState<State>("idle");

  const handleClick = () => {
    if (state !== "idle") return;
    setState("loading");
    setTimeout(() => {
      setState("success");
      setTimeout(() => setState("idle"), 2000);
    }, 1800);
  };

  return (
    <Button
      disabled={state === "loading"}
      loading={state === "loading"}
      onClick={handleClick}
      variant={state === "success" ? "outline" : "default"}
    >
      {state === "success" ? (
        <>
          <CheckIcon className="size-4 text-emerald-500" />
          Saved
        </>
      ) : (
        <>
          <CloudUploadIcon className="size-4" />
          {state === "loading" ? "Saving…" : "Save Changes"}
        </>
      )}
    </Button>
  );
}
```
