Components
Cart
NativeEditable cart rows, undoable removal, promo codes and an order summary.
Installation
npx nook-ui@latest add cartPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Cart" component to this project, exactly as Nook ships it.
Editable cart rows, undoable removal, promo codes and an order summary.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add cart`. It writes `components/ui/cart.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/cart.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { Skeleton } from "@/components/ui/skeleton";
export default function CartLoading() {
return (
<div className="grid w-full max-w-md gap-4" aria-busy="true" role="status">
<span className="sr-only">Loading your cart</span>
{[0, 1].map((row) => (
<div key={row} className="flex gap-3">
<Skeleton className="size-20 shrink-0" />
<div className="grid flex-1 content-start gap-2">
<Skeleton className="h-4 w-40" />
<Skeleton className="h-3 w-24" />
<Skeleton className="h-8 w-28" />
</div>
</div>
))}
<Skeleton className="h-10 w-full" />
</div>
);
}
```
API
- `Cart`: A controlled or local cart with derived subtotal and an empty state. Compose with Sheet for a side panel.
- `value / defaultValue / onValueChange` (`CartLine[] / callback`): Rows: id, name, optional image/options, price, quantity and maxQuantity.
- `summary` (`Omit<OrderSummaryProps, 'subtotal' | 'currency'>`): Shipping, tax, discounts and promo handlers for the summary.
- `currency / empty / children` (`string / ReactNode / ReactNode`): Currency, custom empty content and actions such as checkout.
- `CartItem`: A row for custom cart layouts.
- `item / currency` (`CartLine / string`): Product information and amount formatting.
- `onQuantityChange / onRemove` (`callback`): Handlers for the quantity and removal controls.
- `QuantityStepper`: A NumberField adapter with a default quantity range of 1–99.
- `value / defaultValue / onValueChange / min / max` (`NumberFieldProps`): The same controlled state and keyboard contract as NumberField. Give it an aria-label.
- `OrderSummary`: Subtotal, shipping, tax, absolute discount and clamped total, plus an optional promo form.
- `subtotal / shipping / tax / discount` (`number`): Amounts in major currency units.
- `onApplyPromo` (`(code) => PromoResult | Promise<PromoResult>`): Return { discount, label? } or { error }. No request is made by the component.
- `onRemovePromo / onDiscountChange` (`callback`): Tell the app when the promo is removed or its discount changes.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Quantity entry reuses NumberField for bounds, arrow keys and hold-to-repeat buttons. Removal moves focus to Undo and announces the removed item. Promo errors are linked to the field and announced.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { Skeleton } from "@/components/ui/skeleton";
export default function CartLoading() {
return (
<div className="grid w-full max-w-md gap-4" aria-busy="true" role="status">
<span className="sr-only">Loading your cart</span>
{[0, 1].map((row) => (
<div key={row} className="flex gap-3">
<Skeleton className="size-20 shrink-0" />
<div className="grid flex-1 content-start gap-2">
<Skeleton className="h-4 w-40" />
<Skeleton className="h-3 w-24" />
<Skeleton className="h-8 w-28" />
</div>
</div>
))}
<Skeleton className="h-10 w-full" />
</div>
);
}Examples
Long product names
- $96.00
Handmade stoneware dinner plate set with speckled glaze, 4 pieces
Colour: Oat, Size: 27 cm, Gift wrapped
$96.00 each
- $56.00
Linen napkins
Pack of 6
$28.00 each
Order summary
- Subtotal
- $152.00
- Shipping
- $0.00
- Tax
- $0.00
- Total
- $152.00
A cart in a side panel
An order on its way
Order NK-2048
On its wayOrder confirmed
Everyday notebook × 2 and Morning cup × 1
Packed with care
Your order left our Brooklyn studio.
Out for delivery
Arriving today, before 6 pm.
Delivered
We will let you know when it arrives.
Empty cart
Your cart is empty. Add a notebook or a cup to get started.
With promo code
- $36.00
Everyday notebook
Forest / A5
$18.00 each
- $32.00
Morning cup
Sand
$32.00 each
Order summary
- Subtotal
- $68.00
- Shipping
- $6.00
- Tax
- $4.20
- Total
- $78.20
Props
Cart
A controlled or local cart with derived subtotal and an empty state. Compose with Sheet for a side panel.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange | CartLine[] / callback | – | Rows: id, name, optional image/options, price, quantity and maxQuantity. |
| summary | Omit<OrderSummaryProps, 'subtotal' | 'currency'> | – | Shipping, tax, discounts and promo handlers for the summary. |
| currency / empty / children | string / ReactNode / ReactNode | – | Currency, custom empty content and actions such as checkout. |
CartItem
A row for custom cart layouts.
| Prop | Type | Default | Description |
|---|---|---|---|
| item / currency | CartLine / string | – | Product information and amount formatting. |
| onQuantityChange / onRemove | callback | – | Handlers for the quantity and removal controls. |
QuantityStepper
A NumberField adapter with a default quantity range of 1–99.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange / min / max | NumberFieldProps | – | The same controlled state and keyboard contract as NumberField. Give it an aria-label. |
OrderSummary
Subtotal, shipping, tax, absolute discount and clamped total, plus an optional promo form.
| Prop | Type | Default | Description |
|---|---|---|---|
| subtotal / shipping / tax / discount | number | – | Amounts in major currency units. |
| onApplyPromo | (code) => PromoResult | Promise<PromoResult> | – | Return { discount, label? } or { error }. No request is made by the component. |
| onRemovePromo / onDiscountChange | callback | – | Tell the app when the promo is removed or its discount changes. |
Accessibility
Quantity entry reuses NumberField for bounds, arrow keys and hold-to-repeat buttons. Removal moves focus to Undo and announces the removed item. Promo errors are linked to the field and announced.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.