Components
Table
NativeA semantic data table that scrolls sideways on small screens.
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV-001 | Paid | Credit card | $250.00 |
| INV-002 | Pending | PayPal | $150.00 |
| INV-003 | Unpaid | Bank transfer | $350.00 |
Installation
npx nook-ui@latest add tablePrompt
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 "Table" component to this project, exactly as Nook ships it.
A semantic data table that scrolls sideways on small screens.
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 table`. It writes `components/ui/table.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/table.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 { Badge } from "@/components/ui/badge";
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
const invoices = [
{ id: "INV-001", status: "Paid", method: "Credit card", amount: "$250.00" },
{ id: "INV-002", status: "Pending", method: "PayPal", amount: "$150.00" },
{ id: "INV-003", status: "Unpaid", method: "Bank transfer", amount: "$350.00" },
];
export default function TableDefault() {
return (
<Table aria-label="Recent invoices">
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.id}>
<TableCell className="font-medium">{invoice.id}</TableCell>
<TableCell>
<Badge variant={invoice.status === "Paid" ? "default" : invoice.status === "Pending" ? "secondary" : "outline"}>{invoice.status}</Badge>
</TableCell>
<TableCell>{invoice.method}</TableCell>
<TableCell className="text-right">{invoice.amount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
}
```
API
- `Table`: The table inside a scroll container.
- `aria-label` (`string`): Names the scrollable region.
- `containerProps` (`HTMLAttributes<HTMLDivElement>`): Props for the scroll container.
- `TableHeader / TableBody / TableFooter`: Row groups.
- `TableRow`: A row.
- `TableHead`: A column header.
- `scope` (`"col" | "row"`, default "col"): Header scope.
- `TableCell`: A data cell.
- `TableCaption`: A visible caption.
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: Headers get scope=col. The scroll container is a focusable region so keyboard users can scroll; name it with `aria-label` on Table.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { Badge } from "@/components/ui/badge";
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
const invoices = [
{ id: "INV-001", status: "Paid", method: "Credit card", amount: "$250.00" },
{ id: "INV-002", status: "Pending", method: "PayPal", amount: "$150.00" },
{ id: "INV-003", status: "Unpaid", method: "Bank transfer", amount: "$350.00" },
];
export default function TableDefault() {
return (
<Table aria-label="Recent invoices">
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.id}>
<TableCell className="font-medium">{invoice.id}</TableCell>
<TableCell>
<Badge variant={invoice.status === "Paid" ? "default" : invoice.status === "Pending" ? "secondary" : "outline"}>{invoice.status}</Badge>
</TableCell>
<TableCell>{invoice.method}</TableCell>
<TableCell className="text-right">{invoice.amount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
}Examples
Sortable columns
Press a column name to sort by it; press again to reverse.
| Status | |||
|---|---|---|---|
| INV-001 | Nook Co | Paid | $250.00 |
| INV-002 | Northwind | Pending | $150.00 |
| INV-003 | Globex | Unpaid | $350.00 |
| INV-004 | Initech | Paid | $450.00 |
With a footer total
| Service | Days | Amount |
|---|---|---|
| Design sprint | 3 | $1,800.00 |
| Prototype build | 5 | $3,000.00 |
| Usability tests | 2 | $900.00 |
| Total | $5,700.00 | |
Status badges
| Name | Status | |
|---|---|---|
| Maya Okafor | maya@acme.example | Active |
| Tomás Rivera | tomas@acme.example | Invited |
| Lena Fischer | lena@acme.example | Suspended |
Empty
| Invoice | Client | Amount |
|---|---|---|
| No invoices yet. Create your first one to see it here. | ||
Wide, scrolls sideways
| Order | Customer | Product | Qty | Carrier | Tracking | Shipped | Total |
|---|---|---|---|---|---|---|---|
| #4821 | Maya Okafor | Linen shirt | 2 | DHL | JD0146000050 | 12 May | $96.00 |
| #4822 | Maya Okafor | Linen shirt | 2 | DHL | JD0146000050 | 12 May | $96.00 |
Loading rows
| Invoice | Client | Amount |
|---|---|---|
Could not load
| Invoice | Client | Amount |
|---|---|---|
We could not load your invoices. Check your connection and try again. | ||
Props
Table
The table inside a scroll container.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | – | Names the scrollable region. |
| containerProps | HTMLAttributes<HTMLDivElement> | – | Props for the scroll container. |
TableHeader / TableBody / TableFooter
Row groups.
TableRow
A row.
TableHead
A column header.
| Prop | Type | Default | Description |
|---|---|---|---|
| scope | "col" | "row" | "col" | Header scope. |
TableCell
A data cell.
TableCaption
A visible caption.
Accessibility
Headers get scope=col. The scroll container is a focusable region so keyboard users can scroll; name it with `aria-label` on Table.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.