Data display
Delta & Metric
Delta is a trend glyph and value in the semantic tone. Metric is label, 32 SemiBold value, delta and caption.
lucide-react
Preview
+18%-4%0%
Prospects discovered
1,284+18%
vs. prior 7 days
Bounce rate
2.1%-4%
vs. prior 7 days
Meetings booked
200%
vs. prior 7 days
import { Delta, Metric, Sparkbars } from "@/components/ui/metric";
export default function Example() {
return (
<div className="flex w-full flex-col gap-6">
<div className="flex gap-4">
<Delta value={18} />
<Delta value={-4} />
<Delta value={0}>0%</Delta>
</div>
<div className="grid gap-px overflow-hidden rounded-lg border border-line bg-line sm:grid-cols-3">
<Metric className="bg-surface p-5" label="Prospects discovered" value="1,284" delta={<Delta value={18} />} caption="vs. prior 7 days" aside={<Sparkbars values={[3, 5, 4, 6, 5, 7, 8]} />} />
<Metric className="bg-surface p-5" label="Bounce rate" value="2.1%" delta={<Delta value={-4} invert />} caption="vs. prior 7 days" />
<Metric className="bg-surface p-5" label="Meetings booked" value="20" delta={<Delta value={0}>0%</Delta>} caption="vs. prior 7 days" />
</div>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install lucide-reactCreate a
metric.tsxfile and paste the following code into it.src/components/ui/metric.tsximport { ArrowDownRight, ArrowUpRight, Minus } from "lucide-react"; import type { ReactNode } from "react"; import { cx } from "@/utils/cx"; export interface DeltaProps { /** Positive, negative or zero. The sign picks the tone and glyph. */ value: number; /** Formatted label. Defaults to `+12%`. */ children?: ReactNode; /** Flip colors when lower is better (e.g. bounce rate). */ invert?: boolean; className?: string; } /** Trend glyph + 12 Medium value in the semantic tone. */ export function Delta({ value, children, invert, className }: DeltaProps) { const up = value > 0; const flat = value === 0; const good = invert ? !up : up; const Icon = flat ? Minus : up ? ArrowUpRight : ArrowDownRight; return ( <span className={cx( "inline-flex items-center gap-0.5 text-sm font-medium tabular", flat ? "text-fg-muted" : good ? "text-success-text" : "text-error-text", className, )} > <Icon aria-hidden className="size-3.5" strokeWidth={2.25} /> {children ?? `${up ? "+" : ""}${value}%`} </span> ); } export interface MetricProps { label: ReactNode; value: ReactNode; delta?: ReactNode; caption?: ReactNode; /** Visual on the right, e.g. a <Sparkbars>. */ aside?: ReactNode; size?: "md" | "lg"; className?: string; } /** Label, 32 SemiBold value, delta, caption. */ export function Metric({ label, value, delta, caption, aside, size = "lg", className }: MetricProps) { return ( <div className={cx("flex items-end justify-between gap-4", className)}> <div className="min-w-0"> <div className="text-base text-fg-secondary">{label}</div> <div className="mt-2 flex items-baseline gap-2"> <span className={cx(size === "lg" ? "text-metric" : "text-2xl font-semibold tabular tracking-tight", "text-fg")}>{value}</span> {delta} </div> {caption && <div className="mt-1.5 text-sm text-fg-muted">{caption}</div>} </div> {aside} </div> ); } /** Tiny bar sparkline used beside metrics. The last bar is highlighted. */ export function Sparkbars({ values, className }: { values: number[]; className?: string }) { const max = Math.max(...values, 1); return ( <div aria-hidden className={cx("flex h-8 items-end gap-[3px]", className)}> {values.map((v, i) => ( <span key={i} style={{ height: `${Math.max(12, (v / max) * 100)}%` }} className={cx("w-1 rounded-[1px]", i === values.length - 1 ? "bg-chart-primary" : "bg-chart-neutral")} /> ))} </div> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | — | Delta: sign picks tone and glyph. |
| invert | boolean | — | Delta: lower is better. |
| aside | ReactNode | — | Metric: visual on the right, e.g. Sparkbars. |