Skip to content
Nana UI

Data Display & Media

Stat Card

A single headline figure for a dashboard: what it measures, the number, and how it moved. Lay several out with a CSS grid, and set tone to colour the icon and the change.

View .md Download

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add stat-card

All three format the change the same way — the rule lives in headless/stats-cards.

import "@nana-tec/ui-components/stat-card";
<nana-stat-card label="Total revenue" value="KSh 45,231.89" change="20.1">
<nana-icon slot="icon" name="payments"></nana-icon>
</nana-stat-card>

value is shown as given, so format it yourself — currency, separators, a leading +. change is a signed percentage and is formatted for you: 20.1 reads as +20.1%, -4 as −4%.

The line under the figure follows one rule:

You setThe line reads
change+20.1% from last month
change and comparison+20.1% from last week
change and hint+20.1% since yesterday
hint only+201 since last hour
neithernothing — the line is left out

tone colours the icon and the change. It does not pick itself from the sign of the change: a rise in cancellations is bad news, so you decide.

Each card is a description list: the label is the term, and the figure and its detail line are its descriptions, so a screen reader announces them together. The icon is decorative and hidden from assistive technology. Tone is never the only signal — the change keeps its sign.

Properties

PropertyAttributeTypeDefaultDescription
changechangenumber | undefined—Signed percentage change over the comparison window, e.g. 12.5 or -3
comparisoncomparisonstring'from last month'What change is measured against
hinthintstring | undefined—Replaces the comparison text, e.g. +201 since last hour
labellabelstring''What the figure measures
tonetoneStatCardTone'neutral'Colours the icon and the change
valuevaluestring''The headline figure, already formatted

Slots

SlotDescription
iconA small glyph shown beside the label, tinted by tone

CSS parts

PartDescription
::part(base)The card
::part(label)The row holding the label and icon
::part(icon)The icon wrapper
::part(value)The headline figure
::part(detail)The line under the figure
::part(change)The formatted change inside the detail line

CSS custom properties

PropertyDescription
--nana-stat-card-bgCard background
--nana-stat-card-borderCard border colour
--nana-stat-card-radiusCard corner radius
--nana-stat-card-paddingCard padding
Explore Stat Card interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook