# Loading to check pill

> A pill button that shows a spinner while it works, then pops a check mark into place with a spring.

- Category: [Buttons](https://library.aimran.es/components/buttons)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/animated-loading-check
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Some actions deserve a clear “it’s done”: booking a table, paying for an order, reserving a class at the gym. This pill runs through a short wait and ends with a check that bounces in, so nobody wonders whether it went through. That final bounce turns a plain loading button into a success animation people actually notice.

Set the duration close to how long your request really takes, usually under a second and a half. If it can take much longer, add a line of text such as “Confirming…” next to it so the wait does not feel stuck.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Check, Loader2 } from "lucide-react";

const spring = { type: "spring", stiffness: 300, damping: 30 } as const;

interface LoadingCheckButtonProps {
  text?: string;
  color?: string;
  /** Duración de la carga simulada en ms. */
  delay?: number;
}

export default function LoadingCheckButton({
  text = "Book now",
  color = "#0071e3",
  delay = 1200,
}: LoadingCheckButtonProps) {
  const [state, setState] = useState<"idle" | "load" | "done">("idle");

  const go = () => {
    if (state !== "idle") return;
    setState("load");
    setTimeout(() => setState("done"), delay);
    setTimeout(() => setState("idle"), delay + 1600);
  };

  return (
    <motion.button
      type="button"
      whileTap={{ scale: 0.96 }}
      onClick={go}
      className="flex min-w-36 items-center justify-center gap-2 rounded-full px-6 py-3 text-sm font-medium text-white shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
      style={{ backgroundColor: color }}
    >
      <AnimatePresence mode="wait" initial={false}>
        {state === "idle" ? (
          <motion.span
            key="idle"
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
          >
            {text}
          </motion.span>
        ) : state === "load" ? (
          <motion.span key="load" initial={{ scale: 0.6 }} animate={{ scale: 1 }}>
            <Loader2 className="h-4 w-4 animate-spin" />
          </motion.span>
        ) : (
          <motion.span
            key="done"
            initial={{ scale: 0.4, opacity: 0 }}
            animate={{ scale: 1, opacity: 1 }}
            transition={spring}
            className="flex items-center gap-2"
          >
            <Check className="h-4 w-4" /> Done
          </motion.span>
        )}
      </AnimatePresence>
    </motion.button>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Loading to check pill” block (Buttons) from AIMRAN Library to my project.

## What it is
A pill button that shows a spinner while it works, then pops a check mark into place with a spring.

## Chosen settings
- Text: "Book now"
- Color: #0071e3
- Duration: 1200ms (from 500 to 2500ms)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Check, Loader2 } from "lucide-react";

const spring = { type: "spring", stiffness: 300, damping: 30 } as const;

interface LoadingCheckButtonProps {
  text?: string;
  color?: string;
  /** Duración de la carga simulada en ms. */
  delay?: number;
}

export default function LoadingCheckButton({
  text = "Book now",
  color = "#0071e3",
  delay = 1200,
}: LoadingCheckButtonProps) {
  const [state, setState] = useState<"idle" | "load" | "done">("idle");

  const go = () => {
    if (state !== "idle") return;
    setState("load");
    setTimeout(() => setState("done"), delay);
    setTimeout(() => setState("idle"), delay + 1600);
  };

  return (
    <motion.button
      type="button"
      whileTap={{ scale: 0.96 }}
      onClick={go}
      className="flex min-w-36 items-center justify-center gap-2 rounded-full px-6 py-3 text-sm font-medium text-white shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
      style={{ backgroundColor: color }}
    >
      <AnimatePresence mode="wait" initial={false}>
        {state === "idle" ? (
          <motion.span
            key="idle"
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
          >
            {text}
          </motion.span>
        ) : state === "load" ? (
          <motion.span key="load" initial={{ scale: 0.6 }} animate={{ scale: 1 }}>
            <Loader2 className="h-4 w-4 animate-spin" />
          </motion.span>
        ) : (
          <motion.span
            key="done"
            initial={{ scale: 0.4, opacity: 0 }}
            animate={{ scale: 1, opacity: 1 }}
            transition={spring}
            className="flex items-center gap-2"
          >
            <Check className="h-4 w-4" /> Done
          </motion.span>
        )}
      </AnimatePresence>
    </motion.button>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
