Skip to content
Motion · Feedback

Payment status

One ring: processing, verifying, done.

Installation

  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/ and the colour tokens go into your CSS.

    $ pnpm dlx asta-ui@latest add payment-status

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/payment-status.json

  2. Or install the package

    Don’t want the file? Import from asta-ui/payment-status and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui
    import { PaymentStatus } from "asta-ui/payment-status";
  3. Or copy it by hand

    Copy these files. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useEffect, useRef, useState } from "react";
    import { useInView } from "../lab-hooks";
    
    const EASE = "cubic-bezier(.16,1,.3,1)";
    const OK = "var(--color-brand)";
    const BAD = "var(--color-ink-2)";
    const R = 44;
    const C = 2 * Math.PI * R;
    
    type Phase = "processing" | "verifying" | "paid" | "declined";
    const WORD: Record<Phase, string> = { processing: "Processing…", verifying: "Verifying…", paid: "Paid", declined: "Declined" };
    
    /** One ring tells the whole story: it spins, fills, then turns into a check (or, now and then, a cross). */
    export default function PaymentStatus() {
      const [run, setRun] = useState(0);
      const [phase, setPhase] = useState<Phase>("processing");
      const [fading, setFading] = useState(false);
      const spinner = useRef<SVGGElement>(null);
      const root = useRef<HTMLButtonElement>(null);
      const visible = useInView(root);
      const spin = phase === "processing";
      const phaseNow = useRef(phase);
      const angle = useRef({ a: 0, v: 0 });
      useEffect(() => {
        phaseNow.current = phase;
      }, [phase]);
    
      // The arc spins while processing, then glides to rest at 12 o'clock instead of snapping back. The loop only runs
      // while it is spinning or gliding, and stops once it is at rest (or off screen).
      useEffect(() => {
        const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
        const s = angle.current;
        const write = () => spinner.current?.setAttribute("transform", `rotate(${(s.a % 360).toFixed(2)} 50 50)`);
        if (still) {
          s.a = 0;
          write();
          return;
        }
        if (!visible || (!spin && s.a === 0)) return;
        let raf = 0;
        let last = performance.now();
        const step = (now: number) => {
          const dt = Math.min(64, now - last) / 1000;
          last = now;
          if (spin) {
            s.v += (400 - s.v) * (1 - Math.exp(-dt / 0.25));
            s.a += s.v * dt;
          } else {
            const rest = Math.ceil(s.a / 360) * 360;
            s.a += (rest - s.a) * (1 - Math.exp(-dt / 0.18));
            s.v = 0;
            if (rest - s.a < 0.05) {
              // At rest: park at 0 and stop.
              s.a = 0;
              write();
              return;
            }
          }
          write();
          raf = requestAnimationFrame(step);
        };
        raf = requestAnimationFrame(step);
        return () => cancelAnimationFrame(raf);
      }, [spin, visible]);
    
      // The story on a timer. Off screen it stops, and picks up again from the start when it is back.
      useEffect(() => {
        if (!visible) return;
        const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
        const end: Phase = run % 3 === 2 ? "declined" : "paid";
        const resume = !still && phaseNow.current !== "processing";
        const t = still
          ? [setTimeout(() => setPhase(end), 0)]
          : [
              ...(resume
                ? [
                    setTimeout(() => {
                      setFading(false);
                      setPhase("processing");
                    }, 0),
                  ]
                : []),
              setTimeout(() => setPhase("verifying"), 1600),
              setTimeout(() => setPhase(end), 3200),
              setTimeout(() => setFading(true), 6000),
              setTimeout(() => {
                setFading(false);
                setPhase("processing");
                setRun((r) => r + 1);
              }, 6400),
            ];
        return () => t.forEach(clearTimeout);
      }, [run, visible]);
    
      const done = phase === "paid" || phase === "declined";
      const color = phase === "paid" ? OK : phase === "declined" ? BAD : "var(--color-ink)";
      const dash = phase === "processing" ? C * 0.75 : 0;
    
      const replay = () => {
        setFading(false);
        setPhase("processing");
        setRun((r) => r + 1);
      };
    
      return (
        <button
          type="button"
          ref={root}
          onClick={replay}
          aria-label={`Payment ${WORD[phase]}. Click to replay`}
          className="lab-ps flex h-full w-full cursor-pointer items-center justify-center px-6 pb-6 pt-12 outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-brand/50"
          style={{ containerType: "size" }}
        >
          <style href="asta-paymentstatus" precedence="asta">{`
            .lab-ps-body { display: flex; flex-direction: column; align-items: center; gap: min(5cqh, 18px); }
            .lab-ps-ring { width: min(38cqh, 30cqw, 132px); }
            .lab-ps-text { align-items: center; text-align: center; }
            @container (aspect-ratio > 1.9) {
              .lab-ps-body { flex-direction: row; gap: min(6cqw, 36px); }
              .lab-ps-ring { width: min(58cqh, 22cqw, 132px); }
              .lab-ps-text { align-items: flex-start; text-align: left; }
            }
            @keyframes lab-ps-draw { from { stroke-dashoffset: 1 } to { stroke-dashoffset: 0 } }
            @keyframes lab-ps-pulse { from { transform: scale(1); opacity: .55 } to { transform: scale(1.5); opacity: 0 } }
            @keyframes lab-ps-word { from { transform: translateY(40%); opacity: 0; filter: blur(3px) } to { transform: none; opacity: 1; filter: none } }
            .lab-ps-draw { stroke-dasharray: 1; animation: lab-ps-draw .5s ${EASE} .15s both }
            .lab-ps-pulse { animation: lab-ps-pulse 1.1s ${EASE} both; transform-origin: 50% 50% }
            .lab-ps-word { animation: lab-ps-word .45s ${EASE} both }
            @media (prefers-reduced-motion: reduce) { .lab-ps-draw, .lab-ps-pulse, .lab-ps-word { animation: none } }
          `}</style>
    
          <div className="lab-ps-body">
            <div className="lab-ps-ring relative aspect-square shrink-0">
              {done && <span key={`p${run}`} className="lab-ps-pulse absolute inset-0 rounded-full" style={{ boxShadow: `0 0 0 2px ${color}` }} />}
              <svg viewBox="0 0 100 100" className="h-full w-full" fill="none" aria-hidden>
                <circle cx="50" cy="50" r={R} stroke="var(--color-ink)" strokeOpacity="0.1" strokeWidth="4" />
                <g ref={spinner}>
                  <circle
                    cx="50"
                    cy="50"
                    r={R}
                    stroke={color}
                    strokeWidth="4"
                    strokeLinecap="round"
                    strokeDasharray={C}
                    strokeDashoffset={dash}
                    transform="rotate(-90 50 50)"
                    style={{
                      transition: `stroke-dashoffset ${phase === "verifying" ? 1.5 : 0.7}s ${phase === "verifying" ? "cubic-bezier(.45,0,.2,1)" : EASE}, stroke .5s`,
                    }}
                  />
                </g>
                <g style={{ opacity: fading ? 0 : 1, transition: `opacity .4s ${EASE}` }}>
                {done && (
                  <circle cx="50" cy="50" r={R - 9} fill={color} fillOpacity="0.12" style={{ transition: "fill .4s" }} />
                )}
                {phase === "paid" && <path key={`c${run}`} className="lab-ps-draw" pathLength={1} d="M34 51 45 62 67 39" stroke={OK} strokeWidth="5" strokeLinecap="round" strokeLinejoin="round" />}
                {phase === "declined" && (
                  <path key={`x${run}`} className="lab-ps-draw" pathLength={1} d="M38 38 62 62M62 38 38 62" stroke={BAD} strokeWidth="5" strokeLinecap="round" />
                )}
                </g>
              </svg>
            </div>
    
            <div className="lab-ps-text flex flex-col gap-1.5">
              <span className="font-medium tabular-nums tracking-[-0.03em] text-ink" style={{ fontSize: "clamp(26px, 11cqh, 44px)", lineHeight: 1 }}>
                $248.50
              </span>
              <span key={phase} className="lab-ps-word text-[14px]" style={{ color: done ? color : "var(--color-mute)", opacity: fading ? 0 : 1, transition: `opacity .4s ${EASE}` }}>
                {WORD[phase]}
              </span>
            </div>
          </div>
        </button>
      );
    }
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Payment status component to my project.
    
    One ring: processing, verifying, done.
    It fills its parent, so give the wrapper a size. It is designed on a dark surface: put it inside an element with the `dark` class.
    
    Install it:
    ```sh
    pnpm dlx asta-ui@latest add payment-status --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/payment-status.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import PaymentStatus from "@/components/astabyte/payment-status";
    ```
    
    Usage example and props: https://ui.astabyte.com/payment-status
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]

Usage

It fills its parent. Give the wrapper a size.

import PaymentStatus from "@/components/astabyte/payment-status";

export default function Page() {
  // Payment status
  return (
    <div className="relative h-96 w-full">
      <PaymentStatus />
    </div>
  );
}