Usage billing
Usage-based billing card tracking spend-to-date and projected spend against budget, resource meters and inline cap-increase confirmation.
pnpm dlx shadcn@latest add @haze/usage-billing---
import { AlertTriangle, ArrowUpRight, Check, Gauge } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Meter {
label: string;
used: string;
limit: string;
pct: number;
warn?: boolean;
}
interface Props {
id?: string;
spendToDate?: string;
projected?: string;
budget?: string;
meters?: Meter[];
class?: string;
}
const {
id = "haze-usage-billing",
spendToDate = "$412.60",
projected = "$568.00",
budget = "$600.00",
meters = [
{ label: "Model inference tokens", used: "82.4M", limit: "100M", pct: 82, warn: true },
{ label: "Vector index storage", used: "18.2 GB", limit: "50 GB", pct: 36 },
{ label: "Edge build minutes", used: "1,420 min", limit: "2,000 min", pct: 71 },
],
class: className,
} = Astro.props;
---
<section aria-labelledby={`${id}-title`} data-haze-usage-billing class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-3xl rounded-2xl border border-border bg-card p-5 sm:p-6">
<header class="flex flex-wrap items-start justify-between gap-3 border-b border-border pb-4">
<div class="flex items-start gap-2.5">
<span class="grid size-8 shrink-0 place-items-center rounded-lg border border-frame bg-muted text-muted-foreground" aria-hidden="true">
<Gauge class="size-4" />
</span>
<div>
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">Usage & metered spend</h2>
<p class="text-xs/5 text-muted-foreground">Cycle Nov 1 – Nov 30 · 9 days remaining</p>
</div>
</div>
<span class="inline-flex items-center gap-1.5 rounded-full border border-frame-warning bg-warning/10 px-2.5 py-0.5 text-xs font-medium text-warning">
<AlertTriangle class="size-3.5" aria-hidden="true" />
95% projected cap
</span>
</header>
<div class="mt-4 grid gap-3 sm:grid-cols-3">
<div class="rounded-xl border border-border bg-muted/40 p-3.5">
<p class="text-xs text-muted-foreground">Spend to date</p>
<p class="mt-1 text-2xl/7 font-semibold text-foreground tabular-nums">{spendToDate}</p>
</div>
<div class="rounded-xl border border-border bg-muted/40 p-3.5">
<p class="text-xs text-muted-foreground">Projected spend</p>
<p class="mt-1 text-2xl/7 font-semibold text-warning tabular-nums">{projected}</p>
</div>
<div class="rounded-xl border border-border bg-muted/40 p-3.5">
<p class="text-xs text-muted-foreground">Monthly budget</p>
<p data-ub-budget class="mt-1 text-2xl/7 font-semibold text-foreground tabular-nums">{budget}</p>
</div>
</div>
<div class="mt-5 space-y-3">
{
meters.map((m) => (
<div class="rounded-xl border border-border bg-muted/40 p-3.5">
<div class="flex flex-wrap items-center justify-between gap-2 text-xs">
<span class="font-medium text-foreground">{m.label}</span>
<span class="font-mono text-muted-foreground tabular-nums">{m.used} / {m.limit} ({m.pct}%)</span>
</div>
<div class="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted">
<div class={cn("h-full rounded-full", m.warn ? "bg-warning" : "bg-primary")} style={`width: ${m.pct}%`}></div>
</div>
</div>
))
}
</div>
<div class="mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
<p class="text-xs/5 text-muted-foreground">Raise your monthly cap to avoid rate-limiting on burst traffic.</p>
<button type="button" data-ub-open aria-expanded="false" class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
Increase cap to $1,000
<ArrowUpRight class="size-3.5" aria-hidden="true" />
</button>
</div>
<div data-ub-confirm hidden class="mt-4 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-frame bg-muted/40 p-3.5">
<p class="text-xs font-medium text-foreground">Confirm raising soft budget cap from {budget} to $1,000.00?</p>
<div class="flex items-center gap-2">
<button type="button" data-ub-cancel class="inline-flex h-8 cursor-pointer items-center rounded-lg border border-frame bg-field px-3 text-xs font-medium text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Cancel</button>
<button type="button" data-ub-apply class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg bg-primary px-3 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<Check class="size-3.5" aria-hidden="true" />
Confirm cap
</button>
</div>
</div>
<p data-ub-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</section>
<script>
function initUsageBillings() {
document.querySelectorAll<HTMLElement>("[data-haze-usage-billing]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const open = root.querySelector<HTMLButtonElement>("[data-ub-open]");
const confirm = root.querySelector<HTMLElement>("[data-ub-confirm]");
const budget = root.querySelector<HTMLElement>("[data-ub-budget]");
const status = root.querySelector<HTMLElement>("[data-ub-status]");
open?.addEventListener("click", () => {
if (!confirm) return;
confirm.hidden = !confirm.hidden;
open.setAttribute("aria-expanded", String(!confirm.hidden));
});
root.querySelector<HTMLButtonElement>("[data-ub-cancel]")?.addEventListener("click", () => {
if (confirm) confirm.hidden = true;
open?.setAttribute("aria-expanded", "false");
});
root.querySelector<HTMLButtonElement>("[data-ub-apply]")?.addEventListener("click", () => {
if (budget) budget.textContent = "$1,000.00";
if (confirm) confirm.hidden = true;
open?.setAttribute("aria-expanded", "false");
if (status) status.textContent = "Monthly budget cap raised to $1,000.00.";
});
});
}
initUsageBillings();
document.addEventListener("astro:page-load", initUsageBillings);
</script>When to use
- Monitoring metered AI token, storage or build-minute spend against a monthly budget
- Letting admins confirm a budget cap increase inline before hitting rate limits
When not to use
- Showing fixed seat-based plans and invoice PDFs; use billing-overview
Installation
Add the Haze registry to components.json once, then install Usage billing with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/usage-billingnpx shadcn@latest add @haze/usage-billingyarn dlx shadcn@latest add @haze/usage-billingbunx --bun shadcn@latest add @haze/usage-billingFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-usage-billing" | Unique prefix for section heading IDs. |
| spendToDate | string | "$412.60" | Current accrued spend. |
| projected | string | "$568.00" | End-of-cycle projected spend. |
| budget | string | "$600.00" | Current monthly budget limit. |
| meters | Meter[] | 3 resource meters | Individual usage bars with warning state. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across Increase cap, Cancel and Confirm cap buttons
- EnterSpace
- Open the confirmation bar or confirm the higher monthly cap
Accessibility
- The cap-increase button exposes aria-expanded to reveal the inline confirmation bar.
- Confirming the new budget updates the metric in place and announces the change via role="status".
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "Usage billing" with `npx shadcn@latest add @haze/usage-billing`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import UsageBilling from "@/components/haze/blocks/usage-billing.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/usage-billing.md
Customize with real content
Adapt the Haze usage-billing block for our product. Replace the demo values of these props with our real content: id, spendToDate, projected, budget, meters, class. Keep the layout, the heading level rules and these accessibility details: The cap-increase button exposes aria-expanded to reveal the inline confirmation bar. Confirming the new budget updates the metric in place and announces the change via role="status". Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using usage-billing, check it fits: use it when monitoring metered ai token, storage or build-minute spend against a monthly budget; letting admins confirm a budget cap increase inline before hitting rate limits. Avoid it when showing fixed seat-based plans and invoice pdfs; use billing-overview. Alternatives: @haze/billing-overview, @haze/usage-meter.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.