nook
Browse the docs

Components

Table

Native

A semantic data table that scrolls sideways on small screens.

See the prompt
A list of your recent invoices.
InvoiceStatusMethodAmount
INV-001PaidCredit card$250.00
INV-002PendingPayPal$150.00
INV-003UnpaidBank transfer$350.00

Installation

npx nook-ui@latest add table

Prompt

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.

Plain text
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-001Nook CoPaid$250.00
INV-002NorthwindPending$150.00
INV-003GlobexUnpaid$350.00
INV-004InitechPaid$450.00

With a footer total

Invoice 1042 · Northwind Ltd
ServiceDaysAmount
Design sprint3$1,800.00
Prototype build5$3,000.00
Usability tests2$900.00
Total$5,700.00

Status badges

NameEmailStatus
Maya Okaformaya@acme.exampleActive
Tomás Riveratomas@acme.exampleInvited
Lena Fischerlena@acme.exampleSuspended

Empty

InvoiceClientAmount
No invoices yet. Create your first one to see it here.

Wide, scrolls sideways

OrderCustomerProductQtyCarrierTrackingShippedTotal
#4821Maya OkaforLinen shirt2DHLJD014600005012 May$96.00
#4822Maya OkaforLinen shirt2DHLJD014600005012 May$96.00

Loading rows

InvoiceClientAmount
Loading invoices

Could not load

InvoiceClientAmount

Props

Table

The table inside a scroll container.

PropTypeDefaultDescription
aria-labelstring–Names the scrollable region.
containerPropsHTMLAttributes<HTMLDivElement>–Props for the scroll container.

TableHeader / TableBody / TableFooter

Row groups.

TableRow

A row.

TableHead

A column header.

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