Skip to main content

MetricGrid

Single Valuechart

Responsive grid of KPI tiles — the summary row at the top of a dashboard.

import { MetricGrid } from "@elabs-ai/components-charts";
Install
npm install @elabs-ai/components-tokens @elabs-ai/components-ui @elabs-ai/components-charts

Skipping the @source line is the most common first failure: Tailwind does not scan node_modules, so every component renders unstyled. The one-time wiring

Prompt for your coding agent

Paste it into Claude Code, Cursor, Codex or any other coding agent. Text in [brackets] is yours to fill in.

Add the brand-ui MetricGrid chart (from @elabs-ai/components-charts) to this project.

1. Read https://elabs-ai.com/llms.txt first: it maps every package and the rules. If you can use MCP servers, connect https://elabs-ai.com/mcp and use its search, docs and tokens tools. If not, run the same lookups in the terminal: `npx -y @elabs-ai/components-cli search "<what you need>"` and `npx -y @elabs-ai/components-cli docs <Component>`.
2. Look MetricGrid up before writing code: `npx -y @elabs-ai/components-cli docs MetricGrid` prints its real props, variants, what it pairs with and what to avoid.
3. If @elabs-ai/components-charts is not installed yet: `pnpm add @elabs-ai/components-tokens @elabs-ai/components-ui @elabs-ai/components-charts` (or `npm install @elabs-ai/components-tokens @elabs-ai/components-ui @elabs-ai/components-charts`). If this is the first brand-ui package in the project, wire it once: import `@elabs-ai/components-tokens/styles.css` plus the `themes/light.css` and `themes/dark.css` stylesheets in the CSS entry, add one Tailwind `@source` line per installed @elabs-ai package (Tailwind does not scan node_modules, so without it everything renders unstyled), and wrap the app root in `ThemeProvider` from `@elabs-ai/components-tokens`.
4. Use it here: [the screen or file, and what it should show]
5. Rules: use only @elabs-ai/components-* components and the semantic tokens — no raw colours, no raw font sizes, no arbitrary Tailwind values. Look up each component's real props with the docs tool before you use it; never guess a prop.
6. Done means: the typecheck passes, `npx -y @elabs-ai/components-cli audit src --strict` reports nothing, and you have opened the app and looked at every screen you touched in the light and the dark theme.

Avoid

  • More than ~5 tiles in one row — KPIs answer 'how are we doing', not 'everything we measure'.
  • Numbers without tabular-nums — figures jitter across the row.
  • Re-declaring a KPI tile locally — MetricCard is owned by @elabs-ai/components-ui and re-exported here (ADR 0012).

Works with

Contains

Used inside

  • AppShell

Examples

7 live examples

Two Columns

Three Columns

No Delta

Loading

Loading vs ready (#268) — `loading` forwards to every tile, matching each card's box height.

Loading Empty

Loading with no children yet — reserves the grid's final shape with placeholder tiles.

API

MetricGrid

PropTypeDescription
childrenReactNodeOptional so a `loading` grid can render its placeholder shape before any tiles exist.
columns2 | 3 | 4Target columns once the grid's own container is wide enough (container queries, not the viewport — see `colsMap`). Defaults to 4.
revealbooleanStagger the tiles in on mount. Motion-gated. Defaults to false (dashboards opt in).
featurednumberIndex of the tile that spans wider (research 11 §B.5 KPI-2) — pairs with `<MetricCard emphasis="headline">` so the headline KPI out-ranks the band.
featuredSpan2 | 3Columns the featured tile spans at the larger breakpoints. Defaults to 2.
classNamestringLands on the grid element itself (inside the `@container` wrapper), so `gap-*`, margins and test hooks merge as before; a class that must sit on the OUTER box in a parent grid (`col-span-*`) goes on a wrapper of your own.
loadingbooleanLoading vs ready — forwards `loading` to every child tile; when there are no children yet, renders `columns` placeholder `MetricCard`s so the grid reserves its final shape. Default: `false`.

MetricCard

PropTypeDescription
labelrequiredReactNode
valuerequiredReactNode
valueFormatMetricCardValueFormatHow to render a NUMERIC `value`. Default: `"compact"`. Ignored for every other `ReactNode` — a string you already formatted is rendered verbatim.
currencystringISO 4217 code for `valueFormat: "currency"`. Default: `"USD"`.
copyExactValuebooleanOffer the exact figure on click when a numeric `value` was shortened. Default: `true`. Turning it off leaves a compacted number with no way back to its digits, so only do that when the tile is decorative.
descriptionReactNodeSecondary line under the value — sublabel / context.
deltastringSigned change, e.g. "+12.4%". Direction colors it.
deltaDirection"up" | "down" | "neutral"
positiveIsGoodbooleanWhether "up" is good (green) — flip for metrics where down is good.
comparisonsMetricCardComparison[]Several named changes side by side, as a row of chips under the tile body — month over month beside year over year, or actual against target and against last year. Each chip carries an arrow, the sign and a tone, and a bad-news chip also differs in SHAPE (a dashed outline), so the row survives greyscale. Use `delta` for the ONE headline change beside the value and this for the rest; hidden at `size="sm"`. Default: none.
iconReactNode
visualReactNodeOptional inline visual shown under the value/description.
sparklineReactNodeTrend slot rendered directly under the value (RM-072) — pass a `<Sparkline …/>` from `@elabs-ai/components-charts`. Hidden at `size="sm"`.
evidenceReactNodeOptional grounding footer (research 11 §B.5 KPI-3) — connects a cited figure to its source (e.g. an `EvidenceChip` from `@elabs-ai/components-ai`). Rendered subdued (`text-meta text-muted-foreground`) under the tile body.
loadingbooleanLoading vs ready — renders a layout-shaped skeleton (matching the real box height) instead of the value/label/delta text. Default: `false`.
announceLoadingbooleanWhether this tile announces its own `loading` state via a live region. Set to `false` when several tiles are composed inside a container that already announces once for the whole region (e.g. a loading `MetricGrid`) — see loading-states.md §a11y ("one live region per region, not per box"). Default: `true`.

Also accepts: HTMLAttributes<HTMLDivElement>, VariantProps<typeof metricValueVariants>

Theming

The tokens each state resolves to. Change the token and every theme follows.

StateToken
valuetabular-nums