Invoice Table
InvoiceTable renders an invoice's line items with a totals footer. It doesn't fetch or calculate anything: you pass lines and totals in minor units. Click Reload to see the loading state.
@dentil/invoice-tableOn this page
| Description | Qty | Unit price | Tax rate | Amount |
|---|---|---|---|---|
Pro plan Dec 1 – 31, 2026 | 12 | $20.00 | 10% | $240.00 |
Pro plan, added seat Dec 15 – 31, 2026 · 17 of 31 days of $20.00 | 1 | $20.00 | 10% | $10.97 |
API requests Nov 15 – Dec 14, 2026 | 1,200,000 | $0.0005 | 10% | $600.00 |
Onboarding session | 1 | $500.00 | 0% | $500.00 |
| Subtotal | $1,350.97 | |||
| Tax (10% on $850.97) | $85.10 | |||
| Total | $1,436.07 | |||
| Amount due | $1,436.07 | |||
'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { type InvoiceLine, InvoiceTable, formatInvoiceAmount } from '@/components/dentil/invoice-table/invoice-table';
const lines: InvoiceLine[] = [
{
id: 'seats',
description: 'Pro plan',
period: { start: '2026-12-01', end: '2026-12-31' },
quantity: 12,
unitAmount: 2000,
taxRate: 10,
amount: 24000,
},
{
id: 'seat-added',
description: 'Pro plan, added seat',
period: { start: '2026-12-15', end: '2026-12-31' },
proration: { fullAmount: 2000, days: { used: 17, total: 31 } },
quantity: 1,
unitAmount: 2000,
taxRate: 10,
amount: 1097,
},
{
id: 'api',
description: 'API requests',
period: { start: '2026-11-15', end: '2026-12-14' },
quantity: 1200000,
unitAmount: '0.05',
taxRate: 10,
amount: 60000,
},
{
id: 'onboarding',
description: 'Onboarding session',
quantity: 1,
unitAmount: 50000,
taxRate: 0,
amount: 50000,
},
];
const subtotal = lines.reduce((sum, line) => sum + line.amount, 0);
const taxable = lines.filter((line) => line.taxRate === 10).reduce((sum, line) => sum + line.amount, 0);
const tax = Math.round(taxable * 0.1);
export function InvoiceTableOverviewDemo() {
const [loading, setLoading] = useState(false);
const reload = async () => {
setLoading(true);
await new Promise((resolve) => setTimeout(resolve, 800));
setLoading(false);
};
return (
<div className="flex w-full flex-col gap-4">
<InvoiceTable
currency="USD"
lines={lines}
loading={loading}
totals={[
{ label: 'Subtotal', amount: subtotal },
{ label: `Tax (10% on ${formatInvoiceAmount(taxable, 'USD')})`, amount: tax },
{ label: 'Total', amount: subtotal + tax },
{ label: 'Amount due', amount: subtotal + tax, variant: 'strong' },
]}
/>
<Button variant="outline" size="sm" className="self-start" onClick={reload} disabled={loading}>
Reload
</Button>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/invoice-tablenpx shadcn@latest add @dentil/invoice-tableyarn dlx shadcn@latest add @dentil/invoice-tablebunx --bun shadcn@latest add @dentil/invoice-tableFiles land in components/dentil/invoice-table/. Uses the stock shadcn table, and @dentil/currency-input for the allocation inputs and currency formatting.
Usage
import { InvoiceTable } from '@/components/dentil/invoice-table/invoice-table';
<InvoiceTable
currency="USD"
lines={invoice.items.map((item) => ({
id: item.id,
description: item.description,
period: item.period, // { start, end } as unix seconds, ISO strings or Dates
quantity: item.quantity,
unitAmount: item.unit_amount,
taxRate: item.tax_percent,
amount: item.amount,
}))}
totals={[
{ label: 'Subtotal', amount: invoice.subtotal },
{ label: 'Tax', amount: invoice.tax },
{ label: 'Amount due', amount: invoice.amount_due, variant: 'strong' },
]}
/>Map your API's invoice onto InvoiceLine and InvoiceTotal. The Qty, Unit price, Tax rate and Tax columns show when any line has a value for them, or pass columns to choose. Use formatInvoiceAmount(amount, currency) for amounts inside labels, such as "Tax (10% on $851.00)".
For prices below one cent, pass unitAmount as a decimal string in minor units, such as Stripe's unit_amount_decimal. The API requests line above uses '0.05', which shows as $0.0005. A string is never rounded to the currency's decimal places.
period adds a muted line under the description. Parts the two dates share are written once, so a month reads "Dec 1 – 31, 2026" and a period across the new year reads "Dec 15, 2026 – Jan 14, 2027". Dates are shown in UTC unless you pass timezone.
For a prorated line, pass proration with the full price and, if you have them, the days covered. The added seat above reads "17 of 31 days of $20.00" after its period, so the amount explains itself. Keep originalAmount for discounts: a struck-through price reads as a sale.
Examples
Plan changes and proration
A group puts the credit for unused time and the charge for remaining time under one heading, with the net beside it. Switch to Downgrade to see a negative net credited to the balance.
| Description | Qty | Unit price | Amount |
|---|---|---|---|
Pro → Business Upgraded Dec 15, 2026 | $16.45 | ||
Unused time on Pro Dec 15 – 31, 2026 · 17 of 31 days of $20.00 | 1 | $20.00 | -$10.97 |
Remaining time on Business Dec 15 – 31, 2026 · 17 of 31 days of $50.00 | 1 | $50.00 | $27.42 |
Business plan Jan 1 – 31, 2027 | 1 | $50.00 | $50.00 |
| Subtotal | $66.45 | ||
| Amount due | $66.45 | ||
'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import {
type InvoiceLine,
type InvoiceLineGroup,
type InvoiceTotal,
InvoiceTable,
} from '@/components/dentil/invoice-table/invoice-table';
const changePeriod = { start: '2026-12-15', end: '2026-12-31' };
const days = { used: 17, total: 31 };
const invoices: Record<'upgrade' | 'downgrade', { lines: (InvoiceLine | InvoiceLineGroup)[]; totals: InvoiceTotal[] }> =
{
upgrade: {
lines: [
{
id: 'change',
description: 'Pro → Business',
detail: 'Upgraded Dec 15, 2026',
amount: 1645,
lines: [
{
id: 'unused-pro',
description: 'Unused time on Pro',
period: changePeriod,
proration: { fullAmount: 2000, days },
quantity: 1,
unitAmount: 2000,
amount: -1097,
},
{
id: 'remaining-business',
description: 'Remaining time on Business',
period: changePeriod,
proration: { fullAmount: 5000, days },
quantity: 1,
unitAmount: 5000,
amount: 2742,
},
],
},
{
id: 'business',
description: 'Business plan',
period: { start: '2027-01-01', end: '2027-01-31' },
quantity: 1,
unitAmount: 5000,
amount: 5000,
},
],
totals: [
{ label: 'Subtotal', amount: 6645 },
{ label: 'Amount due', amount: 6645, variant: 'strong' },
],
},
downgrade: {
lines: [
{
id: 'change',
description: 'Business → Pro',
detail: 'Downgraded Dec 15, 2026',
amount: -1645,
lines: [
{
id: 'unused-business',
description: 'Unused time on Business',
period: changePeriod,
proration: { fullAmount: 5000, days },
quantity: 1,
unitAmount: 5000,
amount: -2742,
},
{
id: 'remaining-pro',
description: 'Remaining time on Pro',
period: changePeriod,
proration: { fullAmount: 2000, days },
quantity: 1,
unitAmount: 2000,
amount: 1097,
},
],
},
],
totals: [
{ label: 'Subtotal', amount: -1645 },
{ label: 'Credit to balance', amount: 1645 },
{ label: 'Amount due', amount: 0, variant: 'strong' },
],
},
};
export function InvoiceTablePlanChangeDemo() {
const [change, setChange] = useState<keyof typeof invoices>('upgrade');
return (
<div className="flex w-full flex-col gap-4">
<div className="flex gap-2">
{(['upgrade', 'downgrade'] as const).map((value) => (
<Button
key={value}
variant="outline"
size="sm"
className="aria-pressed:bg-accent aria-pressed:text-accent-foreground dark:aria-pressed:bg-accent capitalize"
aria-pressed={change === value}
onClick={() => setChange(value)}>
{value}
</Button>
))}
</div>
<InvoiceTable currency="USD" lines={invoices[change].lines} totals={invoices[change].totals} />
</div>
);
}Credit notes and payments
Entry rows put a credit note or part payment on the left. gap starts each group, and className strikes through the void payment.
| Description | Tax rate | Amount |
|---|---|---|
Team plan Dec 1 – 31, 2026 | 10% | $1,000.00 |
Priority support | 10% | $200.00 |
| Subtotal | $1,200.00 | |
| Tax (10% on $1,200.00) | $120.00 | |
| Total | $1,320.00 | |
| CN-0012 · Service outage credit | -$120.00 | |
| Adjustment total | -$120.00 | |
| Adjusted total | $1,200.00 | |
| PP-0003 · Paid | $500.00 | |
| PP-0004 · Void | $300.00 | |
| Amount paid | -$500.00 | |
| Amount due | $700.00 | |
'use client';
import { InvoiceTable } from '@/components/dentil/invoice-table/invoice-table';
export function InvoiceTableAdjustmentsDemo() {
return (
<InvoiceTable
className="w-full"
currency="USD"
lines={[
{
id: 'plan',
description: 'Team plan',
period: { start: '2026-12-01', end: '2026-12-31' },
taxRate: 10,
amount: 100000,
},
{ id: 'support', description: 'Priority support', taxRate: 10, amount: 20000 },
]}
totals={[
{ label: 'Subtotal', amount: 120000 },
{ label: 'Tax (10% on $1,200.00)', amount: 12000 },
{ label: 'Total', amount: 132000 },
{
id: 'cn-0012',
variant: 'entry',
gap: true,
label: (
<>
<span className="font-mono">CN-0012</span> · Service outage credit
</>
),
amount: -12000,
},
{ label: 'Adjustment total', amount: -12000, gap: true },
{ label: 'Adjusted total', amount: 120000 },
{
id: 'pp-0003',
variant: 'entry',
gap: true,
label: (
<>
<span className="font-mono">PP-0003</span> · Paid
</>
),
amount: 50000,
},
{
id: 'pp-0004',
variant: 'entry',
label: (
<>
<span className="font-mono">PP-0004</span> · Void
</>
),
amount: 30000,
className: 'line-through',
},
{ label: 'Amount paid', amount: -50000, gap: true },
{ label: 'Amount due', amount: 70000, variant: 'strong' },
]}
/>
);
}Allocation
Pass allocation to split an amount across lines, for a credit note or a part payment. Each line gets an input capped at max(line), and a line with nothing left gets a disabled one. Allocate more than $150.00 in total to see the inputs marked invalid.
| Description | Tax | Amount | Remaining | Credit |
|---|---|---|---|---|
Team plan Dec 1 – 31, 2026 | $100.00 | $1,000.00 | $1,100.00 | |
Priority support | $20.00 | $200.00 | $0.00 | |
Additional storage (500 GB) | $9.00 | $90.00 | $59.00 | |
| Credit note total | $100.00 | |||
{"plan":10000} (max $150.00 in total)'use client';
import { useState } from 'react';
import { type InvoiceLine, InvoiceTable, formatInvoiceAmount } from '@/components/dentil/invoice-table/invoice-table';
type CreditableLine = InvoiceLine & { credited: number };
const lines: CreditableLine[] = [
{
id: 'plan',
description: 'Team plan',
period: { start: '2026-12-01', end: '2026-12-31' },
tax: 10000,
amount: 100000,
credited: 0,
},
{ id: 'support', description: 'Priority support', tax: 2000, amount: 20000, credited: 22000 },
{ id: 'storage', description: 'Additional storage (500 GB)', tax: 900, amount: 9000, credited: 4000 },
];
const cap = 15000;
export function InvoiceTableAllocationDemo() {
const [values, setValues] = useState<Record<string, number | undefined>>({ plan: 10000 });
const allocated = Object.values(values).reduce<number>((sum, value) => sum + (value ?? 0), 0);
return (
<div className="flex w-full flex-col gap-4">
<InvoiceTable
currency="USD"
lines={lines}
verticalAlign="middle"
allocation={{
label: 'Credit',
values,
onChange: setValues,
max: (line) => line.amount + (line.tax ?? 0) - line.credited,
invalid: allocated > cap,
}}
totals={[{ label: 'Credit note total', amount: allocated, variant: 'strong' }]}
/>
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{JSON.stringify(values)}</code> (max {formatInvoiceAmount(cap, 'USD')}{' '}
in total)
</span>
</div>
);
}const [values, setValues] = useState<Record<string, number | undefined>>({});
<InvoiceTable
currency={invoice.currency}
lines={lines} // InvoiceLine plus any fields you need, e.g. credited
allocation={{
label: 'Credit',
values,
onChange: setValues,
max: (line) => line.amount + (line.tax ?? 0) - line.credited,
}}
/>
// Send it as an array if your API wants one.
const items = Object.entries(values).map(([invoice_item, amount]) => ({ invoice_item, amount: amount ?? 0 }));values is keyed by line id, so reordering lines never moves an amount to the wrong row. The inputs show the currency code, so the column is wider than the amounts beside it.
API reference
InvoiceTable
| Prop | Type | Default | Description |
|---|---|---|---|
| lines | (TLine | InvoiceLineGroup<TLine>)[] | — | Rows, in display order. TLine extends InvoiceLine, so extra fields are kept and passed back to allocation.max. A group renders a heading row with its lines indented under it. |
| currency | string | — | ISO 4217 code, e.g. USD. Sets the symbol and decimal places. |
| locale | string | 'en-US' | Locale for money, quantities, percentages and periods. It isn’t read from the browser, so server and client render the same text. Pass your user’s locale if you have it. |
| timezone | string | 'UTC' | IANA time zone that line periods are shown in. Like locale, it isn’t read from the browser. Pass your billing zone if periods start at midnight there. |
| columns | ('quantity' | 'unitAmount' | 'taxRate' | 'tax')[] | — | Optional columns to show. They always render in that order. Defaults to the ones any line has a value for. Description and Amount always show. |
| totals | InvoiceTotal[] | — | Footer rows, in display order. The table doesn’t add anything up, so pass the numbers from your API. |
| allocation | InvoiceAllocation<TLine> | — | Adds a Remaining column and an amount input per line. Totals then line up under the inputs. |
| verticalAlign | 'top' | 'middle' | 'top' | Where cells sit when a line is taller than one row of text, e.g. with a period. top keeps numbers level with the description; with allocation it lines the first row of text up with the inputs. |
| loading | boolean | false | Replaces the rows with a spinner and hides the totals. |
| empty | ReactNode | 'No items' | Shown when lines is empty. The totals are hidden too. |
| …props | ComponentProps<'table'> | — | Other props (className, aria-label…) are passed to the table. |
InvoiceLine
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | — | Stable identity for the row, and the key in allocation values. |
| description | ReactNode | — | The line. Wraps onto more lines when long. |
| meta | ReactNode | — | Beside the description: a badge, a link or a note. |
| period | { start: InvoiceDate; end: InvoiceDate } | — | Muted line under the description, such as "Dec 1 – 31, 2026". Each date is unix seconds, unix milliseconds, an ISO string or a Date. Both dates are shown as given, so pass an inclusive end if your API's is exclusive. An invalid date hides the line. |
| proration | InvoiceProration | — | Adds how the amount relates to the full price, such as "17 of 31 days of $20.00", after the period. |
| quantity | number | — | Shown in the Qty column. |
| unitAmount | number | string | — | Unit price in minor units. A decimal string such as '0.05' keeps fractions of a minor unit, like Stripe's unit_amount_decimal, and shows as $0.0005. |
| taxRate | number | — | Percent, e.g. 10 for 10%. |
| tax | number | — | Tax in minor units. |
| amount | number | — | Line amount in minor units. |
| originalAmount | number | — | Struck through before amount when the two differ, e.g. the price before a discount. For proration, use proration, which doesn't read as a discount. |
InvoiceProration
| Prop | Type | Default | Description |
|---|---|---|---|
| fullAmount | number | — | The line’s price for a whole billing period, in minor units. |
| days | { used: number; total: number } | — | Shown as "17 of 31 days of $20.00". Without it the text reads "Prorated from $20.00". |
| label | ReactNode | — | Replaces the generated text, e.g. to translate it. |
InvoiceLineGroup
Pass one in lines in place of a line. isInvoiceLineGroup(item) tells the two apart.
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | — | React key for the heading row. |
| description | ReactNode | — | The heading, such as "Pro → Business". Shown in medium weight. |
| meta | ReactNode | — | Beside the heading: a badge, a link or a note. |
| detail | ReactNode | — | Muted line under the heading, e.g. "Upgraded Dec 15, 2026". |
| lines | TLine[] | — | Lines indented under the heading. They render like any other line, allocation inputs included. |
| amount | number | — | Net of the lines in minor units, shown on the heading row. Omit it to leave the cell blank. |
InvoiceTotal
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | — | React key. Defaults to the row index. |
| label | ReactNode | — | Right-aligned beside the amount, or left-aligned for an entry. |
| amount | number | — | Amount in minor units. Pass negatives for credits and payments. |
| variant | 'muted' | 'strong' | 'entry' | 'muted' | strong is for the final amount due. entry puts the label in the description column, for a credit note or a payment. |
| gap | boolean | false | Adds space above, to start a group. |
| className | string | — | Applied to the amount cell, e.g. line-through for a void payment. |
InvoiceAllocation
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | 'Amount' | Header of the input column. |
| values | Record<string, number | undefined> | — | Allocated amount per line in minor units, keyed by line id. |
| onChange | (values: Record<string, number | undefined>) => void | — | Called with every value when one input changes. An emptied input sets its line to undefined. |
| max | (line: TLine) => number | — | Largest amount a line can take, in minor units. Input above it is clamped. At 0 or below, the input is disabled. |
| showRemaining | boolean | true | Shows each line's max in a Remaining column. |
| disabled | boolean | false | Disables every input. |
| invalid | boolean | false | Sets aria-invalid on every enabled input, e.g. when the sum is over a cap. |
formatInvoiceAmount
Formats minor units with the currency’s symbol and decimals.
| Prop | Type | Default | Description |
|---|---|---|---|
| amount | number | string | — | Amount in minor units. A decimal string shows every fraction digit it has. |
| currency | string | — | ISO 4217 code. |
| locale | string | 'en-US' | Locale for the separators and symbol. |
formatInvoicePeriod
Formats a period the way line items show it, for your own labels. Returns null when either date is invalid.
| Prop | Type | Default | Description |
|---|---|---|---|
| period | InvoicePeriod | — | The start and end dates. |
| locale | string | 'en-US' | Locale for the month names and order. |
| timezone | string | 'UTC' | IANA time zone the dates are shown in. |