Skip to content

InvoiceCard

Invoice summary with aging state.
Implemented
Status
Implemented
Family
2 of 13
Registry
@lopifi/invoice-card
npx shadcn@latest add @lopifi/theme @lopifi/invoice-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

Number, customer, amount, due date, aging state (current / 1-30 / 31-60 / 61-90 / 90+). Overdue is --negative with the day count, never color alone. Partial payments show paid vs. outstanding.

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/invoice-card.tsx

Lopifi dependencies · 11
cardcnfiscal-periodformat-moneyiconsmoneymoney.typesreferencerulestatus-pilltooltip
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/invoice-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/invoice-card.tsx
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import { daysBetween, formatDate } from "@/lib/ledger/fiscal-period";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { Card } from "@/components/ledger/card";
import { Money } from "@/components/ledger/money";
import { Reference } from "@/components/ledger/reference";
import { Rule } from "@/components/ledger/rule";
import { StatusPill } from "@/components/ledger/status-pill";

export type AgingBucket = "current" | "1-30" | "31-60" | "61-90" | "90+";

export function bucketFor(dueDate: Date, today: Date): AgingBucket {
  const overdue = daysBetween(dueDate, today);
  if (overdue <= 0) return "current";
  if (overdue <= 30) return "1-30";
  if (overdue <= 60) return "31-60";
  if (overdue <= 90) return "61-90";
  return "90+";
}

export interface InvoiceCardProps extends React.ComponentPropsWithoutRef<"div"> {
  customer: string;
  dueDate: Date;
  number: string;
  outstanding: MoneyValue;
  paid?: MoneyValue;
  today?: Date;
  total: MoneyValue;
}

/** Overdue is `--negative` with the day count, never colour alone. */
export const InvoiceCard = React.forwardRef<HTMLDivElement, InvoiceCardProps>(
  ({ className, number, customer, total, paid, outstanding, dueDate, today = new Date(), ...props }, ref) => {
    const overdueDays = daysBetween(dueDate, today);
    const bucket = bucketFor(dueDate, today);
    const partial = paid != null && Number(paid.amount) > 0;

    return (
      <Card className={cn("flex flex-col gap-3", className)} ref={ref} {...props}>
        <div className="flex items-start justify-between gap-3">
          <div className="min-w-0">
            <p className="truncate text-body font-medium">{customer}</p>
            <Reference truncate={false} value={number} />
          </div>
          <StatusPill entity="Invoice" status={bucket === "current" ? "pending" : "overdue"} />
        </div>

        <div className="space-y-1">
          <Row label="Invoice total" value={total} />
          {partial ? <Row label="Paid" tone="secondary" value={paid} /> : null}
        </div>

        <div>
          <Rule className="ml-auto w-[45%]" variant="subtotal" />
          <div className="flex items-baseline justify-between pt-1">
            <span className="text-label font-medium">Outstanding</span>
            <Money accounting size="md" value={outstanding} />
          </div>
        </div>

        <p className={cn("text-caption", bucket === "current" ? "text-text-secondary" : "text-negative")}>
          {bucket === "current"
            ? `Due ${formatDate(dueDate)}`
            : `${overdueDays} days overdue · due ${formatDate(dueDate)}`}
        </p>
      </Card>
    );
  },
);
InvoiceCard.displayName = "InvoiceCard";

function Row({
  label,
  value,
  tone = "primary",
}: {
  label: string;
  value: MoneyValue;
  tone?: "primary" | "secondary";
}) {
  return (
    <div className="flex items-baseline justify-between gap-4">
      <span className="text-body text-text-secondary">{label}</span>
      <Money accounting tone={tone} value={value} />
    </div>
  );
}

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