KPI tile
A headline number with its comparison, direction-aware colour and an optional sparkline.
A responsive row of KPI tiles that wraps cleanly.
<KpiRow />KPI row is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/kpi-row.jsonInstalls the chart, its dependencies and the shared core into your components folder.
Then import the theme once: import "@/components/charts/core/charts.css" Installation guide
import { KpiRow } from "@/components/charts/kpi-row";
import { kpis } from "./sample-data";
export function Example() {
return (
<KpiRow
items={[
{ label: "ARR", value: kpis.arr.value, compare: kpis.arr.prior, compareLabel: "vs last year", format: "currency", trend: kpis.arr.spark },
{ label: "Net revenue retention", value: kpis.nrr.value, compare: kpis.nrr.prior, compareLabel: "vs last year", format: { kind: "percent", decimals: 1 } },
{ label: "Gross margin", value: kpis.grossMargin.value, compare: kpis.grossMargin.prior, compareLabel: "vs last year", format: { kind: "percent", decimals: 1 } },
{ label: "Active users", value: kpis.activeUsers.value, compare: kpis.activeUsers.prior, compareLabel: "vs last month", format: "integer" },
]}
/>
);
}
An array of KPI tile props.
[{ label: "ARR", value: 18.4e6, compare: 15.9e6, format: "currency" }, ...]Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data
Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API
export interface KpiRowProps {
items: (KpiTileProps & { id?: string })[];
/** Minimum tile width before tiles wrap to a new row. Default 200. */
minTileWidth?: number;
className?: string;
/** Accessible name for the group. */
label?: string;
}Installs kpi-row.tsx and the shared core/ (11 files).
"use client";
import type { CSSProperties } from "react";
import { KpiTile, type KpiTileProps } from "./kpi-tile";
import { ChartMessage } from "./core/frame";
export interface KpiRowProps {
items: (KpiTileProps & { id?: string })[];
/** Minimum tile width before tiles wrap to a new row. Default 200. */
minTileWidth?: number;
className?: string;
/** Accessible name for the group. */
label?: string;
}
/**
* A row of headline numbers that wraps responsively. Keep it to the three to five numbers a reader should see
* first; everything else belongs in a chart or a table.
*/
export function KpiRow({ items, minTileWidth = 200, className, label = "Key metrics" }: KpiRowProps) {
if (!Array.isArray(items) || !items.length)
return (
<section className={["clui", className].filter(Boolean).join(" ")} aria-label={label}>
<ChartMessage issues={[{ level: "error", message: "No data to display." }]} height={96} />
</section>
);
return (
<section
className={["clui clui-kpi-row", className].filter(Boolean).join(" ")}
style={{ "--clui-kpi-min": `${minTileWidth}px` } as CSSProperties}
aria-label={label}
>
{items.map((item, i) => (
<KpiTile key={item.id ?? item.label ?? i} {...item} />
))}
</section>
);
}
A headline number with its comparison, direction-aware colour and an optional sparkline.
KPIs against targets and qualitative ranges: the compact replacement for gauges.