Blocks / Line items editor

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";
/01 → Default
Line items
LineDescriptionQtyUnit priceTax %Disc. %AmountActions
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>
  );
}
/02 → Sections
Line items
LineDescriptionQtyUnit priceTax %AmountActions
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>
  );
}
/03 → Read only
Line items
LineDescriptionQtyUnit priceTax %Disc. %Amount
ServicesSection subtotal €1,114.50
1Monthly hosting12€49.0020 %€588.00
2Support hours6.5 h€90.0020 %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
PropTypeDefaultDescription
labelstring"Line items"Names the sheet.
value / defaultValueLineItem[]—{ id, kind?: 'item' | 'section', description, quantity?, unit?, unitPrice? (minor units), taxRate? (%), discount? (%), productId? }. Controlled or not.
onChange(lines: LineItem[]) => void—After every change.
currencystring—An ISO 4217 code (`EUR`, `USD`, `JPY`): every amount is in its minor units.
localestring—A BCP 47 tag for the numbers and the symbol; the device's by default.
productsProductOption[]—{ id, label, hint?, unitPrice?, taxRate?, unit? }. A button in each description searches them and fills the line.
taxRatesnumber[]—The rates suggested while typing a tax cell.
defaultTaxRatenumber—The rate a new line starts with.
showTax / showDiscountbooleantrueThe tax and discount columns.
sectionsbooleantrueAdds Add section: a heading row with its subtotal.
readOnlybooleanfalseText only, no controls: the table of a printed document.
disabledbooleanfalseLocks the cells.
addLabel / addSectionLabel / emptystring / ReactNode—The words of the buttons and of the empty sheet.
classNamestring—Extra classes.