Skip to content
Thrum

Metric table

A table for a set of metrics side by side: each column draws its cells by kind, as a number with its unit, a signed change, a sparkline or a bar to a scale the column shares. Pick it for a comparison by region, plan or product. For paging, selection and column menus over plain values, use the data table.

Install

npx shadcn@latest add @thrum-pro/metric-table

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Automatically installs icons arrow-down, arrow-up and arrow-up-down from the icon set.

Data shape

Type
type MetricColumn = {
  key: string;
  header: string;
  kind: "text" | "number" | "delta" | "sparkline" | "bar";
  format?: Intl.NumberFormatOptions;
  sortable?: boolean;
  invert?: boolean;   // delta: a fall is good news
  max?: number;       // bar: the value of a full bar
};
type MetricRow = {
  id: string;
  href?: string;
  values: Record<string, string | number | (number | null)[] | null>;
};
Sample
[
  { id: "na", href: "/regions/na", values: { region: "North America", revenue: 482100, change: 0.124, trend: [41, 44, 43, 47], seats: 1840 } },
  { id: "eu", values: { region: "Western Europe", revenue: 391800, change: -0.031, trend: [38, 37, null, 36], seats: null } },
]

Props

PropTypeDefaultDescription
columnsreadonly MetricColumn[]RequiredThe columns, in order. The first one heads each row, links it when the row has an href, and stays in view while the table scrolls sideways.
rowsreadonly MetricRow[]RequiredThe rows in their unsorted order. Each has an id, an optional href and one value per column key.
captionstringRequiredWhat the table holds. Shown above it, and the name of the table and of its scrolling frame.
sortMetricSort | null–The sort, when the parent holds it: a column key and asc or desc. null is the given order. Use it with onSortChange.
defaultSortMetricSort | nullDefault nullThe sort at first, when the table holds it itself.
onSortChange(sort: MetricSort | null) => void–Called with the new sort when a heading is pressed.
density"compact" | "normal"Default "normal"Row padding: compact rows start at 32 pixels, normal rows at 40. A sparkline or a badge can make a row taller.
stickyFirstColumnbooleanDefault trueKeep the first column in view while the table scrolls sideways, with a hairline at its edge.
localestringDefault "en-US"Locale for every number and for sorting text.
emptyLabelstringDefault "No data"Text shown in the body when there are no rows.
soundbooleanDefault truePlay a soft click when the sort changes, if the visitor has sound on.
classNamestring–Classes for the frame: its width, a max-h to scroll the body.

Motion and sound

Motion

  • First draw: numbers, badges and bars appear as they are. Each sparkline is revealed left to right in 700 ms.
  • New data: numbers roll from the values on screen and bars grow or shrink to the new value, both in about 400 ms with no overshoot. Sparklines morph.
  • Sorting moves rows at once; nothing slides.
  • Reduced motion: everything appears complete and changes instantly.

Sound

  • Pressing a sortable heading plays the select sound. Data changes are silent.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • It is a native table named by its caption. The first cell of each row is a row heading, so every cell is read with its row and its column.
  • Sortable headings are buttons inside the column headings, and the sorted column carries aria-sort.
  • Each sparkline is an image whose name states the row, the column, the first and last value and the low and high.
  • A change is read with a word for its direction, Up, Down or No change, before the signed value. Colour only says whether it is good news.
  • A bar is decoration: its number is printed beside it. A missing value prints a dash and is read as No data.
  • The frame is a focusable region, so a keyboard reader can scroll a wide table. It is a panel surface: under frosted glass it turns translucent and its text keeps 4.5:1 contrast.
KeysAction
TabMove to the table frame, then to each sortable heading and each row link.
Enter / SpaceOn a heading: sort by it. Numbers start with the largest, text with A; a second press reverses, a third returns to the given order.
Arrow keysOn the frame: scroll it when the columns do not fit.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/metric-table.tsx
Packages
motion
Brings along
TableSparklineTrend badgeAnimated numberLinkChart foundationsMotion tokensSound engine
Icons
arrow-downarrow-uparrow-up-down

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor