Line Items

View as Markdown

The lines of an invoice or quote typed in place, with quantity, price and tax, and totals that follow as you type.

Invoice INV-2041

  1. €2,900.00
  2. €3,800.00
  3. €460.00
  4. €42.00
Subtotal
€7,202.00
Tax 7% on €460.00
€32.20
Tax 19% on €6,700.00
€1,273.00
Total
€8,507.20

Enter on the last line starts a new one.

When to use

The lines of an invoice or quote typed in place, with quantity, price and tax, and totals that follow as you type. Use Order Summary instead when the lines are settled and only read, as on a receipt.

Usage

import { LineItems, type LineItem } from "./ui/uicontext/components/LineItems.ts"
export const InvoiceLines = <M>(h: Html.H<M>, lines: ReadonlyArray<LineItem>, onChange: (lines: ReadonlyArray<LineItem>, total: number) => M) =>	LineItems(h, {		props: { label: "Invoice lines", value: lines, currency: "EUR", taxRates: [0, 0.07, 0.19] },		onEmit: { RequestedChange: ({ value, total }) => onChange(value, total) },	})

Examples

Starting empty

No taxRates, so no tax column. Type a line and press Enter for the next.

Quote for Harbor Street Bakery

  1. $0.00
Subtotal
$0.00
Total
$0.00

Enter on the last line starts a new one.

Nothing to send yet.

API reference

Props

LineItems props
NameTypeDefaultDescription
labelrequiredstring—What the lines belong to: "Invoice INV-2041".
valuerequiredLineItem[]—The lines to start with.
currencystring"USD"ISO 4217 code; "USD" by default.
taxRatesnumber[]—Tax rates a line can take, as fractions. Without them there's no tax column.
defaultTaxRatenumbertaxRatesThe rate a new line starts with; the first of taxRates by default.
idstring"lines"Starts the ids inside it, unique on the page; "lines" by default.
localestring—For amounts and percents; the browser's by default.

Events

LineItems events
EventPayloadDescription
RequestedChange{ value: LineItem[]; total: number }The lines changed: every line with a description or an amount, in order, and the total.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/line-items

Source