Skip to content

Stat tile

Pro

One number and how it moved: what it is, the figure, its change against something, and a small trend under the number. Not an M3 component (@windmorph/react-pro).

import { StatTile, Sparkline } from '@windmorph/react-pro/charts';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Purpose

One number and how it moved, for a dashboard or a summary: what the number is, the figure, its change against something, and a small trend under it. Where a chart with a single bar would make the reader work it out, the tile says it.

M3 has no chart components, so the tile follows M3's colour roles, type scale and springs instead of a spec. For an amount against a limit, such as storage used or seats taken, use a Meter; to show in detail how something changed over time, with axes and a readout, a Line chart; to compare a few figures with each other, Ranked bars.

Behaviour

  • label says what the number is and names the tile, a group. formatValue writes value; by default it is in the nearest LocaleProvider's locale, else the browser's, with up to two decimals, or three significant digits under one ("0.004", never "0"). unit sits smaller beside the number ("min"), so a long unit never wraps the number.
  • valueText is what screen readers hear for the figure and its unit, in place of what's shown, as the core Slider's valueText: the full value where the figure is short ("105,312" for "105K", "8.2 minutes" for "8.2 min"). It is called with the value the figure settles on, never a counting one, and a value that isn't a number reads labels.noValue instead. Left out, the figure and its unit are read as shown.
  • The number counts up from 0 the first time the tile comes into view, then springs from the figure showing to each new value, never past it. Its box keeps the final figure's width as it counts, so nothing beside it moves. A tile on screen as the page loads shows its final number from the server's HTML, with no count.
  • A value that isn't a finite number, such as a figure still loading or a share of nothing, reads labels.noValue ("No value"), never "NaN".
  • change says how the number moved: direction picks the arrow, and value and context are your own words ("12%", "on last week"). tone says whether it is good news: good is in the success colour, bad in error, and neutral, the default, stays quiet. Good or bad news also shows in words after the change, in its colour ("↑ 9% on last week · worse", from labels.good and labels.bad, "better" and "worse" by default), so colour is never the only cue. Direction and tone are separate, since a rise in returns is bad news. icons replaces the arrows.
  • Screen readers hear the change as one sentence, the visible text hidden from them so it is read once: the direction, the amount and the context, then good or bad news in words (labels.good, labels.bad): "Up 12% on last week, better". labels.change(parts) puts the sentence together, so a language can order it its own way, and labels.separator is the dot before the tone on screen.
  • trend takes the number's recent values, oldest first, and draws them as a Sparkline under the number: in the quiet colour, with a dot in the first series colour on the newest. About 12 values read best; average a longer run first.
  • A sparkline is drawn over its values' own range rather than from 0, so its shape reads at a small size; a run that moves less than a tenth of its level keeps that tenth, so a nearly flat figure stays nearly flat. A value that isn't a number (null or NaN) leaves a gap in its place, so time keeps its spacing. Time runs from the start edge, so right to left the newest value is on the left.
  • Inside a tile the sparkline is decorative. On its own, beside the words it stands for, name it with aria-label or aria-labelledby and it becomes an image for screen readers. New values spring into their shape while it is on screen, and land at once off screen.
  • size is md (the default, for a row of tiles) or lg, for the one figure a page is about. The tile draws no container: put it on a card for one.

When not to use

For a value against a limit, use a Meter; for how something changed over time in detail, a Line chart.

See also

  • Meter: A value on a known scale, such as storage used or a quota, with a warning past a threshold said in words, never by colour alone. Not an M3 component (@windmorph/react-pro).
  • Line chart: Lines over time: one subject with a wash under it and others to compare with, read by pointer, finger and keyboard. Not an M3 component (@windmorph/react-pro).
  • Chart frame: The card a chart sits in: its title names the chart, a switch shows the same numbers as a table, and it has empty, loading, pending and error states. Not an M3 component (@windmorph/react-pro).