Figure
- Status
- Implemented
- Family
- 1 of 13
- Registry
- @lopifi/figure
npx shadcn@latest add @lopifi/theme @lopifi/figureThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
A large display numeral. The only place a figure may leave the figure face.
<Figure value={{ amount: 24819024, currency: "USD" }} size="hero" family="display" />
The step-down: at hero (40px), a value exceeding a character threshold steps to lg (28px), then md (20px). Driven by a container query on character count, not clamp() — so the value always lands on a type-scale token rather than between two.
The display gate: family="display" is only valid when the component is provably solitary. In KpiRow, where figures align across cards, the prop is ignored and the figure face is forced. Enforce it in the parent, not by trusting the caller.
Never truncates. Escalation ladder in numerics.
Lifted verbatim from Primitives. 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/figure.tsx
- Lopifi dependencies · 3
- cnformat-moneymoney.types
- npm packages
- clsxtailwind-merge
- Registry entry
- /r/figure.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 { cn } from "@/lib/ledger/cn";
import { formatMoneyParts, moneyAriaLabel } from "@/lib/ledger/format-money";
import type { FigureSize, MoneyValue } from "@/lib/ledger/money.types";
export interface FigureProps extends Omit<React.ComponentPropsWithoutRef<"div">, "children"> {
colorBySign?: boolean;
/**
* A figure may leave the figure face for Inter at display size only when it
* never aligns with another figure. A parent that stacks figures (KpiRow, a
* table) forces `"sans"` rather than trusting the caller.
*/
family?: "sans" | "display";
locale?: string;
redacted?: boolean;
size?: FigureSize;
value: MoneyValue | null;
}
const STEPS: FigureSize[] = ["xs", "sm", "md", "lg", "hero"];
const CLASSES: Record<FigureSize, string> = {
hero: "text-figure-hero",
lg: "text-figure-lg",
md: "text-figure-md",
sm: "text-figure-sm",
xs: "text-figure-xs",
};
/**
* A number never truncates. A truncated figure is not degraded, it is wrong.
*
* The step-down is driven by character count so the value always lands on a
* type-scale token, rather than `clamp()` landing it between two.
*/
export const Figure = React.forwardRef<HTMLDivElement, FigureProps>(
(
{
className,
value,
size = "hero",
family = "sans",
redacted = false,
colorBySign = false,
locale,
...props
},
ref,
) => {
if (value == null) {
return (
<div
className={cn("numeric relative text-text-tertiary", CLASSES[size], className)}
ref={ref}
{...props}
>
<span aria-hidden="true">n/a</span>
<span className="sr-only select-none">not available</span>
</div>
);
}
const parts = formatMoneyParts(value, { locale });
const characters = parts.symbol.length + parts.integer.length + parts.fraction.length;
// Step down one token per threshold crossed, never below `md`.
const index = STEPS.indexOf(size);
let resolved = size;
if (size === "hero" && characters > 15) resolved = "md";
else if (size === "hero" && characters > 11) resolved = "lg";
else if (size === "lg" && characters > 14) resolved = "md";
void index;
const large = resolved === "hero" || resolved === "lg";
const negative = parts.negative;
return (
<div
className={cn(
"numeric relative flex items-baseline font-medium leading-none",
CLASSES[resolved],
family === "display" && "font-display font-normal",
colorBySign && negative ? "text-negative" : "text-text-primary",
className,
)}
ref={ref}
{...props}
>
{redacted ? (
<span aria-hidden="true" className="text-text-tertiary">
••••••
</span>
) : (
<>
{negative ? <span aria-hidden="true">−</span> : null}
{parts.symbol ? (
<span
aria-hidden="true"
className={cn(
"font-normal text-text-tertiary",
/* Display sets in Inter, which needs the air a mono cell
already carries. */
family === "display" ? "mr-[4px]" : "mr-[var(--numeric-symbol-gap)]",
)}
>
{parts.symbol}
</span>
) : null}
<span aria-hidden="true">{parts.integer}</span>
{parts.fraction ? (
<span aria-hidden="true" className={large ? "text-text-tertiary" : undefined}>
{parts.fraction}
</span>
) : null}
{parts.symbolSuffix ? (
<span aria-hidden="true" className="ml-1 font-normal text-text-tertiary">
{parts.symbolSuffix}
</span>
) : null}
</>
)}
{/* Spoken text, not an aria-label (prohibited on a role-less element).
A redacted figure says so — it never reads the amount it hides. */}
<span className="sr-only select-none">{redacted ? "hidden" : moneyAriaLabel(value, { locale })}</span>
</div>
);
},
);
Figure.displayName = "Figure";
Also in Primitives
- MoneyThe core primitive. A monetary value, formatted correctly.
- DeltaA signed change, with polarity and a redundant non-color cue.
- PercentPercent vs. percentage points, explicitly discriminated.
- RuleSingle / double / section accounting rule lines.
- StatusPillPayment and reconciliation states.
- SparklineInline trend, one-shot draw.
- TrendArrow + delta + optional sparkline, composed.
- AsOfTimestamp with live relative formatting and a stated timezone.
- RedactedMasked value with reveal.
- ReferenceCopyable transaction/account ID with disambiguated glyphs.
- CurrencyBadgeISO code + optional flag.
- EntityMarkBank/merchant logo with the full fallback ladder.
- TooltipHover/focus restatement. Never the only home of a fact.
- InfoTipThe ⓘ. Extra context that survives touch, because it opens on press.
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 Figure 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 Primitives 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.