A key number with its change, the period it's compared with and an optional trend.
Recurring revenue
$296.8K
Up 2.5% vs October, an improvement
Weekly signups
859
Up 4.8% vs last week, an improvement
p95 latency
236 ms
Down 12% vs yesterday, an improvement
Open tickets
254
Up 14 vs last week, a decline
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Stat } from "./ui/uicontext/components/charts/Stat.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"import { latency, mrr, signupsByPlan, ticketsByStatus } from "./metrics.ts"const styles = stylex.create({ row: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 200px), 1fr))", gap: space.lg, inlineSize: "100%" },})const revenue = mrr[0]?.points.map((_, i) => mrr.reduce((sum, s) => sum + (s.points[i]?.y ?? 0), 0)) ?? []const signups = signupsByPlan[0]?.points.map((_, i) => signupsByPlan.reduce((sum, s) => sum + (s.points[i]?.y ?? 0), 0)) ?? []const p95 = (latency[1]?.points ?? []).filter((_, i) => i % 24 === 0).map((p) => p.y)const open = ticketsByStatus[0]?.points.map((p) => p.y) ?? []const change = (values: ReadonlyArray<number | null>) => { const last = values.at(-1) ?? 0 const before = values.at(-2) ?? 0 return before === null || before === 0 || last === null ? 0 : (last - before) / before}// The numbers a team checks first. Latency going down is good, so its drop is green; open tickets// going up is bad.export const KpiRow = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.row)).children( Stat(h, { label: "Recurring revenue", value: revenue.at(-1) ?? null, format: { style: "currency", currency: "USD" }, change: { value: change(revenue), period: "vs October" }, trend: revenue }), Stat(h, { label: "Weekly signups", value: signups.at(-1) ?? null, change: { value: change(signups), period: "vs last week" }, trend: signups }), Stat(h, { label: "p95 latency", value: p95.at(-1) ?? null, format: { style: "unit", unit: "millisecond" }, change: { value: -0.12, period: "vs yesterday" }, good: "down", trend: p95 }), Stat(h, { label: "Open tickets", value: open.reduce<number>((sum, v) => sum + (v ?? 0), 0), change: { value: 14, period: "vs last week", as: "absolute" }, good: "down" }), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/statUsage
import { Stat } from "./ui/uicontext/components/charts/Stat.ts"export const RevenueStat = <M>(h: Html.H<M>, mrr: number, change: number, trend: ReadonlyArray<number>) => Stat(h, { label: "Recurring revenue", value: mrr, format: { style: "currency", currency: "USD" }, change: { value: change, period: "vs last month" }, trend, })Examples
States
Loading, empty, unchanged, linked, and a very large number.
Net revenue retention
Refunds this month
—
No change vs last month
Uptime, last 30 days
99.98%
No change vs last 30 days
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Stat } from "./ui/uicontext/components/charts/Stat.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ row: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 200px), 1fr))", gap: space.lg, inlineSize: "100%" },})// Loading, no value yet, no change, a linked report, and a number too big for the card.export const StatStates = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.row)).children( Stat(h, { label: "Net revenue retention", value: null, loading: true }), Stat(h, { label: "Refunds this month", value: null, change: { value: 0, period: "vs last month" } }), Stat(h, { label: "Uptime, last 30 days", value: 0.9998, format: { style: "percent", digits: 2 }, change: { value: 0, period: "vs last 30 days" }, good: "neither" }), Stat(h, { label: "API requests served this year across every region", value: 48_213_904_117, change: { value: 1.84, period: "vs last year" }, href: "#requests" }), )API reference
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | — |
valuerequired | number | null | Null: no value yet, shown as "—" |
format | ChartFormat | — |
change | StatChange | — |
good | "up" | "down" | "neither" | Which way is good: up (revenue, the default), down (latency, churn) or neither |
trend | ReadonlyArray<number | null> | Recent values, oldest first, drawn as a sparkline |
href | string | A link to the full report: the label becomes it |
loading | boolean | Shows a placeholder in the value's place |
locale | string | — |
style | Style | — |
Accessibility
- The change is read in words, with its direction and whether that's good: “Up 8.4% vs October, an improvement”. Color only repeats it.