# Order Summary

> What an order comes to: its lines, then subtotal, discount, shipping, tax and the total.

Page: https://uicontext.com/docs/components/order-summary

Group: Records.

## When to use

What an order comes to: its lines, then subtotal, discount, shipping, tax and the total. Use [Fact Grid](https://uicontext.com/docs/components/fact-grid.md) instead when the numbers don't add up to a total.

## Usage

```ts
import { OrderSummary } from "./ui/uicontext/components/OrderSummary.ts"

export const Summary = <M>(h: Html.H<M>) =>
	OrderSummary(h, { currency: "USD", lines: [{ id: "mug", name: "Stoneware mug", quantity: 2, unitPrice: 2400 }], shipping: 0, taxRate: 0.0825 })
```

## Examples

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

### At checkout

The example the page opens with: Order Summary in “At checkout”.

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

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

// a drawn product shot, so the demo needs no image files
const shot = (fill: string) =>
	`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><rect width="48" height="48" fill="#f3f4f6"/><path d="M14 16h20l-2 22H16z" fill="${fill}"/><path d="M19 16a5 5 0 0110 0" fill="none" stroke="${fill}" stroke-width="2"/></svg>`)}`

// a storefront checkout's summary: a sale price, a discount code, free shipping and sales tax
export const Checkout = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		OrderSummary(h, {
			title: "Order summary",
			card: true,
			currency: "USD",
			locale: "en-US",
			lines: [
				{ id: "tote", name: "Waxed canvas tote", detail: "Oat · Large", quantity: 1, unitPrice: 6800, compareAt: 8500, image: shot("#d6c7a1") },
				{ id: "mug", name: "Stoneware mug", detail: "Slate", quantity: 2, unitPrice: 2400, image: shot("#64748b") },
				{ id: "socks", name: "Merino socks, three pairs", detail: "M", quantity: 1, unitPrice: 3200, image: shot("#7c3aed") },
			],
			discount: { label: "WELCOME10", amount: 1480 },
			shipping: 0,
			taxRate: 0.0825,
		}),
	)
```

### Tax included, in euros

`taxIncluded` shows the VAT inside the prices rather than adding it; `locale` writes the amounts.

```ts title="src/vat.ts" source="www/src/examples/order-summary/vat.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { OrderSummary } from "./ui/uicontext/components/OrderSummary.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

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

// an invoice for a customer in Germany: VAT is inside the prices, and amounts are written the German way
export const Invoice = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		OrderSummary(h, {
			currency: "EUR",
			locale: "de-DE",
			taxIncluded: true,
			taxRate: 0.19,
			taxLabel: "VAT",
			lines: [
				{ id: "seats", name: "Business plan", detail: "Annual", quantity: 12, unitPrice: 14_400 },
				{ id: "sso", name: "SSO add-on", detail: "Annual", quantity: 1, unitPrice: 48_000 },
			],
			shipping: 0,
		}),
	)
```

## API reference

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `lines` (required) | `OrderLine[]` | — | What was ordered, in the order shown. |
| `currency` (required) | `string` | — | ISO 4217: "USD", "EUR", "JPY". |
| `discount` | `{ readonly label: string; readonly amount: number }` | — | Off the subtotal, in minor units, with the code or reason: { label: "WELCOME10", amount: 1200 }. |
| `shipping` | `number` | — | In minor units; 0 reads "Free". Leave out while it isn't known yet. |
| `taxRate` | `number` | — | A rate such as 0.0825, applied to the subtotal after the discount. |
| `taxIncluded` | `boolean` | — | Tax already in the prices, as in much of Europe: shown as "Including VAT", not added. |
| `taxLabel` | `string` | `"Tax"` | The tax line's name; "Tax" by default, "VAT" or "GST" elsewhere. |
| `title` | `string` | — | A heading over it: "Order summary". |
| `card` | `boolean` | — | Draws it on a bordered card. |
| `locale` | `string` | — | — |
| `style` | `Style` | — | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/order-summary
```

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

It writes these files:

- `src/ui/uicontext/components/OrderSummary.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

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

## Source

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

## 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.
