# Invoice Editor

> An outgoing invoice as a form beside the InvoicePreview it becomes: customer picker, line items with quantity, unit, unit price, VAT rate and discount, a discount on the whole invoice, the note and the totals per rate.

Component · Data · Halo kit · [Live page](https://ui.twentyfirst.media/halo/components/InvoiceEditor/)

An outgoing invoice as a form beside the InvoicePreview it becomes: customer picker, line items with
quantity, unit, unit price, VAT rate and discount, a discount on the whole invoice, the note and the
totals per rate. The preview updates as you type. It sits beside the form from 1100px (`stackBelow`), under it
below that, and on phones (below 640px) the form and the preview become tabs.

- `value` / `onChange` (or `defaultValue`) hold the draft: `customer`, `lines` (`id`, `description`,
  `quantity`, `price`, `vat`, `discount`, `unit`), `discount` and `note`.
- `vatRates` are data (default 19 %, 7 % and 0 %): pass your country's rates. `units` adds the unit column.
- Sums come from `invoiceTotals(lines, { discount })`: each line rounded to cents, VAT once per rate on
  the rate's net. Run the same function on your server and the numbers match to the cent.
- Numbers are typed in the provider's locale (`1,5` in German) and money is formatted with `Intl`.
- `preview` passes InvoicePreview's own props (number, from, dates, brand); `preview={false}` hides it.
  `head` adds fields at the top, `actions` the buttons under the totals.

## Example

```tsx
import * as React from "react";
import { Button, InvoiceEditor, Select } from "@twentyfirstmedia/halo";
import type { InvoiceDraft } from "@twentyfirstmedia/halo";

const CUSTOMERS = [
  { id: "northwind", name: "Northwind", detail: "Hamburg · net 14 days" },
  { id: "kestrel", name: "Kestrel Bank", detail: "Berlin · net 30 days" },
  { id: "sunline", name: "Sunline Travel", detail: "Munich · net 14 days" },
];

export default function Preview() {
  const [value, setValue] = React.useState<InvoiceDraft>({
    customer: "northwind",
    lines: [
      {
        id: "1",
        description: "Team plan · 40 seats · May 2026",
        quantity: 40,
        unit: "Seat",
        price: 24,
        vat: 19,
      },
      {
        id: "2",
        description: "Onboarding workshop (half day)",
        quantity: 1,
        unit: "Day",
        price: 650,
        vat: 19,
        discount: 10,
      },
      {
        id: "3",
        description: "Printed handbook",
        quantity: 12,
        unit: "Piece",
        price: 18.5,
        vat: 7,
      },
    ],
    note: "Thank you for your business. Please pay within 14 days.",
  });
  return (
    <InvoiceEditor
      value={value}
      onChange={setValue}
      customers={CUSTOMERS}
      customerAction={
        <Button variant="secondary" icon="plus">
          New
        </Button>
      }
      head={<Select label="Payment terms" options={["14 days", "30 days"]} />}
      units={["Seat", "Day", "Hour", "Piece"]}
      preview={{
        brand: "Halo",
        number: 2097,
        from: "Halo Workspace GmbH · Example Street 1 · 20457 Hamburg",
        issued: "Apr 16, 2026",
        due: "Apr 30, 2026",
      }}
      footnote="The number is given when the invoice is issued."
      actions={
        <>
          <Button variant="secondary">Save draft</Button>
          <Button icon="send">Issue invoice</Button>
        </>
      }
    />
  );
}
```

## Props

### InvoiceEditor

| Prop | Type | Notes |
| --- | --- | --- |
| `value?` | `InvoiceDraft` |  |
| `defaultValue?` | `InvoiceDraft` |  |
| `onChange?` | `(value: InvoiceDraft) => void` |  |
| `customers?` | `{ id: string; name: string; detail?: string }[]` | The customer picker's options. |
| `customerAction?` | `ReactNode` | Beside the picker, e.g. a "New customer" button. |
| `head?` | `ReactNode` | More fields at the top: dates, payment terms, number. |
| `vatRates?` | `{ value: number; label?: string }[]` | The VAT rates to pick from, in percent (default 19, 7 and 0). Your country's rates are data. |
| `units?` | `string[]` | Units to pick per line (hours, days, pieces …); omitted: no unit column. |
| `currency?` | `string` | Currency for amounts (default the provider's, euros). |
| `lineDiscounts?` | `boolean` | Discount per line (default true). |
| `invoiceDiscount?` | `boolean` | Discount on the whole invoice (default true). |
| `notes?` | `boolean` | The note field (default true). |
| `newLine?` | `() => InvoiceDraftLine` | A new line (e.g. with your id); default an empty line with the first VAT rate. |
| `preview?` | `Partial<Omit<InvoicePreviewProps, "lines">> \| false` | The live InvoicePreview beside the form (its number, from, dates …); `false` hides it. `to` defaults to the picked customer, the lines and the note come from the editor. |
| `stackBelow?` | `number` | Below this width (default 1100px) the preview moves under the form; below 640px they become tabs. |
| `actions?` | `ReactNode` | Under the totals: save, issue. |
| `footnote?` | `ReactNode` | Small print beside the totals ("The number is given when the invoice is issued"). |
| `readOnly?` | `boolean` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### InvoicePreview

| Prop | Type | Notes |
| --- | --- | --- |
| `number` | `string \| number` | Required |
| `from?` | `string` |  |
| `to` | `string` | Required |
| `issued` | `string` | Required |
| `due` | `string` | Required |
| `lines` | `{ d: string; q: number; u: number; v: number; discount?: number }[]` | Lines: description, quantity, unit price, VAT rate in percent, optional discount in percent. |
| `discount?` | `number` | Discount on the whole invoice in percent (shown as subtotal, discount, net). |
| `note?` | `string` |  |
| `kind?` | `string` |  |
| `brand?` | `string` |  |
| `format?` | `(n: number) => string` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
