KPI stripFree

How's the week, in four numbers?

npx shadcn@latest add https://beautifulcharts.dev/r/kpi-strip.json

Usage

A complete client module. Install the item first, then paste it into your app.

"use client";

import { KpiStripBlock } from "@/components/beautiful-charts/blocks/instrument/kpi-strip";

export function Dashboard() {
  return <KpiStripBlock />;
}

Props

  • data

    KpiStripItem[]

    Your rows (KpiStripItem = Pick<KpiStatProps, "title" | "value" | "previous" | "previousLabel" | "target" | "trend" | "polarity" | "valueFormatter" | "unit">). Missing values are null and stay gaps; with no rows every stat shows a dash. Leave it out to see the sample.

  • className

    string

    Classes for the strip. Classes on the card.

Every kpi stat prop works too, so you can restyle it without touching the source.

Sourcecomponents/beautiful-charts/blocks/instrument/kpi-strip.tsx

Show the source (27 lines)
"use client";

import { KpiStat, type KpiStatProps } from "../../themes/instrument/kpi-stat";

export type KpiStripItem = Pick<KpiStatProps, "title" | "value" | "previous" | "previousLabel" | "target" | "trend" | "polarity" | "valueFormatter" | "unit">;
/** Sample: four headline metrics for a weekly business review. */
export const kpiStripSample: KpiStripItem[] = [
  { title: "Revenue", value: 48200, previous: 45100, previousLabel: "last week", trend: [39, 41, 40, 43, 44, 45.1, 48.2].map((v) => v * 1000), valueFormatter: (v) => `$${(v / 1000).toFixed(1)}k` },
  { title: "Active teams", value: 312, previous: 298, previousLabel: "last week", target: 350, trend: [240, 252, 261, 270, 284, 298, 312] },
  { title: "Churn", value: 1.8, previous: 2.3, previousLabel: "last week", polarity: "down", valueFormatter: (v) => `${v.toFixed(1)}%`, trend: [2.9, 2.6, 2.7, 2.4, 2.5, 2.3, 1.8] },
  { title: "Support backlog", value: 41, previous: 29, previousLabel: "last week", polarity: "down", trend: [22, 25, 24, 27, 26, 29, 41] },
];

/** "How's the week, in four numbers?" Each KPI says its change in words and tints it by meaning. */
export function KpiStripBlock({ data = kpiStripSample, className, ...shared }: {
  /** One entry per KPI. Leave it out to see the sample. */
  data?: KpiStripItem[] | undefined;
  /** Classes for the strip. */
  className?: string | undefined;
} & Partial<Omit<KpiStatProps, keyof KpiStripItem>>) {
  return (
    <div className={className} data-bc-block="kpi-strip" style={{ display: "grid", gap: 16, gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 220px), 1fr))" }}>
      {data.map((item, i) => <KpiStat key={i} density="compact" {...shared} {...item} />)}
    </div>
  );
}

Details

Props every chart shares (2): locale, timeZone
  • locale

    string

    BCP 47 locale. Defaults to "en-US" so server and client render the same text.

  • timeZone

    string

    IANA time zone for dates. Defaults to "UTC" so server and client agree.

Pointer
Not interactive.
Keyboard
Not focusable: there's nothing to move between.
Screen readers
A labelled group: the value, its change in words and the target are read as one sentence.
Motion
The value rolls in digit by digit, the trend line draws, then the change fades in. With reduced motion it appears settled at once.