Skip to content
Haze UI

Metric card

An executive KPI card with timeframe switching, a dual-series Bezier chart with hover readout, and a proportional breakdown.

pnpm dlx shadcn@latest add @haze/metric-card
Open preview in a new tab
Livesmall script

When to use

  • A dashboard tile presents a headline KPI alongside interactive timeframe switching (7D, 30D, 90D) and period-over-period comparison
  • Users benefit from seeing both trajectory against the previous period and a compact revenue or usage mix breakdown in one card

When not to use

  • You need a minimal figure without charts or timeframe switching. Use stat.
  • You need full multi-axis charting with zoom and export controls. Use line-chart.

Installation

Add the Haze registry to components.json once, then install Metric card with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/metric-card
First 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

PropTypeDefaultDescription
idstring"haze-metric-card"Unique identifier used to scope the SVG area gradient.
labelstring"Revenue"Metric title rendered in the card header.
timeframesMetricTimeframe[]–Array of timeframe datasets (id, label, value, delta, series, previousSeries, breakdown) for the pill switcher.
defaultTimeframestring"30d"Timeframe id selected on initial render.
headingLevel2 | 3 | 43Heading level for the metric label.
classstring–Additional classes on the outer card element.

Keyboard interactions

TabEnter or Space
Switch between 7D, 30D, and 90D timeframe pills.
Left or Right Arrow
Step through individual data points when the trend chart is focused.
Escape
Clear the active point readout and return to the latest endpoint.

Accessibility

  • Timeframe pills are native buttons with aria-pressed state and clear focus rings.
  • The delta readout pairs a directional triangle with screen-reader phrasing ('Increased by' / 'Decreased by') so meaning never relies on color alone.
  • The chart container is keyboard-focusable and supports Left/Right arrow inspection, announcing the hovered or focused data point in an aria-live readout.

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 component "Metric card" with `npx shadcn@latest add @haze/metric-card`. 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 MetricCard from "@/components/haze/ui/metric-card.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/ui/metric-card.md

  • Customize with real content

    Adapt the Haze metric-card ui for our product. Replace the demo values of these props with our real content: id, label, timeframes, defaultTimeframe, headingLevel, class. Keep the layout, the heading level rules and these accessibility details: Timeframe pills are native buttons with aria-pressed state and clear focus rings. The delta readout pairs a directional triangle with screen-reader phrasing ('Increased by' / 'Decreased by') so meaning never relies on color alone. The chart container is keyboard-focusable and supports Left/Right arrow inspection, announcing the hovered or focused data point in an aria-live readout. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using metric-card, check it fits: use it when a dashboard tile presents a headline kpi alongside interactive timeframe switching (7d, 30d, 90d) and period-over-period comparison; users benefit from seeing both trajectory against the previous period and a compact revenue or usage mix breakdown in one card. Avoid it when you need a minimal figure without charts or timeframe switching. use stat.; you need full multi-axis charting with zoom and export controls. use line-chart.. Alternatives: @haze/stat, @haze/sparkline, @haze/line-chart.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog