# Line Items

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

Page: https://uicontext.com/docs/components/line-items

Group: Records.

## 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](https://uicontext.com/docs/components/order-summary.md) instead when the lines are settled and only read, as on a receipt.

## Usage

```ts
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

Each example is a complete file. Its imports point where the CLI installs the source.

### An invoice with tax rates

The example the page opens with: Line Items in “An invoice with tax rates”.

```ts title="src/demo.ts" source="www/src/examples/line-items/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { LineItems } from "./ui/uicontext/components/LineItems.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "min(100%, 52rem)" } })

// a studio's invoice in euros: services at the standard rate, a printed book at the reduced one
export const StudioInvoice = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		LineItems(h, {
			key: "invoice",
			props: {
				label: "Invoice INV-2041",
				currency: "EUR",
				locale: "en-IE",
				taxRates: [0, 0.07, 0.19],
				defaultTaxRate: 0.19,
				value: [
					{ description: "Brand workshop, two days", quantity: 2, unitPrice: 1450, taxRate: 0.19 },
					{ description: "Logo and type system", quantity: 1, unitPrice: 3800, taxRate: 0.19 },
					{ description: "Printed brand book", quantity: 25, unitPrice: 18.4, taxRate: 0.07 },
					{ description: "Courier to Lisbon", quantity: 1, unitPrice: 42, taxRate: 0 },
				],
			},
		}),
	)
```

### Starting empty

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

This example also uses Button. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/button
```

```ts title="src/quote.ts" source="www/src/examples/line-items/quote.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Button } from "./ui/uicontext/components/Button.ts"
import { formatMoney } from "./ui/uicontext/components/domain/Format.ts"
import { LineItem, LineItems } from "./ui/uicontext/components/LineItems.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	wrap: { display: "grid", gap: space.lg, inlineSize: "min(100%, 44rem)" },
	foot: { display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: space.md, fontSize: font.sm, color: color.muted },
})

const Message = UiSchema.TaggedEnum({ Edited: { lines: Schema.Array(LineItem), total: Schema.Number } })

// a quote started empty: type a line, press Enter, type the next; the app keeps the lines and total
export const NewQuote = Html.component({
	name: "NewQuote",
	model: Schema.Struct({ lines: Schema.Array(LineItem), total: Schema.Number }),
	message: Message,
}).make({
	init: () => ({ lines: [], total: 0 }),
	update: { Edited: ($, { lines, total }) => $.evolve({ lines, total }) },
	view: (h, model) =>
		h.div.attrs(sx(styles.wrap)).children(
			LineItems(h, {
				key: "quote",
				props: { id: "quote", label: "Quote for Harbor Street Bakery", value: [] },
				onEmit: { RequestedChange: ({ value, total }) => Message.Edited({ lines: value, total }) },
			}),
			h.div.attrs(sx(styles.foot)).children(
				h.span.children(model.lines.length === 0 ? "Nothing to send yet." : `Ready to send: ${formatMoney(model.total)}`),
				Button(h, { tone: "primary" }).disabled(model.lines.length === 0).children("Send quote"),
			),
		),
})
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | What the lines belong to: "Invoice INV-2041". |
| `value` (required) | `LineItem[]` | — | The lines to start with. |
| `currency` | `string` | `"USD"` | ISO 4217 code; "USD" by default. |
| `taxRates` | `number[]` | — | Tax rates a line can take, as fractions. Without them there's no tax column. |
| `defaultTaxRate` | `number` | `taxRates` | The rate a new line starts with; the first of `taxRates` by default. |
| `id` | `string` | `"lines"` | Starts the ids inside it, unique on the page; "lines" by default. |
| `locale` | `string` | — | For amounts and percents; the browser's by default. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedChange` | `{ value: LineItem[]; total: number }` | The lines changed: every line with a description or an amount, in order, and the total. |

## Installation

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

With npm: `npx shadcn@latest add checkfu/uicontext/line-items`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/line-items`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/line-items`.

It writes these files:

- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/LineItems.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/LineItems.ts](https://github.com/checkfu/uicontext/blob/main/src/LineItems.ts)
- [src/touch.stylex.ts](https://github.com/checkfu/uicontext/blob/main/src/touch.stylex.ts)

## Used in

- [SaaS dashboard](https://uicontext.com/blocks/saas-dashboard.md)
- [Workflow builder](https://uicontext.com/blocks/automation-builder.md)
- [Team chat](https://uicontext.com/blocks/team-chat.md)
- [Whiteboard](https://uicontext.com/blocks/whiteboard.md)

## Related

- [Data Grid](https://uicontext.com/docs/components/data-grid.md) (`data-grid`): A spreadsheet-like grid for editing records, with typed columns, sorting and grouping.
- [Pivot Table](https://uicontext.com/docs/components/pivot-table.md) (`pivot-table`): Records summed two ways, such as revenue by region and quarter, with totals on both edges and cells tinted by size.
- [Table](https://uicontext.com/docs/components/table.md) (`table`): A simple read-only table with a caption, row headers and an empty state.
- [Group Header](https://uicontext.com/docs/components/group-header.md) (`group-header`): The line over a group of rows with its count, sticky while they scroll, folding the group.
- [Description List](https://uicontext.com/docs/components/description-list.md) (`description-list`): A record's facts as label and value pairs, in rows or columns, with Copy for ids.
- [Fact Grid](https://uicontext.com/docs/components/fact-grid.md) (`fact-grid`): A few numbers about one thing, such as a customer's plan and seats, as small tiles.
