Metric Table
The roic.ai row: metric name, values across time, sparkline, delta. Click a row to promote it into whatever chart the caller renders above.
Preview
Rendered from the story the storybook (a11y) CI gate runs axe against — the preview can't show something that hasn't been verified.
Install
Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.
npx shadcn@latest add https://ds.interlace.tools/r/metric-table.jsonnpx shadcn@latest add @interlace/metric-tableBehavior
What this component does — the keyboard path, the measured colour, the text equivalent and the states it can be in. Every figure below is read out of the test or the source that enforces it by scripts/build-behavior-map.mjs, so nothing here can outlive the gate that keeps it true.
2 steps, 1 key press — replayed on every PR by the play function of Selectable. Axe cannot press a key, so this — not the a11y scan — is what proves the component is operable without a mouse.
- 1a row selects from the keyboardEnter
- 2the promoted metric is the one now charted
9 states, one closed union — not a boolean per condition. Partial is a state, not an absence: a spinner that hides progress, or a missing prior rendered as 0, is the failure this model exists to make impossible.
| State | Reads as | Role | Encoding |
|---|---|---|---|
| loading | loading | Stands instead of the body | muted |
| error | ! error | Stands instead of the body | danger |
| not-applicable | n/a | Stands instead of the body | hatchedrecede |
| not-counted | not counted | Stands instead of the body | hatchedmuted |
| empty | — none | Stands instead of the body | muted |
| partial | ≥ partial | Stands next to the body and changes how to read it | dashedmuted |
| truncated | ⋯ truncated | Stands next to the body and changes how to read it | dashedmuted |
| first-measurement | · first measurement | Stands next to the body and changes how to read it | dashedaccent |
| idle | — | The absence of absence | muted |
Hatched and dashed are the two absences drawn apart on purpose: not-counted means no measurement was taken and is never a zero; truncated means the total is unknown and must never be used as a denominator. Each state also carries a spoken announcement — transitions, never ticks.
Measured contrast
packages/ui/__tests__/theme-contract-lock.test.ts ↗Every semantic colour pair this component's own source uses, measured against the shipped hexes in all 4 theme × scheme combinations. The tightest is muted-foreground on muted at 7.34:1 (harbor · light), against a floor of 4.5:1.
| Pair | interlacelight | interlacedark | harborlight | harbordark | Floor |
|---|---|---|---|---|---|
| muted-foreground on mutedcopy on a muted surface | 8.81:1 | 10.48:1 | 7.34:1 | 8.64:1 | 4.5:1SC 1.4.3 |
| destructive on backgrounddestructive tint on the page surface | 8.31:1 | 10.43:1 | 7.60:1 | 10.03:1 | 3.0:1SC 1.4.11 |
| muted-foreground on backgroundsecondary copy | 9.41:1 | 11.32:1 | 7.82:1 | 9.52:1 | 4.5:1SC 1.4.3 |
| destructive on carddestructive tint inside a card | 8.31:1 | 9.66:1 | 8.02:1 | 9.09:1 | 3.0:1SC 1.4.11 |
| muted-foreground on cardsecondary copy in a card | 9.41:1 | 10.48:1 | 8.25:1 | 8.64:1 | 4.5:1SC 1.4.3 |
| accent-foreground on accenthover/highlight face | 8.98:1 | 10.46:1 | 8.95:1 | 9.65:1 | 4.5:1SC 1.4.3 |
Text pairs are held to 4.5:1 (WCAG 2.2 SC 1.4.3); borders, rings and chart axes to 3:1 (SC 1.4.11 non-text). Bold is the worst cell in the row — the one a brand fork has to keep an eye on.
Text equivalent
packages/ui/src/charts/metric-table.tsx ↗A chart's alt text is not a sentence about the chart — the equivalent of the data is the data. This is what a screen reader gets, read out of the source the install writes into your tree.
Ships sr-only copy for what the visual carries by position, colour or icon alone — a label, not a full data equivalent.
Runtime contract
packages/ui/vitest.config.ts ↗Where it renders, how narrow it survives, and whether its lines are inside the coverage gate — three answers a consumer needs before the paste, not after the bug.
- Render boundary
'use client'Hydrates. It brings JavaScript to any route that imports it — put the boundary here, not at the page.
- Minimum viewport
MIN_VIEWPORT = 320Declared, not assumed. Below 320 CSS px the preflight contract draws a dev-mode outline — how to switch it on.
- Coverage gate
100% × 4Inside the v8 gate: lines 100, statements 100, functions 100, branches 100. A threshold under 100 only records how much you stopped caring, so there isn't one.
History
This component is at v1.2.0, first shipped in @interlace/ui 1.0.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.
@interlace/ui 1.1.01 entry
- Addedminor
New
Distributionchart — a quantity spread over a fixed set of named bins, read against a reference distribution. It is a new component rather than an extension ofTimeSeriesbecause three of that component's properties are chronological and cannot be parameterised out: its axis keys are sorted (['Thu','Fri','Sat']sorts into a week that does not exist), a line asserts the metric passed through every value between two samples when between two hourly aggregates there is nothing to pass through, anddelta()first-to-last is arithmetic performed on a circle. An unmeasured bin **hatches**. Everywhere else anullcan simply be dropped, but for bars a height of zero and a bar never drawn are the same picture — this isnull ≠ zeroat its hardest case.bin.noteprints a second axis reading under the first, replacing the timezone toggle a caller would otherwise build; a toggle hides half the truth and is missing from every screenshot. Also:errorstates on every chart that fetches —TimeSeries,Sparkline,MetricTable,NetworkGraph,Distribution— resolved throughresolveDataStateso the precedence is the array indata-state-modelrather than five hand-rolled ladders. In a dashboard "the fetch failed" and "there is no data" are different statements.DeltaandSeriesTableget none: neither has a fetch lifecycle.StatItemgainstone, carried by three signals rather than a hue alone — the rail, the value colour, and ansr-onlyjudgement.
@interlace/ui 1.0.01 entry
- Addedminor
The visualization layer ships: a token-driven chart set built on the
VISUALIZATION_PHILOSOPHYrow-first doctrine —MetricTableas the centrepiece,TimeSeriesas the thing a row is promoted into, plus a network graph, sparklines and deltas. Every chart carries the DS-wideloadingskeleton opt-in.
Import
25 named exports — pull the parts you need.
import { ANNOTATION_KINDS, AnnotationKind, Direction, MIN_VIEWPORT, MetricTable, NumericPoint, areaPath, axisSlots, bandScales, compact, day, delta, describeDistribution, describeSeries, keepAtNarrow, linePath, nearestIndex, nearestSlot, numeric, peakBin, plotScales, seriesScales, slotAt, stepPath, ticks } from '@/components/ui/charts/metric-table';API reference
Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.
MetricTableProps
Also accepts every <div> attribute.
| Prop | Type | Description |
|---|---|---|
| rows* | readonly MetricRow[] | — |
| caption* | string | — |
| selected | string | null | — |
| onSelect | (key: string) => void | — |
| maxColumns | number | How many date columns to show. The rest of the history stays in the sparkline and in the `sr-only` data table, so nothing is lost. Defaults to 6, not 8. With 8 the date columns consumed the whole width at a typical content measure and pushed **trend and change off the right edge** — the two columns the reader actually came for, scrollable but invisible. Individual dates are the least valuable thing in the row; they are what should give up space first. |
| loading | boolean | Render a `<Skeleton variant="metric-table" />` placeholder. |
| error | unknown | The fetch failed. A table of metrics that failed to load must not render as a table with no rows: an empty `<tbody>` under a real `<caption>` reads as "we looked, and you track nothing" — a claim about the reader rather than about the request. Ranked directly under `loading`, per `DATA_STATES`. |
| announce | AnnouncementOptions | Context for the absence sentences — noun, coverage, reason. |
Skeleton
Pass loading and the component renders a shape-matched <Skeleton /> in its own place — same box, so nothing reflows when the data lands. Below is the same story with loading={true}.
<ANNOTATION_KINDS loading={isPending} />Accessibility
Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.
What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.
- Focus + keyboard behaviour
- Native element semantics — no interaction layer to get wrong.
- Focus ring (WCAG 2.2 SC 2.4.13)
- Inherited from the preflight focus contract shipped in @interlace/theme.
- Reduced motion
- No animation to gate.
- ARIA in the source
role="alert"role="img"role="row"aria-selected
Examples
11 more states from the same story file.
R-rule compliance
Every primitive in @interlace/ui models to the portable 26-rule floor enforced by the componentApi ESLint preset. The cells below pin exactly where each rule applies in this file.
| Rule | Concept | Where |
|---|---|---|
| R6 | data-slot on every part | `data-slot="metric-table" / "-row"` |
| R7 | className merged + ...rest | `cn(...)` + `{...props}` |
| R8 | No `isXxx` | `selected`, `polarity` |
| R11 | One variable per part | the row owns selection; the table owns the columns |
| R14 | Declares min viewport | `data-min-viewport={String(MIN_VIEWPORT)}` |
| R18 | Tailwind only | zero inline `style` |
| R19 | Tokens only | `border-border`, `bg-accent`, `text-muted-foreground` |
| R20 | AA contrast | selected row uses `bg-accent`/`text-accent-foreground` (9.31:1 light, 9.85:1 dark) |
| R23 | Absence is a vocabulary | `loading` / `error` resolve through `resolveDataState` |
| R25 | Client component | row key/click handlers |
| R26 | A11y | native table semantics + `aria-selected` + focus ring |
Minimum viewport
This primitive declares MIN_VIEWPORT = 320 CSS px (DESIGN_PRINCIPLES #14). When mounted in a container narrower than this, the preflight contract draws a dev-mode outline so the regression is visible during local development.
<body data-interlace-dev>...</body>
Add the data-interlace-dev attribute to the body in development builds only — preflight then outlines any primitive whose container is below its declared data-min-viewport.
Dependencies
- Base UI primitive
- Native / no Base UI dependency
- Lucide icons
- none
- NPM dependencies
- none
Source
The full implementation — components/ui/charts/metric-table.tsx once installed.
'use client';
import * as React from 'react';
// @interlace/metric-table v1.2.0 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/metric-table
// What changed since: https://ds.interlace.tools/c/metric-table#history
// Generated banner — keep it, the upgrade diff reads this version.
/**
* @interlace/ui — MetricTable
*
* The roic.ai row: metric name, values across time, sparkline, delta. Click a
* row to promote it into whatever chart the caller renders above.
*
* ## Why this is the centrepiece and not the chart
*
* roic.ai did not build 186 visualisations. They built ONE row and repeated it.
* Density is the product — the eye scans a column of rows and reads a decade,
* which no amount of chart-per-metric ever achieves. Anything that looks like a
…280 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.