TrialBalance
- Status
- Implemented
- Family
- 6 of 13
- Registry
- @lopifi/trial-balance
npx shadcn@latest add @lopifi/theme @lopifi/trial-balanceThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Every account with debit and credit columns and the proof that they're equal. The most boring component in the library and the one an accountant checks first.
Lifted verbatim from Statements. 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/trial-balance.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/trial-balance.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
import * as React from "react";
import { useScrollEdges } from "@/hooks/ledger/use-scroll-edges";
import { cn } from "@/lib/ledger/cn";
import { CheckIcon, ExclamationTriangleIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
import { Rule } from "@/components/ledger/rule";
export type TrialBalanceRow = {
number: string;
name: string;
/** Two columns. One of these is zero for any given account. */
debit: number;
credit: number;
normalBalance: "Dr" | "Cr";
};
export interface TrialBalanceProps extends React.ComponentPropsWithoutRef<"div"> {
asOfLabel: string;
currency: string;
/** Caps the scroller so the header and the account column can freeze. */
maxHeight?: number;
rows: TrialBalanceRow[];
totalCredit: number;
totalDebit: number;
}
/**
* The most boring component in the library, and the one an accountant checks
* first. Every account, with the proof that debits equal credits.
*/
export const TrialBalance = React.forwardRef<HTMLDivElement, TrialBalanceProps>(
({ className, rows, currency, totalDebit, totalCredit, asOfLabel, maxHeight = 520, ...props }, ref) => {
const scroller = useScrollEdges<HTMLDivElement>();
const balanced = totalDebit === totalCredit;
return (
<div className={cn("rounded-xl border border-border bg-surface", className)} ref={ref} {...props}>
<div className="px-6 pb-4 pt-6">
<p className="text-title-sm font-medium">Trial balance</p>
<p className="text-caption text-text-secondary">{asOfLabel}</p>
</div>
<div className="ledger-frozen scrollbar-thin" ref={scroller} style={{ maxHeight }}>
<table className="w-full min-w-[680px]">
<caption className="sr-only">Trial balance. {asOfLabel}</caption>
<thead>
<tr className="border-b border-border-subtle">
<th className="px-6 py-3 text-left text-label font-medium text-text-secondary" scope="col">
Account
</th>
<th className="px-3 py-3 text-left text-label font-medium text-text-secondary" scope="col">
Normal
</th>
<th className="px-3 py-3 text-right text-label font-medium text-text-secondary" scope="col">
Debit
</th>
<th className="px-6 py-3 text-right text-label font-medium text-text-secondary" scope="col">
Credit
</th>
</tr>
</thead>
<tbody>
{rows.map((r) => (
<tr className="border-b border-border-subtle" key={r.number}>
<th className="px-6 py-2 text-left font-normal" scope="row">
<span className="reference-numeric text-caption text-text-tertiary">{r.number}</span>{" "}
<span className="text-body">{r.name}</span>
</th>
<td className="px-3 py-2 text-left text-caption text-text-secondary">{r.normalBalance}</td>
<td className="px-3 py-2 text-right">
{r.debit === 0 ? (
<span className="numeric relative text-figure-sm text-text-tertiary">
<span aria-hidden="true">—</span>
<span className="sr-only select-none">zero</span>
</span>
) : (
<Money accounting value={{ amount: r.debit, currency }} />
)}
</td>
<td className="px-6 py-2 text-right">
{r.credit === 0 ? (
<span className="numeric relative text-figure-sm text-text-tertiary">
<span aria-hidden="true">—</span>
<span className="sr-only select-none">zero</span>
</span>
) : (
<Money accounting value={{ amount: r.credit, currency }} />
)}
</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<td colSpan={2} />
<td className="px-3">
<Rule variant="subtotal" />
</td>
<td className="px-6">
<Rule variant="subtotal" />
</td>
</tr>
<tr>
<th className="px-6 py-3 text-left text-label font-medium" scope="row">
Totals
</th>
<td />
<td className="px-3 py-3 text-right">
<Money accounting size="md" value={{ amount: totalDebit, currency }} />
</td>
<td className="px-6 py-3 text-right">
<Money accounting size="md" value={{ amount: totalCredit, currency }} />
</td>
</tr>
<tr>
<td colSpan={2} />
<td className="px-3">
<Rule variant="total" />
</td>
<td className="px-6">
<Rule variant="total" />
</td>
</tr>
</tfoot>
</table>
</div>
<p
className={cn(
"m-6 mt-4 flex items-center gap-2 rounded-sm px-3 py-2 text-body",
balanced ? "bg-positive-subtle text-positive" : "bg-negative-subtle text-negative",
)}
role={balanced ? undefined : "alert"}
>
{balanced ? (
<CheckIcon aria-hidden="true" className="size-4" />
) : (
<ExclamationTriangleIcon aria-hidden="true" className="size-4" />
)}
{balanced ? (
"Debits equal credits."
) : (
<>
Out of balance by{" "}
<Money tone="inherit" value={{ amount: Math.abs(totalDebit - totalCredit), currency }} />.
</>
)}
</p>
</div>
);
},
);
TrialBalance.displayName = "TrialBalance";
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.
- CreditThe right column. It increases liabilities, equity and revenue, and decreases assets and expenses.
- DebitThe left column. It increases assets and expenses, and decreases liabilities, equity and revenue.
- Trial balanceEvery account's balance in two columns, proving that total debits equal total credits
Also in Statements
- StatementTableThe shared shell: hierarchy, periods, rules.
- StatementRowIndent level, subtotal, total, expand.
- ProfitAndLossP&L with period comparison and variance.
- BalanceSheetAssets / liabilities / equity, with the balance check.
- CashFlowStatementOperating / investing / financing.
- StatementToolbarBasis, period, comparison, currency, consolidation.
- PeriodPickerFiscal-aware. Never assumes January.
- VarianceCellAbsolute + percent + significance flag.
- FluxAnalysisPeriod-over-period explanations.
- DrilldownSheetStatement line → the GL entries behind it.
- CloseChecklistTasks, owners, blockers, sign-off.
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Statements — the family specThe four-layer specification this component was built against, before it was written.Doc
- Financial statement componentsThe 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 TrialBalance 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.
- TrialBalance, runningThe tables 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
- ReportsShould you build statements on the reports endpoints?API
- StatementsThe largest gap in the market. No component library ships a <BalanceSheet />. This family is the reason Lopifi exists. Specs for 12 React components: StatementTable, StatementRow, ProfitAndLoss, BalanceSheet and 8 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 Statements 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.