Line items editor
The lines of an invoice, quote, order or expense report as a sheet, with totals worked out.
import { LineItemsEditor, computeTotals, newLine, moveLine } from "@forgeron/ui";| Line | Description | Qty | Unit price | Tax % | Disc. % | Amount | Actions |
|---|---|---|---|---|---|---|---|
| 1 | €1,700.00 | ||||||
| 2 | €450.00 |
Arrow keys move between cells. Enter goes to the next line and adds one at the end. Alt with Up or Down moves the line. Control or Command with Enter inserts a line below; with Shift and Backspace it removes the line.
- Subtotal
- €2,200.00
- Discounts
- -€50.00
- Total excluding tax
- €2,150.00
- Tax 5.5 %
- on €450.00€24.75
- Tax 20 %
- on €1,700.00€340.00
- Total
- €2,514.75
import { LineItemsEditor, TotalsSummary, type LineItem, type ProductOption } from "@forgeron/ui";
import { useState } from "react";
const products: ProductOption[] = [
{
id: "p1",
label: "Design workshop",
hint: "SVC-001",
unitPrice: 85000,
taxRate: 20,
unit: "day",
},
{ id: "p2", label: "Brand guidelines", hint: "SVC-014", unitPrice: 240000, taxRate: 20 },
{
id: "p3",
label: "Printed booklet",
hint: "PRD-203",
unitPrice: 1250,
taxRate: 5.5,
unit: "pcs",
},
];
export default function Default() {
const [lines, setLines] = useState<LineItem[]>([
{
id: "a",
description: "Design workshop",
quantity: 2,
unit: "day",
unitPrice: 85000,
taxRate: 20,
discount: 0,
productId: "p1",
},
{
id: "b",
description: "Printed booklet",
quantity: 40,
unit: "pcs",
unitPrice: 1250,
taxRate: 5.5,
discount: 10,
productId: "p3",
},
]);
return (
<div style={{ display: "grid", gap: 16, width: 760, maxWidth: "100%" }}>
<LineItemsEditor
value={lines}
onChange={setLines}
currency="EUR"
locale="en"
products={products}
taxRates={[0, 5.5, 10, 20]}
defaultTaxRate={20}
/>
<div style={{ justifySelf: "end" }}>
<TotalsSummary lines={lines} currency="EUR" locale="en" />
</div>
</div>
);
}| Line | Description | Qty | Unit price | Tax % | Amount | Actions |
|---|---|---|---|---|---|---|
| Section subtotal €2,700.00 | ||||||
| 1 | €1,800.00 | |||||
| 2 | €900.00 | |||||
| Section subtotal €3,325.00 | ||||||
| 3 | €3,325.00 | |||||
Arrow keys move between cells. Enter goes to the next line and adds one at the end. Alt with Up or Down moves the line. Control or Command with Enter inserts a line below; with Shift and Backspace it removes the line.
import { LineItemsEditor, type LineItem } from "@forgeron/ui";
const lines: LineItem[] = [
{ id: "s1", kind: "section", description: "Discovery" },
{ id: "a", description: "Interviews", quantity: 3, unitPrice: 60000, taxRate: 20 },
{ id: "b", description: "Synthesis report", quantity: 1, unitPrice: 90000, taxRate: 20 },
{ id: "s2", kind: "section", description: "Delivery" },
{
id: "c",
description: "Prototype",
quantity: 5,
unit: "day",
unitPrice: 70000,
taxRate: 20,
discount: 5,
},
];
export default function Sections() {
return (
<div style={{ width: 720, maxWidth: "100%" }}>
<LineItemsEditor defaultValue={lines} currency="EUR" locale="en" showDiscount={false} />
</div>
);
}| Line | Description | Qty | Unit price | Tax % | Disc. % | Amount |
|---|---|---|---|---|---|---|
| Services | Section subtotal €1,114.50 | |||||
| 1 | Monthly hosting | 12 | €49.00 | 20 % | €588.00 | |
| 2 | Support hours | 6.5 h | €90.00 | 20 % | 10 % | €526.50 |
import { LineItemsEditor, type LineItem } from "@forgeron/ui";
const lines: LineItem[] = [
{ id: "s1", kind: "section", description: "Services" },
{ id: "a", description: "Monthly hosting", quantity: 12, unitPrice: 4900, taxRate: 20 },
{
id: "b",
description: "Support hours",
quantity: 6.5,
unit: "h",
unitPrice: 9000,
taxRate: 20,
discount: 10,
},
];
export default function ReadOnly() {
return (
<div style={{ width: 640, maxWidth: "100%" }}>
<LineItemsEditor value={lines} currency="EUR" locale="en" readOnly />
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | "Line items" | Names the sheet. |
value / defaultValue | LineItem[] | — | { id, kind?: 'item' | 'section', description, quantity?, unit?, unitPrice? (minor units), taxRate? (%), discount? (%), productId? }. Controlled or not. |
onChange | (lines: LineItem[]) => void | — | After every change. |
currency | string | — | An ISO 4217 code (`EUR`, `USD`, `JPY`): every amount is in its minor units. |
locale | string | — | A BCP 47 tag for the numbers and the symbol; the device's by default. |
products | ProductOption[] | — | { id, label, hint?, unitPrice?, taxRate?, unit? }. A button in each description searches them and fills the line. |
taxRates | number[] | — | The rates suggested while typing a tax cell. |
defaultTaxRate | number | — | The rate a new line starts with. |
showTax / showDiscount | boolean | true | The tax and discount columns. |
sections | boolean | true | Adds Add section: a heading row with its subtotal. |
readOnly | boolean | false | Text only, no controls: the table of a printed document. |
disabled | boolean | false | Locks the cells. |
addLabel / addSectionLabel / empty | string / ReactNode | — | The words of the buttons and of the empty sheet. |
className | string | — | Extra classes. |