What an order comes to: its lines, then subtotal, discount, shipping, tax and the total.
- 2.4 kB JS 3.0 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 10 tests
Order summary
Waxed canvas toteOat · Large
was $85.00$68.00Stoneware mugSlate · 2 × $24.00$48.00
Merino socks, three pairsM$32.00
- Subtotal
- $148.00
- DiscountWELCOME10
- −$14.80
- Shipping
- Free
- Tax
- $10.99
- Total
- USD$144.19
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 filesconst 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 taxexport 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, }), )When to use
What an order comes to: its lines, then subtotal, discount, shipping, tax and the total. Use Fact Grid instead when the numbers don't add up to a total.
Usage
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
Tax included, in euros
taxIncluded shows the VAT inside the prices rather than adding it; locale writes the amounts.
- Business planAnnual · 12 × 144,00 €1.728,00 €
- SSO add-onAnnual · 1 × 480,00 €480,00 €
- Subtotal
- 2.208,00 €
- Shipping
- Free
- Including VAT
- 352,54 €
- Total
- EUR2.208,00 €
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 wayexport 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 |
|---|---|---|---|
linesrequired | OrderLine[] | — | What was ordered, in the order shown. |
currencyrequired | 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
pnpm dlx shadcn@latest add checkfu/uicontext/order-summary