InvoiceCard
- Status
- Implemented
- Family
- 2 of 13
- Registry
- @lopifi/invoice-card
npx shadcn@latest add @lopifi/theme @lopifi/invoice-cardThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
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.
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
- BalanceCardThe hero: one trusted number.
- KpiCardMetric + delta + optional sparkline.
- AccountCardBank account with available vs. current.
- PaymentMethodCardThe physical card object. 3D flip, pointer tilt.
- RunwayCardMonths of runway with a burn line.
- SubscriptionCardRecurring charge with next-billing.
- AnomalyCardA flagged deviation with its explanation.
- GoalCardTarget vs. actual with a progress rule.
- StatCardThe minimal label+value card.Spec
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Cards — the family specThe four-layer specification this component was built against, before it was written.Doc
- Balance, KPI and account cardsThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
- AgingGrouping open receivables or payables into buckets by days past due date — current, 1–30, 31–60, 61–90, 90+Term
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.
- InvoiceCard, runningThe cards showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Sales invoicesWhat does an accounts-receivable invoice look like in each API?API
- CardsAll cards: 24px radius, 24px inset, --surface on --canvas, 1px --border, no resting shadow. Specs for 10 React components: BalanceCard, KpiCard, AccountCard, PaymentMethodCard and 6 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 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.