Skip to content

VarianceCell

Absolute + percent + significance flag.
Implemented
Status
Implemented
Family
6 of 13
Registry
@lopifi/variance-cell
npx shadcn@latest add @lopifi/theme @lopifi/variance-cell

The component, rendering

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

Preview

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

Lopifi dependencies · 6
cnformat-moneymoneymoney.typespercenttooltip
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.

components/ledger/variance-cell.tsx
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

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

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.