Data

Stat Counter

A dashboard number that rolls to its new value, with a change badge whose arrow flows up or down.

Preview

Installation

Terminal
npx @usefluid/cli add stat-counter

Usage

StatCounter.tsx
import { StatCounter } from "./StatCounter";

<StatCounter label="Revenue today" value={16902} previous={13380} format={{ style: "currency", currency: "USD", maximumFractionDigits: 0 }} />

API reference

PropTypeDefaultDescription
labelstring—What the number is.
valuenumber—The number. Change it and the digits roll to it.
previousnumber—The value to compare with. The badge shows the change in percent. Leave it out to hide the badge.
formatIntl.NumberFormatOptions—Currency, percent, units and decimals, as in Intl.NumberFormat.
localestringthe browser'sLocale for the number.
upIsGoodbooleantrueSet to false when a rise is bad news, such as costs or errors: the badge turns red when the number goes up.

Keyboard and screen readers

The rolling digits are hidden from screen readers. They read the label, the final value, and "up" or "down" with the percent. With reduced motion the number changes at once.

Notes

Every colour comes from the --fluid-* variables, except green and red for the change, and the piece is yours to change.

How it is made

One spring carries the number, critically damped, so the digits roll and settle without overshooting the real value. The arrow in the badge is a shape of the engine: up and down are two drawings, and it flows between them. Screen readers get the label, the final value and the change, never the rolling digits.

For your agent

For your agent

Add Stat Counter to my project with the Fluid library. Use StatCounter for the key numbers of my dashboard, with the real values and the previous period to compare. Read my project first. Use my logo, my colours and my font through the --fluid-* variables. Keep 44px touch targets, visible focus and reduced motion. If I have no SVG logo, ask before making one up.