import { MetricGrid } from "@elabs-ai/components-charts";npm install @elabs-ai/components-tokens @elabs-ai/components-ui @elabs-ai/components-chartsPrompt 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
Examples
Two Columns
Three Columns
Featured
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
| Prop | Type | Description |
|---|---|---|
children | ReactNode | Optional so a `loading` grid can render its placeholder shape before any tiles exist. |
columns | 2 | 3 | 4 | Target columns once the grid's own container is wide enough (container queries, not the viewport — see `colsMap`). Defaults to 4. |
reveal | boolean | Stagger the tiles in on mount. Motion-gated. Defaults to false (dashboards opt in). |
featured | number | Index 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. |
featuredSpan | 2 | 3 | Columns the featured tile spans at the larger breakpoints. Defaults to 2. |
className | string | Lands 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. |
loading | boolean | Loading 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
| Prop | Type | Description |
|---|---|---|
labelrequired | ReactNode | |
valuerequired | ReactNode | |
valueFormat | MetricCardValueFormat | How to render a NUMERIC `value`. Default: `"compact"`. Ignored for every other `ReactNode` — a string you already formatted is rendered verbatim. |
currency | string | ISO 4217 code for `valueFormat: "currency"`. Default: `"USD"`. |
copyExactValue | boolean | Offer 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. |
description | ReactNode | Secondary line under the value — sublabel / context. |
delta | string | Signed change, e.g. "+12.4%". Direction colors it. |
deltaDirection | "up" | "down" | "neutral" | |
positiveIsGood | boolean | Whether "up" is good (green) — flip for metrics where down is good. |
comparisons | MetricCardComparison[] | 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. |
icon | ReactNode | |
visual | ReactNode | Optional inline visual shown under the value/description. |
sparkline | ReactNode | Trend slot rendered directly under the value (RM-072) — pass a `<Sparkline …/>` from `@elabs-ai/components-charts`. Hidden at `size="sm"`. |
evidence | ReactNode | Optional 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. |
loading | boolean | Loading vs ready — renders a layout-shaped skeleton (matching the real box height) instead of the value/label/delta text. Default: `false`. |
announceLoading | boolean | Whether 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`. |
Theming
The tokens each state resolves to. Change the token and every theme follows.
| State | Token |
|---|---|
| value | tabular-nums |