UI

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 week

2,486

Last 7 days

Weekly active users
PointWeekly active users
Mon1,890
Tue1,960
Wed2,040
Thu2,120
Fri2,245
Sat2,360
Sun2,486
Loading interactive preview…

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.

ModeTrigger propLayoutBest for
KPI tiledata omittedTop label and optional change chip, rolling odometer value, and optional context line.Headline totals, quotas, and counters.
Trend tiledata setAdds a monotone SVG sparkline with optional area wash, baseline, end dot, and live scrubbing.Revenue, latency, and usage over time.
Narrow layout<= 380pxContainer 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 pts

4.8%

Last 30 days

Median API latency

42 ms

Global edge average

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 15d

186

Hover or press arrows to scrub

Daily signups
PointDaily signups
May 164
May 272
May 368
May 485
May 594
May 6112
May 7108
May 8126
May 9138
May 10132
May 11149
May 12164
May 13158
May 14172
May 15186

Hourly requests

268 req/s

Bare stroke (area off)

Hourly requests
PointHourly requests
00:00142 req/s
01:00118 req/s
02:0096 req/s
03:0084 req/s
04:0078 req/s
05:0092 req/s
06:00136 req/s
07:00210 req/s
08:00318 req/s
09:00412 req/s
10:00468 req/s
11:00495 req/s
12:00482 req/s
13:00456 req/s
14:00470 req/s
15:00512 req/s
16:00548 req/s
17:00530 req/s
18:00462 req/s
19:00390 req/s
20:00344 req/s
21:00298 req/s
22:00254 req/s
23:00220 req/s
24:00268 req/s

Static trend

99.6%

Interactive scrubbing disabled

Static trend
PointStatic trend
Mon99.1%
Tue99.3%
Wed99.2%
Thu99.4%
Fri99.5%
Sat99.5%
Sun99.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 limit

412

Queue depth
PointQueue depth
10:00180
10:10210
10:20245
10:30290
10:40340
10:50375
11:00412

Error rate

+1.8 pts spike

2.4%

Error rate
PointError rate
10:000.4%
10:100.5%
10:200.6%
10:300.9%
10:401.4%
10:501.9%
11:002.4%

Modes, tones, and formatting

Tones

toneLine & end dotArea wash (9% oklab)Change chipWhen to use
accent--ui-accent--ui-accent-strongNeutral hairline (--ui-border)Default trend accent without good/bad judgment.
neutral--ui-border-strong--ui-text-secondaryNeutral hairline (--ui-border)Quiet ink trend for secondary or baseline metrics.
success--ui-success--ui-success11% --ui-success tint, --ui-success textPositive movement (growth, uptime, faster times).
warning--ui-warning--ui-warning11% --ui-warning tint, --ui-warning textCaution, approaching limits, or mixed movement.
danger--ui-danger--ui-danger11% --ui-danger tint, --ui-danger textRegression, 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).

PatternPropsOutput (en-US)
Grouped integervalue={14280}14,280
Currencyvalue={54280} valueFormat={{ style: 'currency', currency: 'USD', maximumFractionDigits: 0 }}$54,280
Percentagevalue={0.994} valueFormat={{ style: 'percent', minimumFractionDigits: 1 }}99.4%
Custom unitvalue={42} suffix=" ms"42 ms
Locale overridevalue={12450.5} valueFormat={{ style: 'currency', currency: 'EUR' }} locale="de-DE"12.450,50 €

API reference

Serializable schema arguments and defaults come directly from metricConfigSchema.

ArgumentType / defaultDescription
labelRequiredstring—What is measured, in sentence case, e.g. "Monthly revenue".
valueRequirednumber—The headline value as a raw number. It is formatted with valueFormat in the locale; supply raw numbers, not text.
prefixstring—Text before the value, e.g. "$" or "~". For currency use valueFormat instead.
suffixstring—Text after the value, e.g. " ms" or "%". For percent use valueFormat instead.
valueFormatNumberFormat—How the value shows: decimal (with fraction digits and grouping), percent (0.25 shows 25%) or currency (with an ISO code).
contextstring—Supporting line under the value, e.g. "Last 30 days". While a trend is explored it shows the point label instead.
changestring—The change against a comparison, as short text with its sign, e.g. "+12.4% vs last month".
toneneutral | 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.
datanumber[]—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.
labelsstring[]—One label per trend value, such as a date; shown and announced while exploring the trend. The count must match data.
areabooleanDefault: trueA quiet wash under the trend line.
interactivebooleanDefault: truePointer, 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.
sparklineHeightintegerDefault: 48Height of the trend line in pixels (28–120, 48 by default). It fills the width of its container.
localestring—BCP 47 locale for the value. Omit it to inherit the application locale (en-US by default).
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeMetricTheme—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.
motionnone | 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.
motionOptionsChartMotionOptions—The trend line draw-in and morph to new data, in milliseconds.
dirltr | rtl—Reading direction of the text; the trend runs oldest to newest left to right. Omit it to inherit the page direction.

React integration

PropPurpose
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.
presetApplication defaults overridden by instance props (content fields label, value, data, etc. excluded).
tokens--ui-* CSS custom properties applied after the typed theme.
refRef forwarded to the root <figure> element.
className, style, restForwarded 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.

KeyInteraction
ArrowRight, ArrowUpSteps forward to the next chronological point.
ArrowLeft, ArrowDownSteps backward to the previous chronological point.
PageUp, PageDownJumps forward or backward by one sixth of the series (at least 1).
Home, EndJumps to the first (oldest) or last (latest) point.
EscapeExits scrubbing and returns the headline and context to rest.
  • Screen readers: The root <figure> is named by label via aria-labelledby. When data is present, aria-details links to a visually hidden ChartDataTable listing every point and formatted value. Animated text and odometer wheels keep a single visually hidden plain-text string while marking animated spans aria-hidden="true".
  • Touch and RTL: The interactive plot sets touch-action: pan-y so vertical page scrolling remains smooth while horizontal drags scrub points. Logical CSS properties adapt text, padding, and chip layout to dir="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 use ButtonText, status chips use Highlight / HighlightText, the trend line and end dot use Highlight, and the baseline, trailing segment, and cursor use CanvasText.

Motion and theming

ModeValue odometerLabel & context swapChange chip widthSparkline draw & scrub
motion="subtle" (default)Rolls digit-by-digit on view/changeRise 0.3em through blur (240 ms / 160 ms)Springs on morph within 120 ms change window840 ms pen draw (inOut), snappy cursor & dot grow
motion="expressive"Rolls digit-by-digit on view/changeRise 0.3em through blur (240 ms / 160 ms)Springs on morph within 120 ms change windowUses chart expressive morph and draw options
prefers-reduced-motion: reduceSnaps digits immediately120 ms opacity crossfade (no travel or blur)Snaps width to autoFull line shown immediately; cursor snaps without trail
motion="none"Immediate (0 ms)Immediate (0 ms)Immediate (0 ms), width stays autoFull line shown immediately; 0 ms transitions

Tune sparkline draw-in and dataset morph transitions via motionOptions.draw and motionOptions.morph (durations in milliseconds).

Token groupCSS 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": []
}

On this page