Invoice lines editor
Add, remove, reorder (drag or buttons) and edit an invoice's lines: a product picker scoped to the invoice currency (with an optional New Product entry), tax rate, quantity, unit price (starts at the product's price) and a line discount, with each line's total. A controlled editor: values and onChange (the whole draft), errors, dirtyFields; pass the products and tax rates to pick from and it makes no request, leave one out and its picker reads it once opened. Also ships the line pickers on their own: InvoiceProductPicker (searches the catalogue, or takes your products) and InvoiceTaxRatePicker (reads the rates, or takes yours), and the type-to-search combobox the invoice form uses.
Component: A piece you place inside your own screens: a table, a form, a card or a dialog. You decide the layout around it. Pages vs components
Ready to connect to Dolfin. Loads data through SDK hooks, with appearance and behaviour you can customise. Requires DolfinProvider.
Installation
Needs the Dolfin registry token. The CLI copies the source into your app.
bunx --bun shadcn@4.23.0 add @dolfin/ar-invoice-lines-editorAlso installs: button, card, command, field, input, popover, select, base-theme, base-info-hint, base-money, base-states, ar-invoice-discount, ui-ar-invoice-lines-editor.
Usage
import { InvoiceLinesEditor } from "@/components/dolfin/ar/invoice-lines-editor";
// Place it anywhere inside your <DolfinProvider>.
<InvoiceLinesEditor values={values} />Renders inside DolfinProvider (set it up once). By default it loads its own data through the SDK. Supplied-data examples show how to override that behavior.
API reference
| Prop | Type | Description |
|---|---|---|
values required | InvoiceDraft | The invoice being edited (`useInvoiceDraft().draft`, or your own): its lines, priced in its currency. |
onChange | (values: InvoiceDraft) => void | Called with the whole invoice after each edit (`useInvoiceDraft().setValues`, or your own state). |
errors | Readonly<Partial<Record<string, string>>> | A message per field path (`lines`, `lines.0.quantity`), as `useInvoiceDraft().errors` holds them. |
dirtyFields | readonly string[] | Field paths to ring as changed since the invoice was saved (`useInvoiceDraft().dirtyFields`). |
products | readonly ProductOption[] | The products to pick from, in the invoice currency. Given (`[]` included), the picker makes no request; left out, it searches them once it opens. The same for `taxRates`. |
productsLoading | boolean | |
productsError | Error | |
onProductsRetry | () => void | |
onProductSearch | (query: string) => void | Called with the product search as the user types (debounced 400ms). |
taxRates | readonly TaxRateOption[] | The tax rates a line can carry. |
taxRatesLoading | boolean | |
taxRatesError | Error | |
onTaxRatesRetry | () => void | |
onCreateProduct | (lineKey: string) => void | Offers "New Product" in the product picker; open your create-product dialog for this line. |
emptyState | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | Replaces the note shown when there are no lines. |
renderLineExtra | (line: InvoiceDraftLine, index: number) => ReactNode | Extra fields under a line (for example an income account). |
className | string |
Customisation
Without editing the source, you can change:
- Class names
className- Messages
ar.invoiceDraft.linesbase.states.loadingbase.states.retry
Or edit the installed file directly: it is your code. See theming for colours and fonts.
Hooks
The SDK hooks this component uses. Use them directly from @dolfinai/react to build your own version.
useMessagesuseProductOptionsuseTaxRateOptionsFiles
Written to your app by the install command:
components/dolfin/ar/invoice-lines-editor.tsx320 linescomponents/dolfin/ar/invoice-product-picker.tsx150 linescomponents/dolfin/ar/invoice-tax-rate-picker.tsx102 linescomponents/dolfin/ar/invoice-draft-combobox.tsx100 lines