Skip to main content

Stat

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

Displays a large metric with optional trend indicator and help text.

Import​

import { Stat, statTileHeight } from "~lib/data-display/stat";

Props​

NameTypeRequiredDefaultDescription
labelstringYesN/AMetric label
valuestring | numberYesN/AMain display value
change{ value: number; trend: "up" | "down" | "neutral" }NoN/ATrend indicator
helpTextstringNoN/AExplanatory text below
leadingReactNodeNoN/ADrawn before the tile, centered on the value's line
size"sm" | "md" | "lg"No"md"Text size of the tile
align"left" | "center" | "right"NoInheritedText alignment
truncatebooleanNofalseKeep each line to one, ending in "…"

Examples​

Simple​

Open Simple in Storybook

With Up Trend​

Open With Up Trend in Storybook

With Down Trend​

Open With Down Trend in Storybook

With Help Text​

Open With Help Text in Storybook

Sizes​

Open Small in Storybook
Open Large in Storybook

Centered​

Open Centered in Storybook

Truncated​

With truncate, a label or value too long for the tile ends in "…" rather than wrapping, so tiles in a row stay the same height.

Open Truncated in Storybook

With Leading​

A node such as a coin's Avatar crest sits before the tile's lines, centered on the value. The node and the lines are aligned as one block, so a centered tile centers the pair.

Open With Leading in Storybook

Height​

statTileHeight(size, { change, helpText }) returns how tall a tile with every line kept to one is, in pixels, on the frame's own type scale, so a plan can budget a row of tiles. See StatGroup.

See Also​