ProfitAndLoss
- Status
- Implemented
- Family
- 6 of 13
- Registry
- @lopifi/profit-and-loss
npx shadcn@latest add @lopifi/theme @lopifi/profit-and-lossThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Revenue → COGS → Gross profit → Operating expenses → Operating income → Other → Net income.
- Margin rows (gross %, operating %, net %) rendered as a
Percentlevel, with their period-over-period change inpoints, visually distinguished from the money rows — a percentage in a column of dollars needs to not look like dollars. - Comparison modes: prior period, prior year, budget, forecast. Each with its own variance column.
- Expense rows are
polarity="inverted". An increase in COGS is not good news, and defaulting it to green is the bug this whole system exists to prevent. - Optional per-line
WaterfallChartdrill-in showing what drove the change.
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/profit-and-loss.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/profit-and-loss.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 { cn } from "@/lib/ledger/cn";
import {
type DrilldownTarget,
type StatementHeader,
type StatementLine,
StatementTable,
} from "@/components/ledger/statement-table";
export interface ProfitAndLossProps {
className?: string;
/** Offer the period columns to hide. See `StatementTable`. */
columnManager?: boolean;
header: Omit<StatementHeader, "statement">;
/** Margin rows are Percent, not Money, and visually distinguished. */
margins?: StatementLine[];
materiality?: { absolute: number; relative: number };
/** Caps the scroller so the column headers freeze. See `StatementTable`. */
maxHeight?: number;
/** EBITDA is not a P&L line. If shown, it appears below, separated. */
nonGaap?: React.ReactNode;
onDrilldown?: (line: StatementLine, target: DrilldownTarget) => void;
periods: string[];
/** Revenue → COGS → Gross profit → Opex → Operating income → Other → Net income. */
sections: StatementLine[];
showVariance?: boolean;
}
/**
* Expense rows are `polarity="inverted"` — an increase in COGS is not good
* news, and defaulting it to green is the bug this whole system exists to
* prevent. The polarity is read from the account type, not chosen per call.
*/
export function ProfitAndLoss({
header,
periods,
sections,
margins = [],
showVariance = true,
materiality,
onDrilldown,
nonGaap,
maxHeight,
columnManager,
className,
}: ProfitAndLossProps) {
const lines = React.useMemo(
() => [...sections, ...(margins.length ? [MARGIN_SECTION, ...margins] : [])],
[sections, margins],
);
return (
<div className={cn("w-full", className)}>
<StatementTable
columnManager={columnManager}
header={{ ...header, statement: "Profit and loss" }}
lines={lines}
materiality={materiality}
maxHeight={maxHeight}
onDrilldown={onDrilldown}
periods={periods}
roundingNote="Figures are rounded once, at the display boundary. Parts may not sum."
showVariance={showVariance}
/>
{nonGaap ? (
// Non-GAAP measures appear below net income, in a separated block,
// never inside the P&L.
<section className="mt-6 rounded-xl border border-dashed border-border bg-surface-sunken p-6">
<h3 className="text-title-sm font-medium">Non-GAAP measures</h3>
<p className="mb-4 text-caption text-text-secondary">
Not defined by the framework. Every adjustment is named below.
</p>
{nonGaap}
</section>
) : null}
</div>
);
}
const MARGIN_SECTION: StatementLine = {
id: "margins",
label: "Margins",
level: 1,
values: [],
variant: "section",
};
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.
- Cost of revenueThe direct costs of producing the goods or delivering the services sold in the period — the line gross profit is measured after
- Gross profitNet revenue less cost of revenue, as an amount
- Net incomeRevenues and gains less expenses and losses, including income tax, for the period — the bottom line of the P&L, before any allocation to non-controlling interests
- Operating incomeGross profit less operating expenses — the result of the core business before interest, other income and tax
- P&LPerformance over a period
- PeriodA fiscal reporting window
Also in Statements
- StatementTableThe shared shell: hierarchy, periods, rules.
- StatementRowIndent level, subtotal, total, expand.
- 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.
- TrialBalanceAll accounts with the debit=credit proof.
- 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
- Cost of revenueThe direct costs of producing the goods or delivering the services sold in the period — the line gross profit is measured afterTerm
Elsewhere in the system
Where ProfitAndLoss 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.
- ProfitAndLoss, runningThe statements showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- 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.