Skip to content

BalanceCard

The hero: one trusted number.
Implemented
Status
Implemented
Family
2 of 13
Registry
@lopifi/balance-card
npx shadcn@latest add @lopifi/theme @lopifi/balance-card

The component, rendering

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

Preview

The four-layer spec

The hero. One trusted number. This is the component a user opens the product to see.

Layer 1: radius 24 · inset 24 · min-width 280 · height auto Layer 2:

┌─ 24 ────────────────────────────────┐
│  [eyebrow]  ·  [account mark]        │  ← row, space-between
│   8                                  │
│  [figure]                            │
│   8                                  │
│  [delta]  ·  [as-of]                 │
│  16                                  │
│  ├─ full-bleed sparkline ──────────┤ │  ← optional, bleeds to 3 edges
└──────────────────────────────────────┘

Layer 3: eyebrow (1 line, truncate) · figure (never truncates) · delta (1 line) · media (aspect-[4/1], full-bleed) · actions (max 2) Layer 4:

Slot Token Weight Color
eyebrow label 13/16 500 --text-secondary
figure figure-hero 40/48 500 --text-primary
delta caption 12/16 400 semantic

3 sizes, 2 weights ✓

Available vs. current. A bank balance has two values and they differ. Show available as the figure; current as a secondary line when they diverge. Conflating them is the most consequential copy error in consumer banking UI.

Motion: none at rest. Value flash when live. Sparkline draws once. Interactive variant gets press scale(0.97) and a 1px hover lift.

Responsive: figure steps 40 → 28 below a 280px container. Sparkline drops below 240px.

Edge cases: negative balance (overdraft — parens and a --negative figure, plus an explicit "Overdrawn" pill) · redacted · stale (dim to 0.7 + StaleIndicator) · very long account name.

Lifted verbatim from Cards. 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-card.tsx

Lopifi dependencies · 19
as-ofcardcndeltaentity-markfigurefiscal-periodformat-moneyiconsmoneymoney.typespercentsparklinestale-indicatorstatus-pilltooltipuse-live-valueuse-media-queryuse-shared-now
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/balance-card.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-card.tsx
"use client";

import * as React from "react";
import { useValueFlash } from "@/hooks/ledger/use-live-value";
import { cn } from "@/lib/ledger/cn";
import { isNegative } from "@/lib/ledger/format-money";
import type { MoneyValue, PercentChange, Polarity } from "@/lib/ledger/money.types";
import { AsOf } from "@/components/ledger/as-of";
import { Card } from "@/components/ledger/card";
import { Delta } from "@/components/ledger/delta";
import { EntityMark } from "@/components/ledger/entity-mark";
import { Figure } from "@/components/ledger/figure";
import { Sparkline } from "@/components/ledger/sparkline";
import { StaleIndicator } from "@/components/ledger/stale-indicator";
import { StatusPill } from "@/components/ledger/status-pill";

export interface BalanceCardProps extends React.ComponentPropsWithoutRef<"div"> {
  actions?: React.ReactNode;
  asOf?: Date;
  /**
   * A bank balance has two values and they differ. `available` is the figure;
   * `current` is a secondary line, shown only when they diverge. Conflating
   * them is the most consequential copy error in consumer banking UI.
   */
  available: MoneyValue | null;
  basis?: string;
  current?: MoneyValue | null;
  data?: number[];
  delta?: MoneyValue | null;
  eyebrow: string;
  institution?: string;
  institutionSrc?: string;
  live?: boolean;
  percent?: PercentChange;
  polarity?: Polarity;
  redacted?: boolean;
  stale?: { lastSynced: Date; onRetry?: () => void };
  timeZone?: string;
}

/**
 * The hero. One trusted number — the component a user opens the product
 * to see.
 *
 * 3 sizes, 2 weights: eyebrow (label/500), figure (hero/500), delta
 * (caption/400). The as-of and any secondary line reuse caption/400, which
 * is a fourth slot at the same rank rather than a fourth rank.
 */
export const BalanceCard = React.forwardRef<HTMLDivElement, BalanceCardProps>(
  (
    {
      className,
      eyebrow,
      available,
      current,
      delta,
      percent,
      polarity = "standard",
      basis,
      asOf,
      timeZone,
      data,
      institution,
      institutionSrc,
      redacted = false,
      stale,
      live = false,
      actions,
      ...props
    },
    ref,
  ) => {
    const amount = available
      ? typeof available.amount === "bigint"
        ? Number(available.amount)
        : available.amount
      : null;
    const { flash, key } = useValueFlash(live ? amount : undefined);
    const overdrawn = available != null && isNegative(available);

    const diverges =
      current != null && available != null && Number(current.amount) !== Number(available.amount);

    return (
      <Card
        className={cn("min-w-[280px] overflow-hidden", className)}
        ref={ref}
        stale={Boolean(stale)}
        {...props}
      >
        {/* The eyebrow row carries the account's *state*. An overdrawn pill is a
            fact about the account, not about the change, and putting it down in
            the delta row was what made that row read as a run-on sentence. */}
        <div className="flex items-start justify-between gap-3">
          <span className="flex min-w-0 items-center gap-2">
            <span className="truncate text-label font-medium text-text-secondary">{eyebrow}</span>
            {overdrawn ? <StatusPill entity="Account" status="overdue" /> : null}
          </span>
          {institution ? (
            <EntityMark category="bank" name={institution} size={24} src={institutionSrc} />
          ) : null}
        </div>

        <div
          aria-live={live ? "polite" : undefined}
          className={cn(
            "mt-2 -mx-1 rounded-xs px-1",
            flash === "positive" && "ledger-flash-positive",
            flash === "negative" && "ledger-flash-negative",
          )}
          key={key}
        >
          <Figure colorBySign={overdrawn} redacted={redacted} size="hero" value={available} />
        </div>

        {diverges ? (
          <p className="mt-1 text-caption text-text-secondary">
            Current <span className="numeric">{formatSecondary(current)}</span>
          </p>
        ) : null}

        {/* Change on the left, freshness on the right — two facts at opposite
            ends rather than four clauses in a row. The comparison basis rides
            with the delta as a tooltip, because it is a restatement of a date
            the delta already implies, not a fact the reader has to be told. */}
        <div className="mt-2 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
          {delta !== undefined ? (
            <Delta basisTooltip={basis} percent={percent} polarity={polarity} size="xs" value={delta} />
          ) : (
            <span />
          )}
          {asOf ? <AsOf className="shrink-0" compact date={asOf} timeZone={timeZone} /> : null}
        </div>

        {stale ? (
          <div className="mt-3">
            <StaleIndicator lastSynced={stale.lastSynced} onRetry={stale.onRetry} />
          </div>
        ) : null}

        {actions ? <div className="mt-4 flex gap-2">{actions}</div> : null}

        {data ? (
          // Full-bleed to three edges.
          <div className="-mx-6 -mb-6 mt-4 aspect-[4/1] overflow-hidden">
            <Sparkline className="h-full" data={data} height={64} polarity={polarity} showEndpoint={false} />
          </div>
        ) : null}
      </Card>
    );
  },
);
BalanceCard.displayName = "BalanceCard";

function formatSecondary(value: MoneyValue | null | undefined) {
  if (!value) return "n/a";
  return new Intl.NumberFormat("en-US", {
    currency: value.currency,
    currencyDisplay: "narrowSymbol",
    currencySign: "accounting",
    style: "currency",
  }).format(Number(value.amount) / 10 ** (value.scale ?? 2));
}

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 Cards

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