Skip to content
Organisms

Billing

Plan, usage, card and past invoices.

Primitive

Installation

Primitive
  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/, installs radix-ui@base-ui/react and the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.

    $ pnpm dlx asta-ui@latest add billing --radix

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/billing.json

  2. Or install the package

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

    $ pnpm add asta-ui radix-ui @base-ui/react
    import { Billing } from "asta-ui";
    import { Billing } from "asta-ui/base";
  3. Or copy it by hand

    Install radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useMemo, useState, type ReactNode } from "react";
    import { Button } from "@/components/kit/button";
    import { Meter } from "@/components/kit/meter";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    const KEYFRAMES = `@keyframes asta-billing-roll { from { opacity: 0; transform: translateY(55%) } }
    @keyframes asta-billing-in { from { opacity: 0; transform: translateY(-4px) } }
    @media (prefers-reduced-motion: reduce) { .asta-billing-a { animation: none !important } }`;
    
    export interface BillingPlan {
      id: string;
      name: string;
      /** Price per month. */
      price: number;
      /** One short line, e.g. "For small teams". */
      blurb?: string;
      features?: string[];
    }
    
    export interface BillingUsage {
      label: string;
      value: number;
      max: number;
      format?: (n: number) => string;
    }
    
    export interface BillingInvoice {
      id: string;
      /** Already formatted. */
      date: string;
      amount: number;
      status: "paid" | "due" | "failed";
      href?: string;
    }
    
    export interface BillingProps {
      plans: BillingPlan[];
      currentPlan: string;
      /** Already formatted renewal date, e.g. "Dec 1, 2026". */
      renewsOn: string;
      /** Days left in the period and its length, for the proration preview. */
      daysLeft?: number;
      periodDays?: number;
      usage?: BillingUsage[];
      /** Card on file. Leave the network out; the last four digits and expiry are enough. */
      card?: { last4: string; expires: string; holder?: string };
      invoices?: BillingInvoice[];
      currency?: string;
      locale?: string;
      /** Resolve to switch plans, throw to stay. */
      onChangePlan?: (id: string) => Promise<void> | void;
      onUpdateCard?: () => void;
      className?: string;
    }
    
    /** A number that rolls up into place when it changes. */
    function Roll({ children }: { children: string }) {
      return (
        <span className="inline-flex overflow-hidden align-bottom" aria-live="polite">
          <span key={children} className="asta-billing-a inline-block animate-[asta-billing-roll_.45s_cubic-bezier(.16,1,.3,1)_both] tabular-nums">
            {children}
          </span>
        </span>
      );
    }
    
    function Group({ title, hint, children, aside }: { title: string; hint?: string; children: ReactNode; aside?: ReactNode }) {
      return (
        <section className="grid gap-3 py-6 first:pt-0 @min-[720px]:grid-cols-[220px_1fr] @min-[720px]:gap-10">
          <div className="flex items-start justify-between gap-3 @min-[720px]:block">
            <div>
              <h3 className="text-[14px] font-medium tracking-[-0.01em]">{title}</h3>
              {hint && <p className="mt-1 text-[12.5px] leading-relaxed text-mute">{hint}</p>}
            </div>
            {aside && <div className="@min-[720px]:mt-3">{aside}</div>}
          </div>
          <div className="min-w-0">{children}</div>
        </section>
      );
    }
    
    const rowCls = "flex items-center gap-3 rounded-[10px] bg-paper-2 px-4 py-3";
    
    /**
     * A billing settings page: the current plan with its renewal date, a plan picker that previews the prorated amount
     * due today (the numbers roll as you pick), usage meters, the card on file and past invoices. Laid out as grouped
     * rows that use the full width, with titles on the left once the container is wide enough.
     */
    export function Billing({ plans, currentPlan, renewsOn, daysLeft = 0, periodDays = 30, usage = [], card, invoices = [], currency = "USD", locale = "en-US", onChangePlan, onUpdateCard, className }: BillingProps) {
      const [current, setCurrent] = useState(currentPlan);
      const [pick, setPick] = useState<string | null>(null);
      const [saving, setSaving] = useState(false);
      const [done, setDone] = useState<string | null>(null);
      // Two formatters, built once: whole amounts and amounts with cents.
      const money = useMemo(() => {
        const whole = new Intl.NumberFormat(locale, { style: "currency", currency, minimumFractionDigits: 0 });
        const cents = new Intl.NumberFormat(locale, { style: "currency", currency, minimumFractionDigits: 2 });
        return (n: number) => (n % 1 ? cents : whole).format(n);
      }, [locale, currency]);
    
      const cur = plans.find((p) => p.id === current) ?? plans[0];
      const next = pick ? plans.find((p) => p.id === pick) : undefined;
      const share = periodDays ? daysLeft / periodDays : 0;
      const credit = Math.round(cur.price * share * 100) / 100;
      const charge = next ? Math.round(next.price * share * 100) / 100 : 0;
      const today = Math.max(0, Math.round((charge - credit) * 100) / 100);
      const upgrade = next ? next.price > cur.price : false;
    
      const confirm = async () => {
        if (!next || saving) return;
        setSaving(true);
        try {
          await onChangePlan?.(next.id);
          setCurrent(next.id);
          setDone(`You're on ${next.name} now.`);
          setPick(null);
        } finally {
          setSaving(false);
        }
      };
    
      return (
        <div className={cx("@container w-full text-ink", className)}>
          <style href="asta-billing" precedence="asta">{KEYFRAMES}</style>
          <div className="flex flex-col">
            <Group title="Plan" hint={`Renews on ${renewsOn}. Change any time; we prorate the rest of the month.`}>
              <div role="radiogroup" aria-label="Plan" className="grid gap-2 @min-[560px]:grid-cols-3">
                {plans.map((p) => {
                  const isCur = p.id === current;
                  const on = (pick ?? current) === p.id;
                  return (
                    <button
                      key={p.id}
                      type="button"
                      role="radio"
                      aria-checked={on}
                      onClick={() => {
                        setPick(isCur ? null : p.id);
                        setDone(null);
                      }}
                      className={cx(
                        "group/plan relative flex flex-col gap-1 rounded-[12px] p-4 text-left outline-none transition-[box-shadow,background-color] duration-200 focus-visible:ring-2 focus-visible:ring-brand/50",
                        on ? "bg-paper shadow-[inset_0_0_0_2px_var(--color-brand)]" : "bg-paper-2 hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_18%,transparent)]",
                      )}
                    >
                      <span className="flex items-center justify-between gap-2">
                        <span className="text-[13.5px] font-medium">{p.name}</span>
                        {isCur && <span className="rounded-md bg-ink px-1.5 py-0.5 text-[10.5px] font-medium text-paper">Current</span>}
                      </span>
                      <span className="text-[22px] font-medium tracking-[-0.03em] tabular-nums">
                        {money(p.price)}
                        <span className="text-[12.5px] font-normal tracking-normal text-mute"> /mo</span>
                      </span>
                      {p.blurb && <span className="text-[12px] text-mute">{p.blurb}</span>}
                      {p.features && (
                        <ul className="mt-2 flex flex-col gap-1 text-[12px] text-ink-2">
                          {p.features.map((f) => (
                            <li key={f} className="flex gap-1.5">
                              <svg viewBox="0 0 24 24" className="mt-[3px] h-3 w-3 shrink-0 text-brand" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
                                <path d="m5 12.5 4.5 4.5L19 7.5" />
                              </svg>
                              {f}
                            </li>
                          ))}
                        </ul>
                      )}
                    </button>
                  );
                })}
              </div>
    
              {next ? (
                <div key="preview" className="asta-billing-a mt-3 flex animate-[asta-billing-in_.35s_cubic-bezier(.16,1,.3,1)_both] flex-col gap-4 rounded-[12px] bg-paper-2 p-4">
                  <dl className="grid flex-1 grid-cols-3 gap-3 text-[12px]">
                    <div>
                      <dt className="text-mute">{next.name}, {daysLeft} days</dt>
                      <dd className="mt-0.5 text-[14px] font-medium">
                        <Roll>{money(charge)}</Roll>
                      </dd>
                    </div>
                    <div>
                      <dt className="text-mute">Unused {cur.name}</dt>
                      <dd className="mt-0.5 text-[14px] font-medium">
                        <Roll>{`−${money(credit)}`}</Roll>
                      </dd>
                    </div>
                    <div>
                      <dt className="text-mute">{upgrade ? "Due today" : "Credit"}</dt>
                      <dd className="mt-0.5 text-[14px] font-medium text-brand">
                        <Roll>{upgrade ? money(today) : money(Math.max(0, credit - charge))}</Roll>
                      </dd>
                    </div>
                  </dl>
                  <div className="flex justify-end gap-2 @max-[559px]:[&>*]:flex-1">
                    <Button size="sm" variant="ghost" onClick={() => setPick(null)}>
                      Cancel
                    </Button>
                    <Button size="sm" variant="accent" loading={saving} onClick={confirm}>
                      {upgrade ? `Upgrade to ${next.name}` : `Switch to ${next.name}`}
                    </Button>
                  </div>
                </div>
              ) : (
                <p className="mt-3 h-5 text-[12.5px] text-mute" aria-live="polite">
                  {done ?? `${cur.name} · ${money(cur.price)} a month · next charge on ${renewsOn}`}
                </p>
              )}
            </Group>
    
            {usage.length > 0 && (
              <Group title="Usage" hint="This billing period. Limits reset on renewal.">
                <div className="grid gap-3 @min-[560px]:grid-cols-2">
                  {usage.map((u) => (
                    <div key={u.label} className="rounded-[12px] bg-paper-2 p-4">
                      <Meter label={u.label} value={u.value} max={u.max} format={u.format} size="sm" />
                    </div>
                  ))}
                </div>
              </Group>
            )}
    
            {card && (
              <Group title="Payment method" hint="Charged on each renewal.">
                <div className={rowCls}>
                  <span className="grid h-8 w-12 shrink-0 place-items-center rounded-md bg-ink text-paper" aria-hidden>
                    <svg viewBox="0 0 24 24" className="h-4 w-6" fill="none" stroke="currentColor" strokeWidth="2.1" strokeLinecap="round" strokeLinejoin="round">
                      <rect x="3" y="5.5" width="18" height="13" rx="2" />
                      <path d="M3 10h18" />
                      <path d="M6.5 15h3" />
                    </svg>
                  </span>
                  <span className="min-w-0 flex-1">
                    <span className="block text-[13.5px] font-medium">Card ending {card.last4}</span>
                    <span className="block truncate text-[12px] text-mute">
                      Expires {card.expires}
                      {card.holder ? ` · ${card.holder}` : ""}
                    </span>
                  </span>
                  {onUpdateCard && (
                    <Button size="xs" variant="outline" onClick={onUpdateCard}>
                      Update
                    </Button>
                  )}
                </div>
              </Group>
            )}
    
            {invoices.length > 0 && (
              <Group title="Invoices" hint="Download any invoice as a PDF.">
                <ul className="flex flex-col gap-1">
                  {invoices.map((inv) => (
                    <li key={inv.id} className="flex items-center gap-3 rounded-[10px] px-4 py-2.5 text-[13px] odd:bg-paper-2">
                      <span className="w-[92px] shrink-0 tabular-nums text-ink-2 @max-[420px]:w-auto">{inv.date}</span>
                      <span className="hidden min-w-0 flex-1 truncate font-mono text-[12px] text-mute @min-[480px]:block">{inv.id}</span>
                      <span className="ml-auto font-medium tabular-nums @min-[480px]:ml-0">{money(inv.amount)}</span>
                      <span className={cx("w-[52px] shrink-0 text-right text-[12px]", inv.status === "paid" ? "text-mute" : inv.status === "due" ? "text-ink" : "font-medium text-ink")}>
                        {inv.status === "paid" ? "Paid" : inv.status === "due" ? "Due" : "Failed"}
                      </span>
                      {inv.href ? (
                        <a href={inv.href} aria-label={`Download ${inv.id}`} className="grid h-7 w-7 shrink-0 place-items-center rounded-md text-mute outline-none transition-colors hover:bg-paper hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50">
                          <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
                            <path d="M12 4v11" />
                            <path d="m7 10 5 5 5-5" />
                            <path d="M5 19.5h14" />
                          </svg>
                        </a>
                      ) : (
                        <span className="w-7 shrink-0" />
                      )}
                    </li>
                  ))}
                </ul>
              </Group>
            )}
          </div>
        </div>
      );
    }
    
    export default Billing;
    
    "use client";
    
    import { useMemo, useState, type ReactNode } from "react";
    import { Button } from "@/components/kit/base/button";
    import { Meter } from "@/components/kit/meter";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    const KEYFRAMES = `@keyframes asta-billing-roll { from { opacity: 0; transform: translateY(55%) } }
    @keyframes asta-billing-in { from { opacity: 0; transform: translateY(-4px) } }
    @media (prefers-reduced-motion: reduce) { .asta-billing-a { animation: none !important } }`;
    
    export interface BillingPlan {
      id: string;
      name: string;
      /** Price per month. */
      price: number;
      /** One short line, e.g. "For small teams". */
      blurb?: string;
      features?: string[];
    }
    
    export interface BillingUsage {
      label: string;
      value: number;
      max: number;
      format?: (n: number) => string;
    }
    
    export interface BillingInvoice {
      id: string;
      /** Already formatted. */
      date: string;
      amount: number;
      status: "paid" | "due" | "failed";
      href?: string;
    }
    
    export interface BillingProps {
      plans: BillingPlan[];
      currentPlan: string;
      /** Already formatted renewal date, e.g. "Dec 1, 2026". */
      renewsOn: string;
      /** Days left in the period and its length, for the proration preview. */
      daysLeft?: number;
      periodDays?: number;
      usage?: BillingUsage[];
      /** Card on file. Leave the network out; the last four digits and expiry are enough. */
      card?: { last4: string; expires: string; holder?: string };
      invoices?: BillingInvoice[];
      currency?: string;
      locale?: string;
      /** Resolve to switch plans, throw to stay. */
      onChangePlan?: (id: string) => Promise<void> | void;
      onUpdateCard?: () => void;
      className?: string;
    }
    
    /** A number that rolls up into place when it changes. */
    function Roll({ children }: { children: string }) {
      return (
        <span className="inline-flex overflow-hidden align-bottom" aria-live="polite">
          <span key={children} className="asta-billing-a inline-block animate-[asta-billing-roll_.45s_cubic-bezier(.16,1,.3,1)_both] tabular-nums">
            {children}
          </span>
        </span>
      );
    }
    
    function Group({ title, hint, children, aside }: { title: string; hint?: string; children: ReactNode; aside?: ReactNode }) {
      return (
        <section className="grid gap-3 py-6 first:pt-0 @min-[720px]:grid-cols-[220px_1fr] @min-[720px]:gap-10">
          <div className="flex items-start justify-between gap-3 @min-[720px]:block">
            <div>
              <h3 className="text-[14px] font-medium tracking-[-0.01em]">{title}</h3>
              {hint && <p className="mt-1 text-[12.5px] leading-relaxed text-mute">{hint}</p>}
            </div>
            {aside && <div className="@min-[720px]:mt-3">{aside}</div>}
          </div>
          <div className="min-w-0">{children}</div>
        </section>
      );
    }
    
    const rowCls = "flex items-center gap-3 rounded-[10px] bg-paper-2 px-4 py-3";
    
    /**
     * A billing settings page: the current plan with its renewal date, a plan picker that previews the prorated amount
     * due today (the numbers roll as you pick), usage meters, the card on file and past invoices. Laid out as grouped
     * rows that use the full width, with titles on the left once the container is wide enough.
     */
    export function Billing({ plans, currentPlan, renewsOn, daysLeft = 0, periodDays = 30, usage = [], card, invoices = [], currency = "USD", locale = "en-US", onChangePlan, onUpdateCard, className }: BillingProps) {
      const [current, setCurrent] = useState(currentPlan);
      const [pick, setPick] = useState<string | null>(null);
      const [saving, setSaving] = useState(false);
      const [done, setDone] = useState<string | null>(null);
      // Two formatters, built once: whole amounts and amounts with cents.
      const money = useMemo(() => {
        const whole = new Intl.NumberFormat(locale, { style: "currency", currency, minimumFractionDigits: 0 });
        const cents = new Intl.NumberFormat(locale, { style: "currency", currency, minimumFractionDigits: 2 });
        return (n: number) => (n % 1 ? cents : whole).format(n);
      }, [locale, currency]);
    
      const cur = plans.find((p) => p.id === current) ?? plans[0];
      const next = pick ? plans.find((p) => p.id === pick) : undefined;
      const share = periodDays ? daysLeft / periodDays : 0;
      const credit = Math.round(cur.price * share * 100) / 100;
      const charge = next ? Math.round(next.price * share * 100) / 100 : 0;
      const today = Math.max(0, Math.round((charge - credit) * 100) / 100);
      const upgrade = next ? next.price > cur.price : false;
    
      const confirm = async () => {
        if (!next || saving) return;
        setSaving(true);
        try {
          await onChangePlan?.(next.id);
          setCurrent(next.id);
          setDone(`You're on ${next.name} now.`);
          setPick(null);
        } finally {
          setSaving(false);
        }
      };
    
      return (
        <div className={cx("@container w-full text-ink", className)}>
          <style href="asta-billing" precedence="asta">{KEYFRAMES}</style>
          <div className="flex flex-col">
            <Group title="Plan" hint={`Renews on ${renewsOn}. Change any time; we prorate the rest of the month.`}>
              <div role="radiogroup" aria-label="Plan" className="grid gap-2 @min-[560px]:grid-cols-3">
                {plans.map((p) => {
                  const isCur = p.id === current;
                  const on = (pick ?? current) === p.id;
                  return (
                    <button
                      key={p.id}
                      type="button"
                      role="radio"
                      aria-checked={on}
                      onClick={() => {
                        setPick(isCur ? null : p.id);
                        setDone(null);
                      }}
                      className={cx(
                        "group/plan relative flex flex-col gap-1 rounded-[12px] p-4 text-left outline-none transition-[box-shadow,background-color] duration-200 focus-visible:ring-2 focus-visible:ring-brand/50",
                        on ? "bg-paper shadow-[inset_0_0_0_2px_var(--color-brand)]" : "bg-paper-2 hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_18%,transparent)]",
                      )}
                    >
                      <span className="flex items-center justify-between gap-2">
                        <span className="text-[13.5px] font-medium">{p.name}</span>
                        {isCur && <span className="rounded-md bg-ink px-1.5 py-0.5 text-[10.5px] font-medium text-paper">Current</span>}
                      </span>
                      <span className="text-[22px] font-medium tracking-[-0.03em] tabular-nums">
                        {money(p.price)}
                        <span className="text-[12.5px] font-normal tracking-normal text-mute"> /mo</span>
                      </span>
                      {p.blurb && <span className="text-[12px] text-mute">{p.blurb}</span>}
                      {p.features && (
                        <ul className="mt-2 flex flex-col gap-1 text-[12px] text-ink-2">
                          {p.features.map((f) => (
                            <li key={f} className="flex gap-1.5">
                              <svg viewBox="0 0 24 24" className="mt-[3px] h-3 w-3 shrink-0 text-brand" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
                                <path d="m5 12.5 4.5 4.5L19 7.5" />
                              </svg>
                              {f}
                            </li>
                          ))}
                        </ul>
                      )}
                    </button>
                  );
                })}
              </div>
    
              {next ? (
                <div key="preview" className="asta-billing-a mt-3 flex animate-[asta-billing-in_.35s_cubic-bezier(.16,1,.3,1)_both] flex-col gap-4 rounded-[12px] bg-paper-2 p-4">
                  <dl className="grid flex-1 grid-cols-3 gap-3 text-[12px]">
                    <div>
                      <dt className="text-mute">{next.name}, {daysLeft} days</dt>
                      <dd className="mt-0.5 text-[14px] font-medium">
                        <Roll>{money(charge)}</Roll>
                      </dd>
                    </div>
                    <div>
                      <dt className="text-mute">Unused {cur.name}</dt>
                      <dd className="mt-0.5 text-[14px] font-medium">
                        <Roll>{`−${money(credit)}`}</Roll>
                      </dd>
                    </div>
                    <div>
                      <dt className="text-mute">{upgrade ? "Due today" : "Credit"}</dt>
                      <dd className="mt-0.5 text-[14px] font-medium text-brand">
                        <Roll>{upgrade ? money(today) : money(Math.max(0, credit - charge))}</Roll>
                      </dd>
                    </div>
                  </dl>
                  <div className="flex justify-end gap-2 @max-[559px]:[&>*]:flex-1">
                    <Button size="sm" variant="ghost" onClick={() => setPick(null)}>
                      Cancel
                    </Button>
                    <Button size="sm" variant="accent" loading={saving} onClick={confirm}>
                      {upgrade ? `Upgrade to ${next.name}` : `Switch to ${next.name}`}
                    </Button>
                  </div>
                </div>
              ) : (
                <p className="mt-3 h-5 text-[12.5px] text-mute" aria-live="polite">
                  {done ?? `${cur.name} · ${money(cur.price)} a month · next charge on ${renewsOn}`}
                </p>
              )}
            </Group>
    
            {usage.length > 0 && (
              <Group title="Usage" hint="This billing period. Limits reset on renewal.">
                <div className="grid gap-3 @min-[560px]:grid-cols-2">
                  {usage.map((u) => (
                    <div key={u.label} className="rounded-[12px] bg-paper-2 p-4">
                      <Meter label={u.label} value={u.value} max={u.max} format={u.format} size="sm" />
                    </div>
                  ))}
                </div>
              </Group>
            )}
    
            {card && (
              <Group title="Payment method" hint="Charged on each renewal.">
                <div className={rowCls}>
                  <span className="grid h-8 w-12 shrink-0 place-items-center rounded-md bg-ink text-paper" aria-hidden>
                    <svg viewBox="0 0 24 24" className="h-4 w-6" fill="none" stroke="currentColor" strokeWidth="2.1" strokeLinecap="round" strokeLinejoin="round">
                      <rect x="3" y="5.5" width="18" height="13" rx="2" />
                      <path d="M3 10h18" />
                      <path d="M6.5 15h3" />
                    </svg>
                  </span>
                  <span className="min-w-0 flex-1">
                    <span className="block text-[13.5px] font-medium">Card ending {card.last4}</span>
                    <span className="block truncate text-[12px] text-mute">
                      Expires {card.expires}
                      {card.holder ? ` · ${card.holder}` : ""}
                    </span>
                  </span>
                  {onUpdateCard && (
                    <Button size="xs" variant="outline" onClick={onUpdateCard}>
                      Update
                    </Button>
                  )}
                </div>
              </Group>
            )}
    
            {invoices.length > 0 && (
              <Group title="Invoices" hint="Download any invoice as a PDF.">
                <ul className="flex flex-col gap-1">
                  {invoices.map((inv) => (
                    <li key={inv.id} className="flex items-center gap-3 rounded-[10px] px-4 py-2.5 text-[13px] odd:bg-paper-2">
                      <span className="w-[92px] shrink-0 tabular-nums text-ink-2 @max-[420px]:w-auto">{inv.date}</span>
                      <span className="hidden min-w-0 flex-1 truncate font-mono text-[12px] text-mute @min-[480px]:block">{inv.id}</span>
                      <span className="ml-auto font-medium tabular-nums @min-[480px]:ml-0">{money(inv.amount)}</span>
                      <span className={cx("w-[52px] shrink-0 text-right text-[12px]", inv.status === "paid" ? "text-mute" : inv.status === "due" ? "text-ink" : "font-medium text-ink")}>
                        {inv.status === "paid" ? "Paid" : inv.status === "due" ? "Due" : "Failed"}
                      </span>
                      {inv.href ? (
                        <a href={inv.href} aria-label={`Download ${inv.id}`} className="grid h-7 w-7 shrink-0 place-items-center rounded-md text-mute outline-none transition-colors hover:bg-paper hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50">
                          <svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
                            <path d="M12 4v11" />
                            <path d="m7 10 5 5 5-5" />
                            <path d="M5 19.5h14" />
                          </svg>
                        </a>
                      ) : (
                        <span className="w-7 shrink-0" />
                      )}
                    </li>
                  ))}
                </ul>
              </Group>
            )}
          </div>
        </div>
      );
    }
    
    export default Billing;
    
  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 Billing component to my project.
    
    Plan, usage, card and past invoices.
    It includes: plan, change plan, usage, payment method, invoices, proration.
    
    Install it (Radix build):
    ```sh
    pnpm dlx asta-ui@latest add billing --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/billing.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 { Billing } from "@/components/astabyte/billing";
    ```
    
    Usage example and props: https://ui.astabyte.com/billing
    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 (interactive pieces are built on Radix primitives from the radix-ui package).
    - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
    Add the Astabyte UI Billing component to my project.
    
    Plan, usage, card and past invoices.
    It includes: plan, change plan, usage, payment method, invoices, proration.
    
    Install it (Base UI build):
    ```sh
    pnpm dlx asta-ui@latest add billing
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/billing.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` 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 { Billing } from "@/components/astabyte/billing";
    ```
    
    Usage example and props: https://ui.astabyte.com/billing
    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 (interactive pieces are built on Base UI primitives from the @base-ui/react package).
    - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <!-- Plan cards are real radios: post the form, or hx-post on change to preview the prorated amount. -->
    <form class="asta-billing" style="max-width:920px" onsubmit="return false">
    <section class="asta-billing-group"><div><h3 class="asta-billing-title">Plan</h3><p class="asta-billing-hint">Renews on Dec 1, 2026. Change any time; we prorate the rest of the month.</p></div><div class="asta-billing-plans" role="radiogroup" aria-label="Plan"><label class="asta-billing-plan"><input type="radio" name="plan" value="starter"><span class="asta-billing-plan-name">Starter</span><span class="asta-billing-plan-price">$12<small> /mo</small></span><span style="font-size:12px;color:var(--mute)">For one person</span><ul><li>3 projects</li><li>10 GB storage</li><li>Email support</li></ul></label><label class="asta-billing-plan"><input type="radio" name="plan" value="team" checked><span class="asta-billing-plan-name">Team <span class="asta-billing-plan-current">Current</span></span><span class="asta-billing-plan-price">$48<small> /mo</small></span><span style="font-size:12px;color:var(--mute)">For small teams</span><ul><li>Unlimited projects</li><li>100 GB storage</li><li>Shared libraries</li></ul></label><label class="asta-billing-plan"><input type="radio" name="plan" value="scale"><span class="asta-billing-plan-name">Scale</span><span class="asta-billing-plan-price">$120<small> /mo</small></span><span style="font-size:12px;color:var(--mute)">For growing studios</span><ul><li>Everything in Team</li><li>1 TB storage</li><li>SSO and audit log</li></ul></label></div></section>
    <section class="asta-billing-group"><div><h3 class="asta-billing-title">Usage</h3><p class="asta-billing-hint">This billing period.</p></div><div class="asta-billing-usage"><div><div class="asta-meter asta-meter-sm" role="meter" aria-label="Storage" aria-valuenow="82" aria-valuemin="0" aria-valuemax="100"><div class="asta-meter-head"><span class="asta-meter-label">Storage</span></div><div class="asta-meter-track"><span class="asta-meter-fill" style="--value:0.820"></span></div><div class="asta-meter-foot"><span><b>82 GB</b> of 100 GB</span><span>82% used</span></div></div></div><div><div class="asta-meter asta-meter-sm" role="meter" aria-label="Seats" aria-valuenow="8" aria-valuemin="0" aria-valuemax="10"><div class="asta-meter-head"><span class="asta-meter-label">Seats</span></div><div class="asta-meter-track"><span class="asta-meter-fill" style="--value:0.800"></span></div><div class="asta-meter-foot"><span><b>8</b> of 10</span><span>80% used</span></div></div></div></div></section>
    <section class="asta-billing-group"><div><h3 class="asta-billing-title">Payment method</h3><p class="asta-billing-hint">Charged on each renewal.</p></div><div class="asta-billing-row"><span style="display:grid;place-items:center;width:48px;height:32px;border-radius:6px;background:var(--ink);color:var(--paper)" aria-hidden="true"><svg viewBox="0 0 24 16" width="24" height="16" fill="none" stroke="currentColor" stroke-width="1.4"><rect x="1.5" y="1.5" width="21" height="13" rx="2"/><path d="M1.5 5.5h21M5 11h4"/></svg></span><span><b>Card ending 4821</b>Expires 08/28 · Astabyte Studio</span><button type="button" class="asta-btn asta-btn-outline asta-btn-sm"><span class="asta-btn-label">Update</span></button></div></section>
    <section class="asta-billing-group"><div><h3 class="asta-billing-title">Invoices</h3><p class="asta-billing-hint">Download any invoice as a PDF.</p></div><ul class="asta-billing-invoices"><li><span>Nov 1, 2026</span><code>INV-2026-0111</code><b>$48.00</b><span style="font-size:12px;color:var(--mute)">Paid</span><a href="#" class="asta-btn asta-btn-ghost asta-btn-sm asta-btn-icon" aria-label="Download INV-2026-0111"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5v8M4.5 7 8 10.5 11.5 7M3 13.5h10"/></svg></a></li><li><span>Oct 1, 2026</span><code>INV-2026-0098</code><b>$48.00</b><span style="font-size:12px;color:var(--mute)">Paid</span><a href="#" class="asta-btn asta-btn-ghost asta-btn-sm asta-btn-icon" aria-label="Download INV-2026-0098"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5v8M4.5 7 8 10.5 11.5 7M3 13.5h10"/></svg></a></li><li><span>Sep 1, 2026</span><code>INV-2026-0083</code><b>$36.80</b><span style="font-size:12px;color:var(--mute)">Paid</span><a href="#" class="asta-btn asta-btn-ghost asta-btn-sm asta-btn-icon" aria-label="Download INV-2026-0083"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5v8M4.5 7 8 10.5 11.5 7M3 13.5h10"/></svg></a></li></ul></section>
    </form>

Usage

The demo above, as code.

"use client";

import { useState } from "react";
import { Billing } from "@/components/astabyte/billing";

const GB = (n: number) => `${Math.round(n)} GB`;

export default function BillingDemo() {
  const [note, setNote] = useState("");
  return (
    <div className="flex min-h-[640px] w-full justify-center p-4 sm:p-8">
      <div className="w-full max-w-[920px]">
        <div className="mb-6">
          <h2 className="text-[20px] font-medium tracking-[-0.03em]">Billing</h2>
          <p className="mt-1 text-[13px] text-mute">Astabyte workspace · 8 members</p>
        </div>
        <Billing
          currentPlan="team"
          renewsOn="Dec 1, 2026"
          daysLeft={10}
          periodDays={30}
          plans={[
            { id: "starter", name: "Starter", price: 12, blurb: "For one person", features: ["3 projects", "10 GB storage", "Email support"] },
            { id: "team", name: "Team", price: 48, blurb: "For small teams", features: ["Unlimited projects", "100 GB storage", "Shared libraries"] },
            { id: "scale", name: "Scale", price: 120, blurb: "For growing studios", features: ["Everything in Team", "1 TB storage", "SSO and audit log"] },
          ]}
          usage={[
            { label: "Storage", value: 82, max: 100, format: GB },
            { label: "Seats", value: 8, max: 10 },
            { label: "API requests", value: 412_000, max: 1_000_000, format: (n) => `${Math.round(n / 1000)}k` },
            { label: "Exports", value: 37, max: 200 },
          ]}
          card={{ last4: "4821", expires: "08/28", holder: "Astabyte Studio" }}
          onUpdateCard={() => setNote("Card form would open here (demo).")}
          onChangePlan={() => new Promise((r) => setTimeout(r, 1100))}
          invoices={[
            { id: "INV-2026-0111", date: "Nov 1, 2026", amount: 48, status: "paid", href: "#" },
            { id: "INV-2026-0098", date: "Oct 1, 2026", amount: 48, status: "paid", href: "#" },
            { id: "INV-2026-0083", date: "Sep 1, 2026", amount: 36.8, status: "paid", href: "#" },
            { id: "INV-2026-0067", date: "Aug 1, 2026", amount: 12, status: "paid", href: "#" },
          ]}
        />
        <p className="mt-2 h-5 text-[12.5px] text-mute" aria-live="polite">
          {note}
        </p>
      </div>
    </div>
  );
}