Table

Rows and columns of data, with a header, a body and a footer.

Builds from the last 24 hours.
BuildStatusBranchDuration
b-4821Readymain1m 42s
b-4820Buildingfix/focus-ring2m 05s
b-4819Failedfeat/calendar0m 38s
b-4818Readymain1m 57s
b-4817Readydocs/theming2m 29s
Total8m 51s
import { Badge } from "@/components/ui/badge"
import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableFooter,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"

const builds = [
  { build: "b-4821", status: "Ready", branch: "main", duration: "1m 42s" },
  { build: "b-4820", status: "Building", branch: "fix/focus-ring", duration: "2m 05s" },
  { build: "b-4819", status: "Failed", branch: "feat/calendar", duration: "0m 38s" },
  { build: "b-4818", status: "Ready", branch: "main", duration: "1m 57s" },
  { build: "b-4817", status: "Ready", branch: "docs/theming", duration: "2m 29s" },
]

export default function TableDemo() {
  return (
    <Table>
      <TableCaption>Builds from the last 24 hours.</TableCaption>
      <TableHeader>
        <TableRow>
          <TableHead>Build</TableHead>
          <TableHead>Status</TableHead>
          <TableHead>Branch</TableHead>
          <TableHead align="end">Duration</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {builds.map((row) => (
          <TableRow key={row.build}>
            <TableHead>{row.build}</TableHead>
            <TableCell>
              <Badge variant={row.status === "Failed" ? "outline" : "secondary"}>
                {row.status}
              </Badge>
            </TableCell>
            <TableCell>{row.branch}</TableCell>
            <TableCell align="end">{row.duration}</TableCell>
          </TableRow>
        ))}
      </TableBody>
      <TableFooter>
        <TableRow>
          <TableCell colSpan={3}>Total</TableCell>
          <TableCell align="end">8m 51s</TableCell>
        </TableRow>
      </TableFooter>
    </Table>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/table

Needs the arene setup first.

Usage

import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableFooter,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"
<Table>
  <TableCaption>Builds from the last 24 hours.</TableCaption>
  <TableHeader>
    <TableRow>
      <TableHead>Build</TableHead>
      <TableHead>Status</TableHead>
      <TableHead align="end">Duration</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>b-4821</TableCell>
      <TableCell>Ready</TableCell>
      <TableCell align="end">1m 42s</TableCell>
    </TableRow>
  </TableBody>
</Table>

Composition

Table
├── TableCaption
├── TableHeader
│   └── TableRow
│       └── TableHead
├── TableBody
│   └── TableRow
│       ├── TableHead
│       └── TableCell
└── TableFooter
    └── TableRow
        └── TableCell

The table is drawn on a tray. TableBody is a raised panel inside it, and TableHeader, TableFooter and TableCaption stay on the tray around the panel. Body rows highlight on hover, and a hairline divides them.

Alignment

Set align="end" on the heading and the cells of a column of figures. The table uses tabular figures, so the digits line up.

Actions

Put a menu in the last column. A TableHead in a body row heads that row, as b-4821 does in the example above.

MemberRole
AL
Ada Lovelaceada@example.com
Owner
AT
Alan Turingalan@example.com
Admin
EN
Emmy Noetheremmy@example.com
Member
import * as stylex from "@stylexjs/stylex"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { HStack, VStack } from "@/components/ui/stack"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { DotsThreeIcon } from "@phosphor-icons/react/dist/csr/DotsThree"
import { Text } from "@/components/ui/text"

const members = [
  { name: "Ada Lovelace", email: "ada@example.com", initials: "AL", role: "Owner" },
  { name: "Alan Turing", email: "alan@example.com", initials: "AT", role: "Admin" },
  { name: "Emmy Noether", email: "emmy@example.com", initials: "EN", role: "Member" },
]

const styles = stylex.create({
  actions: { width: "1%" },
})

export default function TableActions() {
  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>Member</TableHead>
          <TableHead>Role</TableHead>
          <TableHead aria-label="Actions" xstyle={styles.actions} />
        </TableRow>
      </TableHeader>
      <TableBody>
        {members.map((member) => (
          <TableRow key={member.email}>
            <TableCell>
              <HStack gap={3} align="center">
                <Avatar>
                  <AvatarFallback>{member.initials}</AvatarFallback>
                </Avatar>
                <VStack>
                  <Text weight="medium">{member.name}</Text>
                  <Text size="xs" tone="muted">
                    {member.email}
                  </Text>
                </VStack>
              </HStack>
            </TableCell>
            <TableCell>{member.role}</TableCell>
            <TableCell align="end">
              <DropdownMenu>
                <DropdownMenuTrigger
                  render={<Button variant="ghost" size="icon-sm" />}
                  aria-label={`Actions for ${member.name}`}
                >
                  <DotsThreeIcon aria-hidden="true" />
                </DropdownMenuTrigger>
                <DropdownMenuContent align="end">
                  <DropdownMenuItem>Change role</DropdownMenuItem>
                  <DropdownMenuItem>Resend invite</DropdownMenuItem>
                  <DropdownMenuSeparator />
                  <DropdownMenuItem variant="destructive">Remove</DropdownMenuItem>
                </DropdownMenuContent>
              </DropdownMenu>
            </TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  )
}

API reference

Pass render to replace a part's element or compose it with another component.

Every part renders through Base UI's useRender, and takes xstyle, className and inline style alongside every attribute of its element.

Table

Renders a table inside a div that draws the tray and scrolls sideways when the columns don't fit. xstyle, className and render go to the table.

PropTypeDefault
containerPropsComponentProps<"div"> & { xstyle?: StyleXStyles; className?: string }—
renderReactElement | ((props, state) => ReactElement)<table />
xstyleStyleXStyles—
classNamestring—

TableHeader, TableBody, TableFooter

Render thead, tbody and tfoot. Each tells its rows which section they are in, so only body rows are raised, divided and highlighted. TableBody draws the panel behind itself. The footer's text is weight 500.

TableRow

Renders a tr. In the body it highlights on hover and draws a hairline below itself. The last row has no hairline, because the panel's edge is below it.

PropTypeDefault
selectedbooleanfalse

selected fills a body row with the muted colour and writes data-selected. Data Table sets it from row selection.

TableHead

Renders a th. In the header it is a column label in small muted type with scope="col". In a body row it heads that row at weight 500 with scope="row". Pass scope to override either.

PropTypeDefault
align"start" | "center" | "end""start"

TableCell

Renders a td. Cells don't wrap. To wrap one, pass xstyle.

PropTypeDefault
align"start" | "center" | "end""start"

TableCaption

Renders a caption under the table, on the tray.

tableStyles

The style maps behind the component. Spread them onto any element.

KeyWhat it is
containerThe tray and horizontal scroller
tableThe table: separate borders, type, tabular figures
bodyThe raised panel behind the body
footerThe footer's weight
bodyRowThe variables a body row sets for its cells
selectedRowThe fill a selected body row hands its cells
cellA cell's padding and alignment
bodyCellA body cell's fill, hairline and corners, read from the row
headA column label's type
captionThe caption
alignsstart, center and end

Data attributes

AttributeOnEffect
data-slot="table-container"the trayTargets the tray from a parent
data-slot="table"the tableTargets the table from a parent
data-slot="table-header"the headerTargets the header from a parent
data-slot="table-body"the bodyTargets the body from a parent
data-slot="table-footer"the footerTargets the footer from a parent
data-slot="table-row"a rowTargets a row from a parent
data-selecteda rowPresent on a selected row
data-slot="table-head"a headingTargets a heading from a parent
data-slot="table-cell"a cellTargets a cell from a parent
data-slot="table-caption"the captionTargets the caption from a parent

CSS variables

VariableOnEffect
--arene-table-radiusthe trayThe tray's corner radius, 12px. The panel's is 4px less
--arene-table-panel-radiusthe trayThe panel's corner, derived from the tray's