# Usage meter

> A plan's allowances as labelled bars, turning to warning near the limit and to destructive at it, with an upgrade button.

- Kind: ui · Category: Feedback · Interactivity: none
- Install: `npx shadcn@latest add @haze/usage-meter`
- File: `src/components/haze/ui/usage-meter.astro`
- npm dependencies: none
- Registry dependencies: @haze/button, @haze/progress, @haze/utils
- Docs page: https://hazeui.com/ui/usage-meter

## Use when
- A billing or settings page shows how much of each plan limit is used
- Customers should see a limit coming before they hit it

## Avoid when
- One task is in progress. Use progress.
- The numbers are business results, not allowances. Use stat or bar-list.

## Alternatives
- [progress](https://hazeui.com/ui/progress.md)
- [stat](https://hazeui.com/ui/stat.md)
- [bar-list](https://hazeui.com/ui/bar-list.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| title | `string` | "Team plan" | no | Visible title, usually the plan's name. |
| period | `string` | "Renews on 1 December" | no | Billing period or renewal date. |
| meters | `{ label: string; used: number; limit?: number; unit?: string }[]` |  | no | Allowances; leave out limit for unlimited. |
| warnAt | `number` | 0.8 | no | Share of a limit from which a meter warns. |
| upgradeLabel | `string` | "Upgrade plan" | no | Label of the upgrade button. |
| upgradeHref | `string` | "#upgrade" | no | Target of the upgrade button; empty hides it. |
| locale | `string` | "en" | no | Locale used to format the numbers. |
| unlimitedLabel | `string` | "Unlimited" | no | Word shown for a meter with no limit. |
| headingLevel | `2 \| 3 \| 4` | 3 | no | Level of the title. |
| class | `string` |  | no | Additional classes on the panel. |

## Accessibility
- Each bar is a native progress element named after its allowance, and the exact numbers are written next to it.
- Nearly used up and used up change the number's color, but the numbers themselves already say how close the limit is.
- Key Tab: Reach the upgrade button.

## Agent prompts

### Install and use

Install the Haze UI component "Usage meter" with `npx shadcn@latest add @haze/usage-meter`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/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 UsageMeter from "@/components/haze/ui/usage-meter.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: https://hazeui.com/ui/usage-meter.md

### Customize with real content

Adapt the Haze usage-meter ui for our product. Replace the demo values of these props with our real content: title, period, meters, warnAt, upgradeLabel, upgradeHref, locale, unlimitedLabel, headingLevel, class. Keep the layout, the heading level rules and these accessibility details: Each bar is a native progress element named after its allowance, and the exact numbers are written next to it. Nearly used up and used up change the number's color, but the numbers themselves already say how close the limit is. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using usage-meter, check it fits: use it when a billing or settings page shows how much of each plan limit is used; customers should see a limit coming before they hit it. Avoid it when one task is in progress. use progress.; the numbers are business results, not allowances. use stat or bar-list.. Alternatives: @haze/progress, @haze/stat, @haze/bar-list.

## Example requests that should lead here
- Show the customer's plan usage: agent runs, seats and storage, with an upgrade button.

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";
import Button from "./button.astro";
import Progress from "./progress.astro";

interface Meter {
  label: string;
  used: number;
  /** Leave out for an unlimited allowance. */
  limit?: number;
  /** Unit after the numbers, such as "runs" or "GB". */
  unit?: string;
}

interface Props {
  /** Visible title, such as the plan's name. */
  title?: string;
  /** Line under the title: the billing period or renewal date. */
  period?: string;
  meters?: Meter[];
  /** Share of a limit (0–1) from which a meter shows as nearly used up. */
  warnAt?: number;
  upgradeLabel?: string;
  /** Leave empty to hide the upgrade button. */
  upgradeHref?: string;
  /** Locale used to format the numbers, such as "bs" or "de". */
  locale?: string;
  unlimitedLabel?: string;
  headingLevel?: 2 | 3 | 4;
  class?: string;
}

const {
  title = "Team plan",
  period = "Renews on 1 December",
  meters = [
    { label: "Agent runs", used: 8240, limit: 10000, unit: "runs" },
    { label: "Seats", used: 4, limit: 5, unit: "seats" },
    { label: "Knowledge storage", used: 1.2, limit: 5, unit: "GB" },
    { label: "Connected inboxes", used: 3, unit: "inboxes" },
  ],
  warnAt = 0.8,
  upgradeLabel = "Upgrade plan",
  upgradeHref = "#upgrade",
  locale = "en",
  unlimitedLabel = "Unlimited",
  headingLevel = 3,
  class: className,
} = Astro.props;
const H = `h${headingLevel}` as "h3";
const fmt = new Intl.NumberFormat(locale, { maximumFractionDigits: 1 });
---

<section aria-label={title} class={cn("overflow-hidden rounded-xl border border-border bg-card", className)}>
  <div class="flex flex-wrap items-center justify-between gap-3 border-b border-border px-4.5 py-3.5">
    <div class="min-w-0">
      <H class="text-[0.9375rem] leading-[1.4] font-medium tracking-[-0.01em] text-foreground">{title}</H>
      {period && <p class="text-[0.8125rem]/5 text-muted-foreground">{period}</p>}
    </div>
    {upgradeHref && <Button href={upgradeHref} variant="secondary" size="sm">{upgradeLabel}</Button>}
  </div>
  <ul role="list" class="flex flex-col gap-4 px-4.5 py-4.5">
    {
      meters.map((m) => {
        const share = m.limit ? m.used / m.limit : 0;
        const variant = !m.limit ? "default" : share >= 1 ? "destructive" : share >= warnAt ? "warning" : "default";
        const unit = m.unit ? ` ${m.unit}` : "";
        return (
          <li>
            <div class="flex flex-col gap-0.5 text-[0.8125rem]/5 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3">
              <span class="font-medium tracking-[-0.01em] text-foreground">{m.label}</span>
              <span class={cn("text-xs/5 tabular-nums", variant === "default" ? "text-muted-foreground" : variant === "warning" ? "text-warning" : "text-destructive")}>
                {m.limit ? `${fmt.format(m.used)} of ${fmt.format(m.limit)}${unit}` : `${fmt.format(m.used)}${unit} · ${unlimitedLabel}`}
              </span>
            </div>
            {m.limit ? (
              <Progress label={m.label} hideLabel value={Math.min(m.used, m.limit)} max={m.limit} variant={variant} size="sm" class="mt-2" />
            ) : null}
          </li>
        );
      })
    }
  </ul>
</section>
```
