Skip to content

Metric Tile

One headline number with its unit, change and trend.

1.9 kB gzipSource Registry JSON

MetricTile playground

Requests
1.28MUp 12%

Props

delta
sentiment

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/metric-tile.json

The CLI writes components/ikada/metric-tile.tsx and merges the ikada theme into your CSS. It also installs the components it is built from: Skeleton. Or take it from the package: import { MetricTile } from "@sproutboat/ikada";

Usage

import { MetricTile } from "@/components/ikada/metric-tile";

<MetricTile
  label="Requests"
  value="1.28M"
  delta={{ value: "12%", direction: "up" }}
  sparkline={<Sparkline aria-label="Requests, last 10 hours" data={requests} formatPoint={hour} />}
/>

Examples

Delta and trend

The delta is a soft pill; the sparkline sits flush to the tile's bottom edge and marks now.
Requests
1.28MUp 12%
14.8 req/s average

Sentiment

A rise in requests is neither good nor bad. Say when the direction is news: error rate down is good.
Error rate
0.21%Down 0.3 pt
Latency
184ms p50Up 9%

Count

Pass a raw number as amount and it is formatted compactly for the locale.
Requests
1.28M
Requests
1,28 Mio.

Loading

A skeleton stands in for the value and the tile is marked aria-busy.
Requests
Loading

No data

Requests
—
No requests since the last deploy

Props

MetricTileProps
PropTypeDescription
labelrequiredstringWhat the number measures, above it.
valuestringAlready formatted: "0.21". For a plain count prefer `amount`.
amountnumberA count, formatted compactly in `locale` ("1.28M", "860K"). Wins over `value`.
localestringNumber-formatting locale; defaults to the `LocaleProvider` value, else `en`.
unitstring"M", "%", "ms p50".
deltaMetricDeltaChange against the previous period, shown as an arrow and a value.
hintReactNodeA line under the value: "14.8 req/s average".
sparklineReactNodeA `<Sparkline />` from `@sproutboat/ikada/charts`, flush to the tile's bottom edge, its line ending in line with the tile's text.
loadingbooleanDraws a skeleton in place of the value. Default `false`.
noDatabooleanNothing to show for this range: an em dash and `emptyText`. Default `false`.
emptyTextstringShown when there is no value. Default "No data for this range".

Also takes every prop of Omit<ComponentProps<"div">, "children">.

Source: src/components/metric-tile.tsx