Skip to content
buttery

v1.0.0

Source on GitHub

Version 1.0.0

MetricCard

One metric on a card: its title, value and change against the previous period, a small chart of both periods, and when it was updated.

import { MetricCard } from "@butteryui/react";

Demo

Sales

$23,405.00

+9%

vs previous period

+9% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales
delta0.09

When to use it

Use it for

  • An overview page's headline numbers: sales, new subscribers, refund rate
  • A number whose trend matters as much as its value

Not for

  • A number with no history: use StatStrip or plain Text
  • Many numbers in rows: use DataTable, with a Sparkline per row

Examples

Headline metric

The number a page leads with at size lg on the tint, beside a metric with an outline.

Bags shipped

1,284

+8.2%

vs previous period

+8.2% vs previous period
Bags shipped
DateThis weekLast week
Oct 8160150
Oct 9172158
Oct 10168162
Oct 11190171
Oct 12201188
Oct 13214193
Oct 14179165

Updated 2 min ago

Late shipments

6

-25%

vs previous period

-25% vs previous period
Late shipments
DateThis weekLast week
Oct 812
Oct 901
Oct 1021
Oct 1112
Oct 1201
Oct 1310
Oct 1411

Updated 2 min ago

Metric by period

A card whose value, change and chart come from state, picked here by the period above it.

Sales

$12,405.00

+12.4%

vs the week before

+12.4% vs the week before
Sales
DateThis periodThe week before
Mon1,4201,350
Tue1,5601,410
Wed1,4901,380
Thu1,7101,550
Fri1,8801,700
Sat2,2401,960
Sun2,1051,890

Updated 4 min ago

Metric that loads

A metric whose numbers arrive after a moment: its skeleton holds every part in place until then.

Bags roasted

Details for Bags roasted

Overview metrics

An overview's headline numbers for the week, side by side from the md breakpoint, refreshed together.

This week

Sales

$12,405.00

+12.4%

vs previous period

+12.4% vs previous period
Sales
DateThis weekLast week
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

Refund rate

0.9%

-18%

vs previous period

-18% vs previous period
Refund rate
DateThis weekLast week
Oct 81.1%1.2%
Oct 91%1.1%
Oct 100.9%1.2%
Oct 111%1%
Oct 120.8%1.1%
Oct 130.9%1%
Oct 140.9%1.1%

Updated 4 min ago

Details for Refund rate

Sales metric

One metric: its title and what it means, the value and its change, both weeks charted, and a link to its details.

Sales

$12,405.00

+12.4%

vs previous period

+12.4% vs previous period
Sales
DateThis weekLast week
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

Variants and states

Overview metrics

Point at a chart to compare the two periods; a refund rate that falls is good news.

Sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

New subscribers

96

+23.1%

vs previous period

+23.1% vs previous period
New subscribers
DateOct 1–14Sep 17–30
Oct 154
Oct 265
Oct 365
Oct 476
Oct 555
Oct 676
Oct 786
Oct 875
Oct 996
Oct 1086
Oct 11107
Oct 1297
Oct 13118
Oct 14128

Refund rate

0.9%

-18%

vs previous period

-18% vs previous period
Refund rate
DateOct 1–14Sep 17–30
Oct 11.2%1.3%
Oct 21.1%1.2%
Oct 31%1.2%
Oct 41%1.1%
Oct 50.9%1.1%
Oct 61%1.2%
Oct 70.9%1%
Oct 80.8%1.1%
Oct 90.9%1%
Oct 100.8%1.1%
Oct 110.9%1%
Oct 120.8%1%
Oct 130.8%1.1%
Oct 140.9%1%

Updated 4 min ago

Details for Refund rate

Loading

Each part is a skeleton in its own place, and the chart shows its pill after 300ms.

Sales

Details for Sales

Variants

Beside elevated above: outline, a 1px edge drawn inside; soft, the bg-control fill; tinted, bg-tint from the palettes.

Sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

New subscribers

96

+23.1%

vs previous period

+23.1% vs previous period
New subscribers
DateOct 1–14Sep 17–30
Oct 154
Oct 265
Oct 365
Oct 476
Oct 555
Oct 676
Oct 786
Oct 875
Oct 996
Oct 1086
Oct 11107
Oct 1297
Oct 13118
Oct 14128

Wholesale sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Wholesale sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Plain

No surface or padding, for metrics in a row on a page or a panel that's already a surface.

Sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

New cafés

96

+23.1%

vs previous period

+23.1% vs previous period
New cafés
DateOct 1–14Sep 17–30
Oct 154
Oct 265
Oct 365
Oct 476
Oct 555
Oct 676
Oct 786
Oct 875
Oct 996
Oct 1086
Oct 11107
Oct 1297
Oct 13118
Oct 14128

