dentil

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-table
On this page
DescriptionQtyUnit priceTax rateAmount
Pro plan
Dec 1 – 31, 2026
12$20.0010%$240.00
Pro plan, added seat
Dec 15 – 31, 2026 · 17 of 31 days of $20.00
1$20.0010%$10.97
API requests
Nov 15 – Dec 14, 2026
1,200,000$0.000510%$600.00
Onboarding session
1$500.000%$500.00
Subtotal$1,350.97
Tax (10% on $850.97)$85.10
Total$1,436.07
Amount due$1,436.07

Installation

pnpm dlx shadcn@latest add @dentil/invoice-table
npx shadcn@latest add @dentil/invoice-table
yarn dlx shadcn@latest add @dentil/invoice-table
bunx --bun shadcn@latest add @dentil/invoice-table

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

DescriptionQtyUnit priceAmount
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

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.

DescriptionTax rateAmount
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

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.

DescriptionTaxAmountRemainingCredit
Team plan
Dec 1 – 31, 2026
$100.00$1,000.00$1,100.00
$
USD
Priority support
$20.00$200.00$0.00
$
USD
Additional storage (500 GB)
$9.00$90.00$59.00
$
USD
Credit note total$100.00
Result: {"plan":10000} (max $150.00 in total)
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

PropTypeDefaultDescription
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.
currencystring—ISO 4217 code, e.g. USD. Sets the symbol and decimal places.
localestring'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.
timezonestring'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.
totalsInvoiceTotal[]—Footer rows, in display order. The table doesn’t add anything up, so pass the numbers from your API.
allocationInvoiceAllocation<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.
loadingbooleanfalseReplaces the rows with a spinner and hides the totals.
emptyReactNode'No items'Shown when lines is empty. The totals are hidden too.
…propsComponentProps<'table'>—Other props (className, aria-label…) are passed to the table.

InvoiceLine

PropTypeDefaultDescription
idstring—Stable identity for the row, and the key in allocation values.
descriptionReactNode—The line. Wraps onto more lines when long.
metaReactNode—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.
prorationInvoiceProration—Adds how the amount relates to the full price, such as "17 of 31 days of $20.00", after the period.
quantitynumber—Shown in the Qty column.
unitAmountnumber | 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.
taxRatenumber—Percent, e.g. 10 for 10%.
taxnumber—Tax in minor units.
amountnumber—Line amount in minor units.
originalAmountnumber—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

PropTypeDefaultDescription
fullAmountnumber—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".
labelReactNode—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.

PropTypeDefaultDescription
idstring—React key for the heading row.
descriptionReactNode—The heading, such as "Pro → Business". Shown in medium weight.
metaReactNode—Beside the heading: a badge, a link or a note.
detailReactNode—Muted line under the heading, e.g. "Upgraded Dec 15, 2026".
linesTLine[]—Lines indented under the heading. They render like any other line, allocation inputs included.
amountnumber—Net of the lines in minor units, shown on the heading row. Omit it to leave the cell blank.

InvoiceTotal

PropTypeDefaultDescription
idstring—React key. Defaults to the row index.
labelReactNode—Right-aligned beside the amount, or left-aligned for an entry.
amountnumber—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.
gapbooleanfalseAdds space above, to start a group.
classNamestring—Applied to the amount cell, e.g. line-through for a void payment.

InvoiceAllocation

PropTypeDefaultDescription
labelstring'Amount'Header of the input column.
valuesRecord<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.
showRemainingbooleantrueShows each line's max in a Remaining column.
disabledbooleanfalseDisables every input.
invalidbooleanfalseSets 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.

PropTypeDefaultDescription
amountnumber | string—Amount in minor units. A decimal string shows every fraction digit it has.
currencystring—ISO 4217 code.
localestring'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.

PropTypeDefaultDescription
periodInvoicePeriod—The start and end dates.
localestring'en-US'Locale for the month names and order.
timezonestring'UTC'IANA time zone the dates are shown in.