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.

Props

By name or description, across the 27 props below

StatTile 17 props

  • labeltype stringRequired

    What the number is: the tile's name. Untrusted text, rendered as text.

  • valuetype numberRequired

    The number. It counts up as the tile first comes into view, then springs to new values.

  • formatValuetype ChartFormatterdefault Intl.NumberFormat in the page's locale

    Formats the number.

  • unittype string

    A unit, small beside the number ("min"), so a long one never wraps the number.

  • valueTexttype ((value: number) => string)

    What assistive technology hears for the number 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 hours" for "8.2 h"). Called with the value it settles on, never a counting one; a value that isn't a number is read as labels.noValue. Left out, the figure and its unit are read as shown.

  • changetype StatTileChange

    How the number moved.

  • trendtype readonly (number | null)[]

    Values for a Sparkline under the number, oldest first; null for no value (a gap).

  • sizetype "md" | "lg"default "md"

    The number's size.

  • iconstype Partial<StatTileIcons>

    Replaces the change's arrows.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

  • idtype string

    The outermost element's id.

Text

  • labelstype Partial<StatTileLabels>

    Words it says. A LabelsProvider sets them for the whole app.

  • aria-describedbytype string

    The id of what describes the tile.

  • aria-detailstype string

    The id of what gives more about it.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Sparkline 10 props

  • valuestype readonly (number | null)[]Required

    The values, oldest first. A few (12 or so) read best; an app averages longer runs. null, or any value that isn't a finite number, is no value at that place: a gap in the line.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

  • idtype string

    The outermost element's id.

Text

  • aria-labeltype string

    Names the trend for assistive technology when it stands alone (role="img"). Left out (with aria-labelledby), it is decorative, as beside the number it shows the trend of.

  • aria-labelledbytype string

    The id of what names the trend, as aria-label does.

  • aria-describedbytype string

    The id of what describes a named trend.

  • aria-detailstype string

    The id of what gives more about a named trend.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • A change that is good, bad or neutral news, with a trend

    Built

    Configuration · Dashboard

  • Sizes: md and lg (size)

    Built

    Variant · Sizes

  • A unit and a format of your own (unit, formatValue)

    Built

    Configuration · Sizes

  • A short figure read in full (valueText)

    Built

    Configuration · Sizes

  • A figure with no value yet

    Built

    Configuration · Sizes

  • A new period, springing from the figure showing

    Built

    Use case · Trend

  • A Sparkline on its own, named

    Built

    Configuration · Trend

  • Not an M3 component

    Extension

    M3 has no chart components; the tile and its sparkline follow M3’s colour roles, type scale and springs, with the chart palette’s first series colour on the trend’s newest value.

  • A number that counts

    Extension

    The figure counts up once as it first comes into view and springs to each new value, never past it; under reduced motion it changes at once, and the server’s HTML holds the final figure.

Theming & tokens

Set the tokens below on the tile or any ancestor. The trend's line, its end dot and the dot's ring come from the shared chart tokens (--wm-chart-quiet, --wm-chart-color-1 and --wm-chart-surface); on a card of another colour than surface, set --wm-chart-surface to it so the ring matches. Only a tile with a trend brings the charts' palette to the page, through its sparkline. className goes on the root; style each part with classNames: label, figure, value, unit, change, changeIcon, context, separator, tone, trend, where trend goes on the sparkline's root. A Sparkline of your own takes className on its root and classNames for what holds its marks, its line and its end dot: plot, trend, point.

StatTile tokens
VariableDefaultPaints
--wm-stat-tile-gap4pxThe space between the label, the figure, the change and the trend.
--wm-stat-tile-figure-gap4pxThe space between the number and its unit.
--wm-stat-tile-change-gap4pxThe space between the change’s arrow and its words (the amount and what it is compared with, which a space keeps apart).
--wm-stat-tile-label-colorvar(--md-sys-color-on-surface-variant)What the number is, and what its change is compared with (`context`).
--wm-stat-tile-value-colorvar(--md-sys-color-on-surface)The number.
--wm-stat-tile-unit-colorvar(--md-sys-color-on-surface-variant)The unit, small beside the number.
--wm-stat-tile-change-good-colorvar(--md-sys-color-success)A change for the better: its arrow and words.
--wm-stat-tile-change-bad-colorvar(--md-sys-color-error)A change for the worse.
--wm-stat-tile-change-neutral-colorvar(--md-sys-color-on-surface-variant)A change that is neither.
--wm-stat-tile-change-icon-size18pxThe change’s arrow.
Sparkline tokens
VariableDefaultPaints
--wm-sparkline-height36pxThe trend’s height, the end dot’s room included.