Stat
Display a key metric with a label, formatted value, trend and countdown
Source
Package
Usage
Stat displays a single metric: a label, a formatted value and an optional trend indicator:
Value formatting
Numeric values are formatted with NumberFormatter and support the same formatting props.
Numeric strings are formatted the same way, other strings are rendered as is.
Use prefix and suffix to add units or currency:
To fully control value rendering, pass a formatter function.
Formatting props and animate are ignored when formatter is set:
Trend indicator
Set diff prop to display a trend delta below the value. Positive values are green,
negative values are red, zero is dimmed. The delta is formatted as a signed percentage:
Use diffFormatter to change the delta text and withDiffIcon={false} to hide the arrow:
Icon
Use icon prop to display an icon next to the value:
Loading state
Set loading prop to display a Skeleton instead of the value and hide the trend indicator:
Animated value
Set animate prop to animate numeric value changes with RollingNumber:
Countdown
Stat.Countdown displays a live countdown to a target time. value is a Date
or a timestamp in milliseconds, keep it stable between renders: a new value restarts the countdown.
format prop accepts dayjs-style tokens:
- Units absent from the format roll into the leading token:
mm:ssdisplays 62 minutes as62:00 Sdisplays tenths of a second,SShundredths andSSSmilliseconds- Literal characters are escaped with square brackets, for example
D[d] HH:mm:ss
onFinish is called once when the target time is reached, onTick is called on every
tick with the remaining time in milliseconds:
Color
Set color prop to change the value color:
Compound components
For full control over the layout, use compound components instead of the shorthand props.
Stat.Icon is always placed next to the value, other components are rendered in the order they are declared:
Example: dashboard stat row
Compose several Stat components in a SimpleGrid to build a stat row:
Accessibility
Stat.Countdownvalue is not announced on every tick. To announce milestones, render your own live region and update it fromonTick.- When
loadingis set, the root element hasaria-busy="true". Stat.Diffrenders a visually hidden direction text after the delta, screen readers announce+12.4% increase. UsediffLabelsprop to translate these texts:
Styles API
Stat supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover or focus a selector to highlight its elements