Updated 4 min ago

Details for New cafés

Sizes

md sets the value in title-lg; lg sets it at 32px for the one number a page leads with.

Sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

Sales

$23,405.00

+9.4%

vs previous period

+9.4% vs previous period
Sales
DateOct 1–14Sep 17–30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Updated 4 min ago

Details for Sales

Props

MetricCard

PropTypeDefaultDescription
title

required

stringWhat it measures, such as "Sales". It names the card and its chart.
titleAs"h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p""h3"The title's element. Defaults to "h3", under an AppPage.Section's h2.
infostringWhat the metric means, behind an InfoButton after the title: a tooltip on hover and focus, a popover on a press or a tap.
valuestringThe value, written out, such as "$12,480.00". Leave it out while loading.
deltanumberThe change against the previous period as a fraction: 0.124 for +12.4%.
deltaLabelstring"vs previous period"What the change is measured against. Defaults to "vs previous period".
comparedbooleanWhether the card compares with an earlier period, so its change line keeps its place while loading and shows "—" when there's no change to work out. Defaults to whether series has a comparison series.
lowerIsBetterbooleanfalseShows a fall as good news (success) and a rise as bad. Defaults to false.
labelsreadonly string[]The chart's labels, such as the period's days. With series, the card shows a small LineChart.
seriesreadonly ChartSeries[]The chart's series: the period, and the previous period with comparison: true.
formatValue((value: number) => string)Writes a value in the chart's tooltip. Defaults to the number.
formatTick((value: number) => string)Writes a gridline's value in the chart. Defaults to a short form, such as 1.2K.
updatedstringWhen the numbers were last updated, such as "Updated 4 min ago".
hrefstringThe metric's details page: the footer's link and the expand button go there.
detailsLabelstring"Details"What the footer's link says. Defaults to "Details".
onNavigate((href: string, event: MouseEvent<HTMLAnchorElement>) => void)Runs as either link is followed, where a router can take over.
loadingbooleanShows the card's skeleton: the same parts in the same places, and the chart's loading pill.
variant"elevated" | "outline" | "soft" | "plain" | "tinted""elevated"How it draws its surface: "elevated" (the default), the surface with the card shadow; "outline", a 1px edge on the surface; "soft", the bg-control fill; "plain", no surface or padding, for metrics laid out on a page or a panel of their own; or "tinted", bg-tint, a soft fill from the palettes its words and chart keep their contrast on.
size"md" | "lg""md""md" (the default), the value in title-lg, or "lg", a 32px value for a headline metric.

It also takes Omit<ComponentPropsWithRef<"div">, "title">.

ChartSeries

One series of values over a chart's labels.

FieldTypeDefaultDescription
key

required

stringIdentifies the series among the chart's others, and marks name it.
label

required

stringIts name in the tooltip and the screen-reader table, such as "This week".
values

required

readonly (number | null)[]One value per label, in order; null where there isn't one, which leaves a gap. A value that isn't a finite number, such as NaN, is left out the same way.
colorChartColorchart-1Its color. Defaults to chart-1, chart-2 and on in order, or chart-muted for the comparison.
comparisonbooleanMarks the series the others are measured against, such as the previous period: it's drawn in chart-muted under the others, and the tooltip shows the first series' change from it.

Accessibility

A group named by its title, which is an h3 by default. The info button is named by the explanation its tooltip shows. The chart is a slider over its points, described by the change. The footer's link is named Details for and the title; the expand button repeats it for the pointer only, so it's hidden from screen readers and Tab. While loading the card is marked busy, its skeletons are hidden and its chart's pill isn't read out, so a page of loading cards isn't announced once per card.

KeysWhat they do
Enter or SpaceOpens what the metric means from the info button, in a popover that Tab or a press elsewhere also closes
Left and Right arrowsStep through the chart's points, announcing each one's label, values and change
Home or EndJumps to the chart's first or last point
EscapeCloses the info popover, or hides the chart's tooltip
EnterFollows the Details link

Motion

It changes shape as one surface, on `spring.smooth`, or `spring.morph` for a big change, rather than closing and reopening.

With reduced motion: Its skeletons don't shimmer, and they crossfade into the numbers in 100ms.

Layout

It takes its container's width on a card padded 16px, elevated by default, outline (its edge drawn inside, so its parts line up with an elevated card's), soft, tinted (bg-tint, which its words and chart keep their contrast on) or plain (no surface or padding): the title truncates with its full text in its title, the value is title-lg in tabular figures, or 32px at size lg, the change wraps under it, and the chart is 160px tall. While it loads, each part's skeleton holds that part's place, so nothing moves when the numbers arrive; the info button is 28px square.

See it in the roastery demo's overview.