ChartOfAccounts
- Status
- Implemented
- Family
- 9 of 13
- Registry
- @lopifi/chart-of-accounts
npx shadcn@latest add @lopifi/theme @lopifi/chart-of-accountsThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Hierarchical tree, max 5 levels, with type, normal balance, contra flag, statement mapping, and current balance per account. Bulk edit of mapping. Shows which accounts have no supporting-schedule mapping — itself a finding.
Lifted verbatim from Accounting core (GL). 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/chart-of-accounts.tsx
- Lopifi dependencies · 9
- accounting.typescnformat-moneyfrozen-labeliconsmoneymoney.typestooltipuse-scroll-edges
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/chart-of-accounts.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 * as React from "react";
import { useScrollEdges } from "@/hooks/ledger/use-scroll-edges";
import type { Account } from "@/lib/ledger/accounting.types";
import { cn } from "@/lib/ledger/cn";
import { FROZEN_LABEL } from "@/lib/ledger/frozen-label";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { ChevronRightIcon, ExclamationTriangleIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
export interface ChartOfAccountsProps {
accounts: Account[];
balances: Record<string, MoneyValue>;
className?: string;
/**
* Caps the scroller so the header and the account column can freeze. Without a
* height the page scrolls instead and there is nothing for the frozen
* header to stick to.
*/
maxHeight?: number;
}
/**
* Hierarchy capped at 5 levels — deeper is a chart-of-accounts problem, not
* a UI problem.
*
* Accounts with no supporting-schedule mapping are surfaced, because that
* absence is itself a finding.
*/
export function ChartOfAccounts({ accounts, balances, maxHeight = 520, className }: ChartOfAccountsProps) {
const scroller = useScrollEdges<HTMLDivElement>();
const [collapsed, setCollapsed] = React.useState<Set<string>>(new Set());
const byParent = React.useMemo(() => {
const map = new Map<string | undefined, Account[]>();
for (const a of accounts) {
const list = map.get(a.parentId) ?? [];
list.push(a);
map.set(a.parentId, list);
}
return map;
}, [accounts]);
const unsupported = accounts.filter(
(a) => (a.type === "asset" || a.type === "liability") && a.isPostable && !a.scheduleType,
);
const rows: { account: Account; depth: number }[] = [];
const walk = (parentId: string | undefined, depth: number) => {
if (depth > 5) return;
for (const a of byParent.get(parentId) ?? []) {
rows.push({ account: a, depth });
if (!collapsed.has(a.id)) walk(a.id, depth + 1);
}
};
walk(undefined, 0);
return (
<div className={cn("space-y-3", className)}>
{unsupported.length > 0 ? (
<p className="flex items-start gap-2 rounded-sm bg-warning-subtle px-3 py-2 text-body">
<ExclamationTriangleIcon aria-hidden="true" className="mt-0.5 size-4 shrink-0 text-warning" />
<span>
<span className="numeric font-medium">{unsupported.length}</span> balance-sheet accounts have no
supporting schedule mapped: {unsupported.map((a) => `${a.number} ${a.name}`).join(", ")}. That
absence is itself a finding.
</span>
</p>
) : null}
<div
className="ledger-frozen scrollbar-thin rounded-xl border border-border bg-surface"
ref={scroller}
style={{ maxHeight }}
>
<table className="w-full min-w-[820px]">
<caption className="sr-only">Chart of accounts</caption>
<thead>
<tr className="border-b border-border-subtle">
{["Account", "Type", "Normal", "Statement line", "Schedule", "Balance"].map((h, i) => (
<th
className={cn(
"px-3 py-3 text-label font-medium text-text-secondary",
i === 5 ? "text-right pr-6" : "text-left",
i === 0 && `pl-6 ${FROZEN_LABEL}`,
)}
key={h}
scope="col"
>
{h}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map(({ account: a, depth }) => {
const hasChildren = (byParent.get(a.id)?.length ?? 0) > 0;
return (
<tr className="border-b border-border-subtle" key={a.id}>
<th
className={cn(FROZEN_LABEL, "py-2 pr-3 text-left font-normal")}
data-level={depth + 1}
scope="row"
style={{ paddingLeft: 24 + depth * 24 }}
>
<span className="flex items-center gap-1.5">
{hasChildren ? (
<button
aria-expanded={!collapsed.has(a.id)}
aria-label={`${collapsed.has(a.id) ? "Expand" : "Collapse"} ${a.name}`}
className="press grid size-5 place-items-center rounded-xs text-text-tertiary hover:bg-surface-hover"
onClick={() =>
setCollapsed((prev) => {
const next = new Set(prev);
if (next.has(a.id)) next.delete(a.id);
else next.add(a.id);
return next;
})
}
type="button"
>
<ChevronRightIcon
className={cn(
"size-3.5 transition-transform duration-2 ease-standard",
!collapsed.has(a.id) && "rotate-90",
)}
/>
</button>
) : (
<span aria-hidden="true" className="size-5" />
)}
<span className="reference-numeric text-caption text-text-tertiary">{a.number}</span>
<span className={cn("text-body", !a.isPostable && "font-medium")}>{a.name}</span>
{a.isContra ? <span className="text-caption text-text-tertiary">(contra)</span> : null}
</span>
</th>
<td className="px-3 py-2 text-caption capitalize text-text-secondary">{a.type}</td>
<td className="px-3 py-2 text-caption text-text-secondary">
{a.normalBalance === "debit" ? "Dr" : "Cr"}
</td>
<td className="px-3 py-2 text-caption text-text-secondary">{a.statementMapping}</td>
<td className="px-3 py-2 text-caption text-text-secondary">
{a.scheduleType ?? <span className="text-warning">Unsupported</span>}
</td>
<td className="py-2 pl-3 pr-6 text-right">
{balances[a.id] ? (
<Money accounting value={balances[a.id]} />
) : (
<span className="numeric relative text-figure-sm text-text-tertiary">
<span className="sr-only select-none">not applicable</span>
</span>
)}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
}
The accounting it encodes
Concepts this component renders. Each one is defined once, in the lexicon, and used identically in the code and the copy.
- AccountA GL account in the chart of accounts. Always qualify when a bank account is meant.
- Chart of accountsThe account structure
- Current balancePosted, including uncleared items
- Normal balanceThe side that increases an account — debit for assets and expenses, credit for liabilities, equity and revenue, inverted for a contra account
- StatementP&L, balance sheet, or cash flow
Also in Accounting core (GL)
- JournalEntryDebit and credit as two columns. No signed-column variant.
- JournalEntryFormLine grid with live balance check and dimension capture.
- JournalEntryTableAll entries, with the gapless-numbering check.
- AccountPickerShows the normal balance. Blocks non-postable accounts.
- AccountRegisterGL detail with a running balance.
- DimensionPickerEntity always required; renders what the account demands.
- AdjustingEntryFormTemplated by type. Auto-reverse defaults on for accruals.
- RecurringEntryTemplateTemplate editable; instances read-only.
- EntryReversalDialogHold-to-confirm. Never a delete.
- ScheduleTableOne shell, seven presets. Prepaids through debt.
- RollForwardOpening → movements → closing → tie. The universal shape.
- AccountTieOutEvery BS account, proven against its evidence.
- SchedulePreviewWhat the schedules will post, before they post.
- RevenueWaterfallDeferred balance recognizing by future period.
- DepreciationScheduleBook and tax in parallel. In-service date, not purchase date.
- LeaseScheduleROU asset and liability on diverging curves.
- AllowanceRollForwardWith the methodology shown, not just the number.
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Accounting core (GL) — the family specThe four-layer specification this component was built against, before it was written.Doc
- General ledger and accounting coreThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
- AccountA GL account in the chart of accounts. Always qualify when a bank account is meant.Term
Elsewhere in the system
Where ChartOfAccounts 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.
- ChartOfAccounts, runningThe gl showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Trial balance checkerBalances — and then the harder question: is anything sitting on the wrong side of its normal?Tool
- Chart of accountsHow does each ledger model an account?API
- Accounting core (GL)The general ledger layer. Specs for 18 React components: JournalEntry, JournalEntryForm, JournalEntryTable, AccountPicker and 14 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 Accounting core (GL) 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.