CategoryBreakdown
- Status
- Implemented
- Family
- 7 of 13
- Registry
- @lopifi/category-breakdown
npx shadcn@latest add @lopifi/theme @lopifi/category-breakdownThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Ranked horizontal bars with values and percentages. Not a pie chart. Humans compare lengths accurately and angles poorly; a pie with more than three slices is decoration.
Top N + "Other" (max 6 series). Percentages use largest-remainder allocation so they sum to exactly 100%.
Lifted verbatim from Dashboard & charts. The doc and this page are the same paragraphs, so they cannot disagree.
What lands in your repository
One component is never one file. Everything below is copied into your project, where you own it.
- Files
components/ledger/category-breakdown.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/category-breakdown.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
"use client";
import { allocatePercentages } from "@/lib/ledger/allocate";
import { vizColorFor } from "@/lib/ledger/chart-utils";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { Money } from "@/components/ledger/money";
import { Percent } from "@/components/ledger/percent";
export type Category = { key: string; label: string; amount: number };
export interface CategoryBreakdownProps {
categories: Category[];
className?: string;
currency: string;
/** Max 6 series; the rest group into "Other". Beyond that is a data problem. */
maxSeries?: number;
title?: string;
}
/**
* Ranked horizontal bars. **Not a pie chart** — humans compare lengths
* accurately and angles poorly.
*
* Percentages use largest-remainder allocation, so they sum to exactly 100%.
*/
export function CategoryBreakdown({
categories,
currency,
maxSeries = 6,
className,
title,
}: CategoryBreakdownProps) {
const sorted = [...categories].sort((a, b) => b.amount - a.amount);
const top = sorted.slice(0, maxSeries - (sorted.length > maxSeries ? 1 : 0));
const rest = sorted.slice(top.length);
const rows =
rest.length > 0
? [...top, { amount: rest.reduce((s, c) => s + c.amount, 0), key: "other", label: "Other" }]
: top;
const percentages = allocatePercentages(rows.map((r) => r.amount));
const max = Math.max(...rows.map((r) => r.amount), 1);
return (
<div className={cn("w-full", className)}>
<table className="w-full">
{title ? <caption className="sr-only">{title}</caption> : null}
<tbody>
{rows.map((row, i) => (
<tr key={row.key}>
<th className="w-[35%] max-w-0 truncate py-2 pr-3 text-left text-body font-normal" scope="row">
{row.label}
</th>
<td className="py-2">
<div
aria-hidden="true"
className="h-4 rounded-xs"
style={{
background: vizColorFor(row.key),
width: `${(row.amount / max) * 100}%`,
}}
/>
</td>
<td className="w-24 py-2 pl-3 text-right">
<Money value={{ amount: row.amount, currency } as MoneyValue} />
</td>
<td className="w-16 py-2 pl-3 text-right">
<Percent
className="text-text-secondary"
signed={false}
value={{ kind: "relative", value: percentages[i] }}
/>
</td>
</tr>
))}
</tbody>
</table>
<p className="mt-2 text-caption text-text-tertiary">
Shares allocated by largest remainder, so they sum to exactly 100%.
</p>
</div>
);
}
Also in Dashboard & charts
- DashboardShellResponsive grid with optional rearrange.
- KpiRow2–4 KPI cards with aligned baselines.Spec
- MoneyChartLine/area with a money axis and negative-aware baseline.
- MoneyBarChartGrouped/stacked, zero-baseline origin, hatched negatives.
- WaterfallChartThe P&L bridge. Essential and rare.
- CashCalendarDaily heatmap of cash movement.
- CandlestickChartFor FX/crypto pairs.
- ChartLegendInteractive, keyboard-navigable.Spec
- ChartTooltipTouch-persistent readout.Spec
- DataTableToggleEvery chart's accessible table equivalent.Spec
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Dashboard & charts — the family specThe four-layer specification this component was built against, before it was written.Doc
- Financial charts for React: waterfalls and sparklinesThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
Elsewhere in the system
Where CategoryBreakdown sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.
- CategoryBreakdown, runningThe charts showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Dashboard & chartsWe wrap a charting engine (Recharts, or visx where more control is needed). We do not rebuild one. What we add is everything a chart library doesn't know about money. Specs for 11 React components: DashboardShell, KpiRow, MoneyChart, MoneyBarChart and 7 more.Doc
Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.
Told when Dashboard & charts changes
Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.