Skip to content

Statistic

Displays a single named figure. Given a previous value, it works out the change and shows it alongside.

tsx
import { Statistic } from 'neba';

<Statistic label="Monthly recurring revenue" value={48210} prefix="$" previousValue={42800} />;

Props

PropTypeDefaultDescription
labelReactNodeThe name of the number. Card calls the same slot `title`, but what this names is a *value*: which is the thing the library already spells `label` on every field it has
value * ReactNodeThe figure. A number is formatted; anything else is rendered exactly as given: a string for the values that are not numbers, or a node such as an AnimateCounter
formatIntl.NumberFormatOptionsHow to write a numeric value: the same prop the progress indicators take. Without it a number is grouped by the reader’s own locale and otherwise left alone
localestringthe reader'sWhich language the figure is written in: the same prop every chart takes. A Statistic sits next to the charts in a dashboard, so a locale set on one of them has to be settable on all
prefixReactNodeSet before the figure: a currency sign
unitReactNodeSet after the figure: %, MB, 명. A second slot rather than one adornment with a side, because a currency symbol leads its number and a unit follows it
iconReactNodeA glyph before the label
previousValuenumberThe figure this one is compared against: last month’s, the target. Passing it is what makes the delta appear
delta'percent' | 'absolute' | 'both' | 'none''percent'How the difference is written. Percentage by default, because a report is nearly always asking how much a figure has moved rather than by how many. With a previousValue of 0 there is nothing to divide by, so it falls back to the difference itself
betterWhen'up' | 'down''up'Which direction counts as good, and so which way the delta is coloured. `up` for revenue, `down` for churn and error rate and page weight. Not decoration: green-for-larger on a bounce rate says the opposite of what the report means, and says it to exactly the reader who is skimming
captionReactNodeA line under the figure: "vs. last month"
alignshared'start' | 'center' | 'end''start'Where the block sits in the card. `center` for a row of tiles that read as one band
variantshared'solid' | 'outline' | 'text''outline'Weight of the surface: Box’s own, because a Statistic is a Box with an arrangement on it
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'The figure’s type scale, and the sheet’s padding and radius
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'Semantic colour role. Arbitrary colour values are not accepted
densityshared'default' | 'compact''default'Padding only: never the height, never the type scale
elevationshared0 | 1 | 2 | 30Drop shadow depth. 0 means no shadow at all
childrenReactNodeAnything below the caption: a sparkline, a ProgressLinear against a target
transitionsharedNebaTransitionAn entrance animation, run once on mount (transition="zoom"). Wrap it in an Animate* component for a trigger or a replay

Every native <div> attribute passes through, along with every Box prop. The delta renders as a Chip.

Examples

previousValue · delta · betterWhen

Pass previousValue and the change against the current value is calculated and shown. delta decides whether that change is written as a proportion, as the difference, or as both.

betterWhen says which direction is good news. Revenue is better up, churn is better down: without it there is no way to colour the delta.

The figure and the delta change shape as well as colour: a rising arrow, a falling one, a short dash when nothing moved. Direction is never carried by colour alone.

icon · unit · caption · align

icon sits before the label and unit after the figure. children is the slot under the figure, for a ProgressLinear against a target or a Sparkline. align="center" is for a row of tiles laid out as one band.

prefix and unit are separate props because they are typographically different: a currency symbol leads its number, a unit follows it.

format

format is passed straight through as Intl.NumberFormat options. Without it a number is only digit-grouped for the reader's locale. A string value is printed unformatted, so figures that are not numbers still work.

tsx
<Statistic label="Revenue" value={48210} format={{ style: 'currency', currency: 'USD' }} />
<Statistic label="Conversion" value={0.0423} format={{ style: 'percent', maximumFractionDigits: 1 }} />
<Statistic label="Median build" value="3m 12s" />

A previousValue of 0 makes the proportion undefined, so the absolute difference is shown regardless of the delta setting.

locale

locale decides which language the figure and its delta are written in. It is the same prop every chart takes, so one dashboard can set the same value on a Statistic and on the LineChart beside it. Without it the reader's own locale is used.

tsx
<Statistic label="Revenue" value={1234.5} locale="de-DE" format={{ minimumFractionDigits: 1 }} />

Released under the MIT License