Skip to content
Thrum

Metric comparison

One metric for this period against the last: the value, the change as a signed percentage, and both values as thin bars to one scale. Use it where the earlier value matters as much as the change. For a value with a trend line, use the stat card; for the change alone, use the trend badge.

Install

npx shadcn@latest add @thrum-pro/metric-comparison

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Props

PropTypeDefaultDescription
labelstringRequiredWhat is measured. Shown as the heading and names the group for screen readers.
currentnumber | nullRequiredThe value for this period. null prints a dash and “No data”.
previousnumber | nullRequiredThe value it is compared with. null says “No earlier data”; 0 says “Up from zero” or “Down from zero” instead of a percentage.
currentLabelstringDefault "This period"Name of this period, shown beside its bar. Long names are cut with an ellipsis and kept in a title.
previousLabelstringDefault "Last period"Name of the earlier period.
invertbooleanDefault falseA fall is the good direction (churn, latency). It changes the colour of the arrow, never its shape.
formatIntl.NumberFormatOptionsDefault compactHow both values are written. The change is always a percentage with one decimal.
localestringDefault "en-US"Locale for number formatting.
colorstringDefault var(--chart-1)Colour of this period's bar. The earlier period is always drawn in the muted text colour.
soundbooleanDefault truePlay a soft tone when the value lands after a change, if the visitor has sound on.
classNamestring–Merged onto the root. It fills the width it is given.

Motion and sound

Motion

  • First draw: both bars grow from zero in 250 ms, the earlier one 40 ms later. The number appears complete.
  • A new value rolls from the number on screen and the bars move to their new lengths in 400 ms with no overshoot.
  • Reduced motion: the bars and the number appear at their values at once.

Sound

  • A soft tone when the value lands after a change. Nothing plays on first draw.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • The root is a group named by the label. Each period is a line of text with its name and value, so a screen reader reads “December $48,210”.
  • The change is a trend badge: “Up +12.4%”. Its direction is an arrow and a sign, and colour only adds whether that is good news.
  • The bars are hidden from screen readers: both values are in the text. Bars show the size of a value; the sign is in the number.
  • Focusing the comparison bars announces the absolute difference against the earlier period and reveals the floating readout.
KeysAction
TabFocus the comparison bars to reveal the exact difference against the earlier period.
EscHide the difference readout.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/metric-comparison.tsx
Packages
motion
Brings along
Chart foundationsMotion tokensAnimated numberTrend badge

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor