Skip to content

BalanceSheet

Assets / liabilities / equity, with the balance check.
Implemented
Status
Implemented
Family
6 of 13
Registry
@lopifi/balance-sheet
npx shadcn@latest add @lopifi/theme @lopifi/balance-sheet

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

Assets → Liabilities → Equity, with the accounting identity checked and displayed.

  • The balance check is a first-class UI element, not a footnote. Assets 4,281,900 = Liabilities 1,840,200 + Equity 2,441,700 ✓ — and when it doesn't balance, that's a prominent error state with the difference stated, not a silently wrong statement.
  • Current vs. non-current sub-grouping.
  • As-of date, not a period — a balance sheet is a point in time and labeling it with a range is a category error the component prevents by taking a Date, not a range.
  • Comparative columns: this date vs. prior period end vs. prior year end.

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/balance-sheet.tsx

Lopifi dependencies · 14
cncolumn-managerfiscal-periodformat-moneyiconsmoneymoney.typespercentperiod-changerulestatement-tabletooltipuse-scroll-edgesvariance-cell
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/balance-sheet.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/balance-sheet.tsx
"use client";

import { cn } from "@/lib/ledger/cn";
import { formatDate } from "@/lib/ledger/fiscal-period";
import { CheckIcon, ExclamationTriangleIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
import {
  type DrilldownTarget,
  type StatementHeader,
  type StatementLine,
  StatementTable,
} from "@/components/ledger/statement-table";

export interface BalanceSheetProps {
  /** A balance sheet is a point in time. Taking a Date, not a range, makes
      "September 2026" a category error the type system prevents. */
  asOf: Date;
  className?: string;
  /** Offer the period columns to hide. See `StatementTable`. */
  columnManager?: boolean;
  comparativeDates?: Date[];
  header: Omit<StatementHeader, "statement" | "periodLabel">;
  lines: StatementLine[];
  /** Caps the scroller so the column headers freeze. See `StatementTable`. */
  maxHeight?: number;
  onDrilldown?: (line: StatementLine, target: DrilldownTarget) => void;
  /** Passed in, already computed, per column. */
  totals: { assets: number[]; liabilities: number[]; equity: number[] };
}

/**
 * The accounting identity is a first-class UI element, not a footnote.
 * When it doesn't balance, that is a prominent error state with the
 * difference stated — never a silently wrong statement.
 */
export function BalanceSheet({
  asOf,
  comparativeDates = [],
  header,
  lines,
  totals,
  onDrilldown,
  maxHeight,
  columnManager,
  className,
}: BalanceSheetProps) {
  const dates = [asOf, ...comparativeDates];
  const periods = dates.map((d) => `As of ${formatDate(d)}`);

  return (
    <div className={cn("w-full", className)}>
      <StatementTable
        columnManager={columnManager}
        header={{
          ...header,
          periodLabel: `As of ${formatDate(asOf)}`,
          statement: "Balance sheet",
        }}
        lines={lines}
        maxHeight={maxHeight}
        onDrilldown={onDrilldown}
        periods={periods}
      />

      <div className="mt-4 space-y-2">
        {dates.map((d, i) => {
          const assets = totals.assets[i];
          const liabilities = totals.liabilities[i];
          const equity = totals.equity[i];
          const difference = assets - (liabilities + equity);
          const balanced = difference === 0;

          return (
            <div
              className={cn(
                "flex flex-wrap items-center gap-x-2 gap-y-1 rounded-md border px-4 py-3",
                balanced ? "border-positive bg-positive-subtle" : "border-negative bg-negative-subtle",
              )}
              key={d.toISOString()}
              role={balanced ? undefined : "alert"}
            >
              {balanced ? (
                <CheckIcon aria-hidden="true" className="size-4 shrink-0 text-positive" />
              ) : (
                <ExclamationTriangleIcon aria-hidden="true" className="size-4 shrink-0 text-negative" />
              )}
              <span className="text-caption text-text-secondary">{formatDate(d)}:</span>
              <span className="flex flex-wrap items-baseline gap-1 text-body">
                Assets <Money accounting value={{ amount: assets, currency: header.currency }} />
                <span aria-hidden="true">=</span>
                Liabilities <Money accounting value={{ amount: liabilities, currency: header.currency }} />
                <span aria-hidden="true">+</span>
                Equity <Money accounting value={{ amount: equity, currency: header.currency }} />
              </span>
              {balanced ? (
                <span className="text-body font-medium text-positive">Balanced</span>
              ) : (
                <span className="flex items-baseline gap-1 text-body font-medium text-negative">
                  Out by{" "}
                  <Money
                    accounting
                    tone="inherit"
                    value={{ amount: difference, currency: header.currency }}
                  />
                </span>
              )}
            </div>
          );
        })}
      </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.

Also in Statements

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where BalanceSheet 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.

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.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.