VarianceCell
- Status
- Implemented
- Family
- 6 of 13
- Registry
- @lopifi/variance-cell
npx shadcn@latest add @lopifi/theme @lopifi/variance-cellThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Absolute change + percent change + significance. Significance is a threshold on both magnitude and materiality (a 200% swing on $12 isn't news), and the threshold is configurable because materiality is a business judgment.
Respects polarity. Division by zero → n/a, never Infinity.
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/variance-cell.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/variance-cell.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
import { cn } from "@/lib/ledger/cn";
import { safeRelativeChange } from "@/lib/ledger/format-money";
import type { Polarity } from "@/lib/ledger/money.types";
import { Money } from "@/components/ledger/money";
import { Percent } from "@/components/ledger/percent";
import { Tooltip } from "@/components/ledger/tooltip";
export interface VarianceCellProps {
currency: string;
current: number | null;
hidden?: boolean;
/**
* Both thresholds must be exceeded for a variance to flag. A 200% swing on
* $12 isn't news, and $40,000 on $8M isn't either.
*/
materiality?: { absolute: number; relative: number };
polarity?: Polarity;
prior: number | null;
}
/**
* Absolute change and percent change together — either alone misleads.
* Division by zero renders `n/a`, never Infinity.
*/
export function VarianceCell({
current,
prior,
currency,
polarity = "standard",
materiality,
hidden = false,
}: VarianceCellProps) {
if (hidden || current === null || prior === null) {
return (
<>
<td className="px-3 py-3" />
<td className="px-6 py-3" />
</>
);
}
const absolute = current - prior;
const relative = safeRelativeChange(current, prior);
const material =
materiality != null &&
Math.abs(absolute) >= materiality.absolute &&
relative != null &&
Math.abs(relative.value) >= materiality.relative;
const up = absolute > 0;
const tone =
polarity === "neutral"
? "text-text-secondary"
: absolute === 0
? "text-text-secondary"
: (polarity === "standard") === up
? "text-positive"
: "text-negative";
return (
<>
<td className={cn("px-3 py-3 text-right", tone)}>
<span className="inline-flex items-baseline gap-1">
{material ? (
<Tooltip content="Exceeds both the absolute and relative materiality thresholds">
<span aria-label="material variance" className="text-[0.85em] leading-none" role="img">
▸
</span>
</Tooltip>
) : null}
<Money accounting tone="inherit" value={{ amount: absolute, currency }} />
</span>
</td>
<td className={cn("px-6 py-3 text-right", tone)}>
<Percent className="text-inherit" value={relative} />
</td>
</>
);
}
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
- 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.
- 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
- MaterialityWhether a misstatement or omission would likely change the judgment of a reasonable user of the statements — judged on size and nature together, never a fixed percentageTerm
Elsewhere in the system
Where VarianceCell 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.
- VarianceCell, runningThe statements showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Difference diagnoserOut by 8,100? That is divisible by 9 — a transposition. This says which error fits the gap.Tool
- 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.