Metric
Display one key number with rolling odometer digits, an optional change chip, supporting context, and an interactive sparkline trend.
import { Metric } from '@uthereal/ui/metric'Metric playground
Weekly active users
+18.4% vs last week2,486
Last 7 days
| Point | Weekly active users |
|---|---|
| Mon | 1,890 |
| Tue | 1,960 |
| Wed | 2,040 |
| Thu | 2,120 |
| Fri | 2,245 |
| Sat | 2,360 |
| Sun | 2,486 |
Overview
Metric renders a single headline KPI inside a bordered surface tile. Pass label and a raw numeric value for a compact KPI tile, or add data (2–200 points in chronological order) to embed a monotone sparkline that draws in on view and supports pointer, touch-drag, and keyboard scrubbing.
Use Metric for dashboard summaries and trend tiles. Use Line chart when you need axes, multi-series comparisons, or legend toggles, and Pill for standalone inline status tags.
| Mode | Trigger prop | Layout | Best for |
|---|---|---|---|
| KPI tile | data omitted | Top label and optional change chip, rolling odometer value, and optional context line. | Headline totals, quotas, and counters. |
| Trend tile | data set | Adds a monotone SVG sparkline with optional area wash, baseline, end dot, and live scrubbing. | Revenue, latency, and usage over time. |
| Narrow layout | <= 380px | Container query tightens padding from 24 px to 16 px and wraps the change chip under label. | Dense multi-column grids and sidebars. |
Usage
'use client'
import { useState } from 'react'
import { Metric } from '@uthereal/ui/metric'
const weeklyRevenue = [41200, 43800, 42950, 46100, 48750, 51400, 54280]
const weekLabels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
export function RevenueTile() {
const [point, setPoint] = useState<{
index: number
value: number
label?: string
} | null>(null)
return (
<Metric
label="Weekly revenue"
value={weeklyRevenue[weeklyRevenue.length - 1]}
valueFormat={{
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0,
}}
change="+12.4% vs last week"
context={point ? `Inspecting ${point.label}` : 'Last 7 days'}
tone="success"
data={weeklyRevenue}
labels={weekLabels}
onScrub={setPoint}
/>
)
}Examples
Use <SchemaPlayground /> above to inspect individual props, recipe, theme, and motion presets. The sets below show plain KPI tiles, sparkline trend tiles, and semantic tones.
KPI tiles
Omit data to render plain KPI tiles. Use valueFormat for locale-aware currencies and percentages, or prefix and suffix for non-ISO units such as " ms".
Monthly revenue
+12.4% vs last month$54,280
Billed across 184 workspaces
Checkout conversion
+0.4 pts4.8%
Last 30 days
Median API latency
42 ms
Global edge average
Sparkline trends
Pass data (2–200 points, oldest first) and matching labels to render an interactive trend line. Hover, touch-drag, or focus and press arrow keys to scrub along the curve; set area={false} for a bare stroke or interactive={false} for a static line.
Daily signups
+14.2% vs prior 15d186
Hover or press arrows to scrub
| Point | Daily signups |
|---|---|
| May 1 | 64 |
| May 2 | 72 |
| May 3 | 68 |
| May 4 | 85 |
| May 5 | 94 |
| May 6 | 112 |
| May 7 | 108 |
| May 8 | 126 |
| May 9 | 138 |
| May 10 | 132 |
| May 11 | 149 |
| May 12 | 164 |
| May 13 | 158 |
| May 14 | 172 |
| May 15 | 186 |
Hourly requests
268 req/s
Bare stroke (area off)
| Point | Hourly requests |
|---|---|
| 00:00 | 142 req/s |
| 01:00 | 118 req/s |
| 02:00 | 96 req/s |
| 03:00 | 84 req/s |
| 04:00 | 78 req/s |
| 05:00 | 92 req/s |
| 06:00 | 136 req/s |
| 07:00 | 210 req/s |
| 08:00 | 318 req/s |
| 09:00 | 412 req/s |
| 10:00 | 468 req/s |
| 11:00 | 495 req/s |
| 12:00 | 482 req/s |
| 13:00 | 456 req/s |
| 14:00 | 470 req/s |
| 15:00 | 512 req/s |
| 16:00 | 548 req/s |
| 17:00 | 530 req/s |
| 18:00 | 462 req/s |
| 19:00 | 390 req/s |
| 20:00 | 344 req/s |
| 21:00 | 298 req/s |
| 22:00 | 254 req/s |
| 23:00 | 220 req/s |
| 24:00 | 268 req/s |
Static trend
99.6%
Interactive scrubbing disabled
| Point | Static trend |
|---|---|
| Mon | 99.1% |
| Tue | 99.3% |
| Wed | 99.2% |
| Thu | 99.4% |
| Fri | 99.5% |
| Sat | 99.5% |
| Sun | 99.6% |
Semantic tones
tone tints the trend line, its end dot, the area wash, and status change chips (success, warning, danger). Always include explicit signed copy in change so direction never relies on color alone.
Queue depth
+28% near limit412
| Point | Queue depth |
|---|---|
| 10:00 | 180 |
| 10:10 | 210 |
| 10:20 | 245 |
| 10:30 | 290 |
| 10:40 | 340 |
| 10:50 | 375 |
| 11:00 | 412 |
Error rate
+1.8 pts spike2.4%
| Point | Error rate |
|---|---|
| 10:00 | 0.4% |
| 10:10 | 0.5% |
| 10:20 | 0.6% |
| 10:30 | 0.9% |
| 10:40 | 1.4% |
| 10:50 | 1.9% |
| 11:00 | 2.4% |
Modes, tones, and formatting
Tones
tone | Line & end dot | Area wash (9% oklab) | Change chip | When to use |
|---|---|---|---|---|
accent | --ui-accent | --ui-accent-strong | Neutral hairline (--ui-border) | Default trend accent without good/bad judgment. |
neutral | --ui-border-strong | --ui-text-secondary | Neutral hairline (--ui-border) | Quiet ink trend for secondary or baseline metrics. |
success | --ui-success | --ui-success | 11% --ui-success tint, --ui-success text | Positive movement (growth, uptime, faster times). |
warning | --ui-warning | --ui-warning | 11% --ui-warning tint, --ui-warning text | Caution, approaching limits, or mixed movement. |
danger | --ui-danger | --ui-danger | 11% --ui-danger tint, --ui-danger text | Regression, errors, or budget overruns. |
Number formatting
Metric formats raw numbers with Intl.NumberFormat using the resolved BCP 47 locale (locale prop > UtherealProvider > 'en-US' for deterministic SSR).
| Pattern | Props | Output (en-US) |
|---|---|---|
| Grouped integer | value={14280} | 14,280 |
| Currency | value={54280} valueFormat={{ style: 'currency', currency: 'USD', maximumFractionDigits: 0 }} | $54,280 |
| Percentage | value={0.994} valueFormat={{ style: 'percent', minimumFractionDigits: 1 }} | 99.4% |
| Custom unit | value={42} suffix=" ms" | 42 ms |
| Locale override | value={12450.5} valueFormat={{ style: 'currency', currency: 'EUR' }} locale="de-DE" | 12.450,50 € |
API reference
Serializable schema arguments and defaults come directly from metricConfigSchema.
| Argument | Type / default | Description |
|---|---|---|
labelRequired | string— | What is measured, in sentence case, e.g. "Monthly revenue". |
valueRequired | number— | The headline value as a raw number. It is formatted with valueFormat in the locale; supply raw numbers, not text. |
prefix | string— | Text before the value, e.g. "$" or "~". For currency use valueFormat instead. |
suffix | string— | Text after the value, e.g. " ms" or "%". For percent use valueFormat instead. |
valueFormat | NumberFormat— | How the value shows: decimal (with fraction digits and grouping), percent (0.25 shows 25%) or currency (with an ISO code). |
context | string— | Supporting line under the value, e.g. "Last 30 days". While a trend is explored it shows the point label instead. |
change | string— | The change against a comparison, as short text with its sign, e.g. "+12.4% vs last month". |
tone | neutral | accent | success | warning | dangerDefault: "accent" | Tint of the trend line, its end dot and the change chip: accent by default, neutral for ink, success when the move is good, danger when it is bad, warning for caution. The text always says the change, so color is never alone. |
data | number[]— | Trend values in time order, oldest first (2–200), drawn as an embedded line under the value; omit it for a plain KPI tile without a chart. |
labels | string[]— | One label per trend value, such as a date; shown and announced while exploring the trend. The count must match data. |
area | booleanDefault: true | A quiet wash under the trend line. |
interactive | booleanDefault: true | Pointer, touch-drag and keyboard exploration (arrows, PageUp/PageDown, Home/End, Escape): a cursor glides along the line, later points dim and the value and context roll to the explored point. |
sparklineHeight | integerDefault: 48 | Height of the trend line in pixels (28–120, 48 by default). It fills the width of its container. |
locale | string— | BCP 47 locale for the value. Omit it to inherit the application locale (en-US by default). |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | MetricTheme— | Color mode, accent, and tokens: core colors and type, the chart palette of the trend, the change colors (success, warning), the tile surface and resting shadow, and valueSize (36). See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset: the value rolls digit by digit to each new number, the label, change and context swap with a small rise and blur, the change pill scales in and follows its width, and the trend draws in like a pen. Reduced motion crossfades; none changes at once. |
motionOptions | ChartMotionOptions— | The trend line draw-in and morph to new data, in milliseconds. |
dir | ltr | rtl— | Reading direction of the text; the trend runs oldest to newest left to right. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
formatValue(value, index) | Custom formatter for scrubbed trend points (and data-table cells); defaults to valueFormat. |
onScrub(point) | Fires with { index, value, label? } as the explored point changes, and null when scrubbing ends. |
preset | Application defaults overridden by instance props (content fields label, value, data, etc. excluded). |
tokens | --ui-* CSS custom properties applied after the typed theme. |
ref | Ref forwarded to the root <figure> element. |
className, style, rest | Forwarded to <figure>; style wins over motion and theme tokens. |
Keyboard & accessibility
When data is present and interactive is true, the sparkline plot exposes role="slider" (tabIndex={0}) with live aria-valuenow (1..N) and aria-valuetext ("{label}: {formattedValue}", defaulting to "Latest" at rest). Focus alone preserves the headline until a navigation key is pressed.
| Key | Interaction |
|---|---|
ArrowRight, ArrowUp | Steps forward to the next chronological point. |
ArrowLeft, ArrowDown | Steps backward to the previous chronological point. |
PageUp, PageDown | Jumps forward or backward by one sixth of the series (at least 1). |
Home, End | Jumps to the first (oldest) or last (latest) point. |
Escape | Exits scrubbing and returns the headline and context to rest. |
- Screen readers: The root
<figure>is named bylabelviaaria-labelledby. Whendatais present,aria-detailslinks to a visually hiddenChartDataTablelisting every point and formatted value. Animated text and odometer wheels keep a single visually hidden plain-text string while marking animated spansaria-hidden="true". - Touch and RTL: The interactive plot sets
touch-action: pan-yso vertical page scrolling remains smooth while horizontal drags scrub points. Logical CSS properties adapt text, padding, and chip layout todir="rtl", while the time-series curve keeps oldest-to-newest left-to-right progression. - Forced colors: Under
@media (forced-colors: active), tile and chip borders useButtonText, status chips useHighlight/HighlightText, the trend line and end dot useHighlight, and the baseline, trailing segment, and cursor useCanvasText.
Motion and theming
| Mode | Value odometer | Label & context swap | Change chip width | Sparkline draw & scrub |
|---|---|---|---|---|
motion="subtle" (default) | Rolls digit-by-digit on view/change | Rise 0.3em through blur (240 ms / 160 ms) | Springs on morph within 120 ms change window | 840 ms pen draw (inOut), snappy cursor & dot grow |
motion="expressive" | Rolls digit-by-digit on view/change | Rise 0.3em through blur (240 ms / 160 ms) | Springs on morph within 120 ms change window | Uses chart expressive morph and draw options |
prefers-reduced-motion: reduce | Snaps digits immediately | 120 ms opacity crossfade (no travel or blur) | Snaps width to auto | Full line shown immediately; cursor snaps without trail |
motion="none" | Immediate (0 ms) | Immediate (0 ms) | Immediate (0 ms), width stays auto | Full line shown immediately; 0 ms transitions |
Tune sparkline draw-in and dataset morph transitions via motionOptions.draw and motionOptions.morph (durations in milliseconds).
| Token group | CSS custom properties |
|---|---|
| Surface & ink | --ui-surface, --ui-border, --ui-border-strong, --ui-border-width, --ui-surface-radius, --ui-radius, --ui-shadow-resting, --ui-text, --ui-text-secondary, --ui-muted |
| Tone colors | --ui-accent, --ui-accent-strong, --ui-success, --ui-warning, --ui-danger, --ui-focus-ring |
| Typography | --ui-font, --ui-font-display, --ui-font-weight, --ui-metric-value-size (36px default) |
UtherealProvider supplies application-wide recipe, theme, locale, and motion defaults below preset and instance props.
Composition
In agent compositions, Metric is a leaf component with no persisted state and an optional onScrub UI event.
{
"type": "Metric",
"props": {
"label": "Active workspaces",
"value": 1284,
"change": "+8.2% vs last month",
"context": "30-day rolling active",
"tone": "success",
"data": [1090, 1125, 1140, 1185, 1210, 1248, 1284],
"labels": ["Wk 1", "Wk 2", "Wk 3", "Wk 4", "Wk 5", "Wk 6", "Wk 7"]
},
"children": []
}