Loading component…
Loading component…
A total split into its parts in one small card – numbers roll, the bar glides and the ranked rows trade places when the period changes
To reuse this local React demo, copy all files from the Code tab into the same folder, then import CompactBreakdown from ./compact-breakdown.
import { CompactBreakdown } from "@/components/ui/compact-breakdown";
export function RevenueByChannel() {
const [period, setPeriod] = useState("30d");
const { items, delta } = useRevenue(period); // [{ label: "Direct", value: 16900 }, …]
return (
<CompactBreakdown
title="Revenue by channel"
periods={[
{ id: "7d", label: "7d" },
{ id: "30d", label: "30d" },
{ id: "90d", label: "90d" },
]}
period={period}
onPeriodChange={setPeriod}
items={items}
delta={delta}
format={(n) => `$${Math.round(n).toLocaleString("en-US")}`}
totalLabel="Total revenue"
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| items | BreakdownItem[] | { id?, label, value, color? } – the parts of the shown period; the list ranks them by value. Give an id when labels can change | |
| title | string | "Breakdown" | Heading of the card |
| periods | { id: string; label: string }[] | Options of the period switch – no switch when left out | |
| period | string | Controlled period id | |
| defaultPeriod | string | first period | Starting period when uncontrolled |
| onPeriodChange | (id: string) => void | Called with the new period – pass the matching items and delta back in | |
| delta | number | Change against the previous period in percent (12.4 or -3) – a small green or red pill next to the total | |
| format | (value: number) => string | whole numbers with separators | Formats every value – the total, the rows and the hovered part |
| totalLabel | string | "Total" | Line under the big number while nothing is hovered |
| footer | ReactNode \| null | "Largest: <part>" | Replaces the line on the gray tray; null hides it |
| className | string | Extra class on the root |
Fills its container up to 360px; below 250px the share column goes and the values stay
Touch screens: taller rows and period options
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"