Display

Table

Semantic table parts with row hover and a scrolling container. For data, not layout.

packages/design-system/components/ui/table.tsx

Examples

Invoices this quarter.
InvoiceProjectStatusAmount
BW-104Brand sprintPaid$8,000
BW-105WebsiteDue$14,500
BW-106Design systemDraft$9,200
Total$31,700
Caption, header, body, footer

Anatomy

  1. 01Container, overflow-x-auto
  2. 02Caption
  3. 03Header
  4. 04Body rows, hover muted
  5. 05Footer

Usage

import {
  Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow,
} from "@repo/design-system/components/ui/table";

<Table>
  <TableCaption>Invoices this quarter.</TableCaption>
  <TableHeader>
    <TableRow>
      <TableHead>Invoice</TableHead>
      <TableHead className="text-right">Amount</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    {invoices.map((invoice) => (
      <TableRow key={invoice.id}>
        <TableCell>{invoice.id}</TableCell>
        <TableCell className="text-right">{invoice.amount}</TableCell>
      </TableRow>
    ))}
  </TableBody>
</Table>

Props

PropTypeDefaultDescription
...propsComponentProps<"table" | "thead" | "tr" | "td" ...>noneEach part passes through to its element. Table wraps itself in an overflow container.
classNamestringnoneMerged last with cn(). Use it for layout (width, margin), not to restyle the component.

Guidance

Do

  • Right-align numbers.
  • Give it a caption, even a visually hidden one.

Don't

  • Use it to lay out a page.