Table

Table displays structured data in rows and columns.

CustomerDueAmount
Acme CorpOct 2$1,200.00
GlobexOct 9$860.50
InitechOct 14$2,410.00
Total$4,470.50
tsx
import { Table } from '@/components/ui/wideset/table/Table';

<div className="w-[26rem] max-w-full">
  <Table>
    <Table.Head>
      <Table.Row>
        <Table.Header>Customer</Table.Header>
        <Table.Header>Due</Table.Header>
        <Table.Header align="right">Amount</Table.Header>
      </Table.Row>
    </Table.Head>
    <Table.Body>
      <Table.Row>
        <Table.Cell>Acme Corp</Table.Cell>
        <Table.Cell>Oct 2</Table.Cell>
        <Table.Cell align="right">$1,200.00</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.Cell>Globex</Table.Cell>
        <Table.Cell>Oct 9</Table.Cell>
        <Table.Cell align="right">$860.50</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.Cell>Initech</Table.Cell>
        <Table.Cell>Oct 14</Table.Cell>
        <Table.Cell align="right">$2,410.00</Table.Cell>
      </Table.Row>
    </Table.Body>
    <Table.Foot>
      <Table.Row>
        <Table.Cell>Total</Table.Cell>
        <Table.Cell />
        <Table.Cell align="right">$4,470.50</Table.Cell>
      </Table.Row>
    </Table.Foot>
  </Table>
</div>

Installation

pnpm dlx wideset add table

Copies the component and any Wideset components it uses into your project.

Examples

Separated

Rows are always divided by a line. separated adds lines between the columns as well, for wide tables of numbers where the eye follows a column down rather than a row across.

tsx
import { Table } from '@/components/ui/wideset/table/Table';

const rows = [
  ['Acme Corp', '$1,200.00', '$300.00', '$900.00'],
  ['Globex', '$860.50', '$0.00', '$860.50'],
  ['Initech', '$2,410.00', '$410.00', '$2,000.00'],
];

export default function TableSeparated() {
  return (
    <div className="w-[30rem] max-w-full">
      <Table separated>
        <Table.Head>
          <Table.Row>
            <Table.Header>Customer</Table.Header>
            <Table.Header align="right">Billed</Table.Header>
            <Table.Header align="right">Paid</Table.Header>
            <Table.Header align="right">Due</Table.Header>
          </Table.Row>
        </Table.Head>
        <Table.Body>
          {rows.map(([customer, billed, paid, due]) => (
            <Table.Row key={customer}>
              <Table.Cell>{customer}</Table.Cell>
              <Table.Cell align="right">{billed}</Table.Cell>
              <Table.Cell align="right">{paid}</Table.Cell>
              <Table.Cell align="right">{due}</Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
      </Table>
    </div>
  );
}

Striped

striped shades every other row, so the eye can follow a long row across many columns without losing its place. Use it for wide tables of similar-looking values; short tables read fine with the row lines alone.

tsx
import { Table } from '@/components/ui/wideset/table/Table';

const rows = [
  ['Redesign website', 'In progress', 'May 30', 'Anna Kowalska'],
  ['Launch mobile app', 'Done', 'Jun 15', 'Marek Nowak'],
  ['Brand refresh', 'Planned', 'Jul 1', 'Ola Wiśniewska'],
  ['Pricing page', 'In progress', 'Jul 12', 'Piotr Zieliński'],
];

export default function TableStriped() {
  return (
    <div className="w-[34rem] max-w-full">
      <Table striped>
        <Table.Head>
          <Table.Row>
            <Table.Header>Project</Table.Header>
            <Table.Header>Status</Table.Header>
            <Table.Header>Deadline</Table.Header>
            <Table.Header>Owner</Table.Header>
          </Table.Row>
        </Table.Head>
        <Table.Body>
          {rows.map(([project, status, deadline, owner]) => (
            <Table.Row key={project}>
              <Table.Cell>{project}</Table.Cell>
              <Table.Cell>{status}</Table.Cell>
              <Table.Cell>{deadline}</Table.Cell>
              <Table.Cell>{owner}</Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
      </Table>
    </div>
  );
}

Sizes

The size sets the row height and the text size together. Small is the default and fits most data; medium and large give room to rows that hold avatars, buttons or two lines of text.

tsx
import { Table } from '@/components/ui/wideset/table/Table';

const sizes = ['sm', 'md', 'lg'] as const;
const names = { sm: 'Small', md: 'Medium', lg: 'Large' };

export default function TableSizes() {
  return (
    <div className="gap-ws-11 flex w-[26rem] max-w-full flex-col">
      {sizes.map((size) => (
        <Table key={size} size={size}>
          <Table.Head>
            <Table.Row>
              <Table.Header>{names[size]}</Table.Header>
              <Table.Header align="right">Amount</Table.Header>
            </Table.Row>
          </Table.Head>
          <Table.Body>
            <Table.Row>
              <Table.Cell>Acme Corp</Table.Cell>
              <Table.Cell align="right">$1,200.00</Table.Cell>
            </Table.Row>
          </Table.Body>
        </Table>
      ))}
    </div>
  );
}

States

Row hover is live with interactive; selectionMode turns it on too, makes the table a grid and sets aria-selected on each row, while the selection itself stays your state. A sortable header gets a sort button and aria-sort; disabled on the header locks the button.

tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';
import { Table } from '@/components/ui/wideset/table/Table';
import { useState } from 'react';

const rows = [
  { id: 1, name: 'Redesign website', deadline: 'May 30' },
  { id: 2, name: 'Launch mobile app', deadline: 'Jun 15' },
  { id: 3, name: 'Brand refresh', deadline: 'Jul 1' },
];

export default function TableStates() {
  const [selected, setSelected] = useState<number[]>([2]);
  const toggle = (id: number) =>
    setSelected((ids) => (ids.includes(id) ? ids.filter((item) => item !== id) : [...ids, id]));

  return (
    <div className="w-[26rem] max-w-full">
      <Table selectionMode="multiple">
        <Table.Head>
          <Table.Row>
            <Table.Header className="w-[3rem]" />
            <Table.Header sortable sortDirection="asc">
              Project
            </Table.Header>
            <Table.Header sortable disabled>
              Deadline
            </Table.Header>
          </Table.Row>
        </Table.Head>
        <Table.Body>
          {rows.map((row) => (
            <Table.Row
              key={row.id}
              selected={selected.includes(row.id)}
              onClick={() => toggle(row.id)}
            >
              <Table.Cell>
                <Checkbox checked={selected.includes(row.id)} aria-label={`Select ${row.name}`} />
              </Table.Cell>
              <Table.Cell>{row.name}</Table.Cell>
              <Table.Cell>{row.deadline}</Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
      </Table>
    </div>
  );
}

Descriptions

A second, quieter line under a cell's label goes in Table.CellDescription: a project's summary under its name, an email under a person. The label keeps the table's type, so never raise its size to make it stand out. Use it in md and lg tables.

tsx
import { StatusBadge } from '@/components/ui/wideset/status-badge/StatusBadge';
import { Table } from '@/components/ui/wideset/table/Table';

const features = [
  { name: 'Offline sync', summary: 'Edits made offline merge on reconnect.', beta: true },
  { name: 'Shared views', summary: 'Saved filters the whole team can open.', beta: false },
  { name: 'Audit log', summary: 'Every change with who made it and when.', beta: false },
];

export default function TableDescriptions() {
  return (
    <div className="w-[30rem] max-w-full">
      <Table>
        <Table.Head>
          <Table.Row>
            <Table.Header>Feature</Table.Header>
            <Table.Header>Status</Table.Header>
          </Table.Row>
        </Table.Head>
        <Table.Body>
          {features.map(({ name, summary, beta }) => (
            <Table.Row key={name}>
              <Table.Cell>
                {name}
                <Table.CellDescription>{summary}</Table.CellDescription>
              </Table.Cell>
              <Table.Cell>
                <StatusBadge color={beta ? 'notice' : 'positive'}>
                  {beta ? 'Beta' : 'Stable'}
                </StatusBadge>
              </Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
      </Table>
    </div>
  );
}

API reference

Table

NameDescriptionDefault
align
'center''left''right'
—
flushMarginboolean—
hasBackground

Applies a solid background color to all cells. Required for sticky header/column to appear correctly over scrolling content. Automatically defaults to `true` when `stickyHeader` or `stickyColumn` is enabled.

boolean
—
interactiveboolean—
placement
'bottom''top''middle'
—
selectedboolean—
selectionMode

Enables row selection - `single` — only one row can be selected at a time - `multiple` — multiple rows can be selected

SelectionMode
—
separatedboolean—
size
'sm''md''lg'
—
stickyColumnboolean—
stickyHeader

Whether the header should be sticky

boolean
—
striped

Indicates whether the table rows should have alternating background colors

boolean
—
truncateboolean—
Every other prop of <table> is passed through to it. See MDN: <table>.

Table.Body

No props of its ownIt takes its content as children.
Every other prop of <tbody> is passed through to it. See MDN: <tbody>.

Table.CellDescription

No props of its ownIt takes its content as children.
Every other prop of <span> is passed through to it. See MDN: <span>.

Table.Cell

NameDescriptionDefault
align

Horizontal alignment of the cell content. Overrides the table-level value.

'center''left''right'
—
flushMargin

Removes horizontal padding. Overrides the table-level value.

boolean
—
placement

Vertical alignment of the cell content. Overrides the table-level value.

'bottom''top''middle'
—
truncate

Truncates overflowing content to a single line with an ellipsis. Overrides the table-level value. Requires a constrained column width (`table-fixed` class on the table with `w-*` classes on the headers, or a `max-w-*` class on the cell); without one, the forced single line widens the column to the full text width and can overflow the container.

boolean
—
Every other prop of <td> is passed through to it. See MDN: <td>.

Table.Foot

No props of its ownIt takes its content as children.
Every other prop of <tbody> is passed through to it. See MDN: <tbody>.

Table.Head

No props of its ownIt takes its content as children.
Every other prop of <tbody> is passed through to it. See MDN: <tbody>.

Table.Header

NameDescriptionDefault
align

Horizontal alignment of the cell content. Overrides the table-level value.

'center''left''right'
—
disabled

Disables the sort interaction visually and functionally. Only applies when sortable is true.

boolean
false
flushMargin

Removes horizontal padding. Overrides the table-level value.

boolean
—
onSort

Called when the user clicks to sort. Required when sortable is true.

(() => void)
—
sortable

Makes the column sortable — renders a sort button and sets aria-sort on the th.

boolean
—
sortAriaLabel

Accessible label for the sort button. When omitted, defaults to `` `Sort by ${column}` `` using the column's text content, or `'Sort by this column'` as a fallback.

string
—
sortDirection

Current sort direction. - `null` — sortable, not currently sorted - `'asc'` — sorted ascending - `'desc'` — sorted descending

SortDirection
—
truncate

Truncates overflowing content to a single line with an ellipsis. Overrides the table-level value. Requires a constrained column width (`table-fixed` class on the table with `w-*` classes on the headers, or a `max-w-*` class on the cell); without one, the forced single line widens the column to the full text width and can overflow the container.

boolean
—
Every other prop of <td> is passed through to it. See MDN: <td>.

Table.Row

NameDescriptionDefault
selected

Whether the row is in the selected state.

boolean
—
Every other prop of <tr> is passed through to it. See MDN: <tr>.

Accessibility

  • Keep Table.Head; header cells name the columns for screen readers.
  • A sortable header gets aria-sort and a labelled sort button (Sort by <column>). Pass sortAriaLabel when the header content is not plain text.
  • A selection checkbox needs aria-label naming the row (Select Acme Corp).
  • Row click is mouse-only. Put a real control (a Checkbox, a LinkButton, a Button) in the row so keyboard users can reach the same action.
  • With stickyHeader or stickyColumn the table becomes a tab stop so keyboard users can scroll it.
PartRendersDescription
Table<table>Structured content arranged in rows and columns.
Table.Body<tbody>The table section containing the body rows.
Table.CellDescription<span>A second line under a cell's label, e.g. a project's summary under its name. Use it in `md` and `lg` tables; an `sm` row has no room for two lines.
Table.Cell<td>A data cell with optional alignment and truncation.
Table.Foot<tbody>The table section containing summary rows.
Table.Head<tbody>The table section containing column headings.
Table.Header<td>A column header cell (`<th>`), optionally sortable.
Table.Row<tr>A data row with an optional selected state.
CustomerDueAmount
Acme CorpOct 2$1,200.00
GlobexOct 9$860.50
InitechOct 14$2,410.00
Total$4,470.50
tsx
import { Table } from '@/components/ui/wideset/table/Table';

<div className="w-[26rem] max-w-full">
  <Table>
    <Table.Head>
      <Table.Row>
        <Table.Header>Customer</Table.Header>
        <Table.Header>Due</Table.Header>
        <Table.Header align="right">Amount</Table.Header>
      </Table.Row>
    </Table.Head>
    <Table.Body>
      <Table.Row>
        <Table.Cell>Acme Corp</Table.Cell>
        <Table.Cell>Oct 2</Table.Cell>
        <Table.Cell align="right">$1,200.00</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.Cell>Globex</Table.Cell>
        <Table.Cell>Oct 9</Table.Cell>
        <Table.Cell align="right">$860.50</Table.Cell>
      </Table.Row>
      <Table.Row>
        <Table.Cell>Initech</Table.Cell>
        <Table.Cell>Oct 14</Table.Cell>
        <Table.Cell align="right">$2,410.00</Table.Cell>
      </Table.Row>
    </Table.Body>
    <Table.Foot>
      <Table.Row>
        <Table.Cell>Total</Table.Cell>
        <Table.Cell />
        <Table.Cell align="right">$4,470.50</Table.Cell>
      </Table.Row>
    </Table.Foot>
  </Table>
</div>

Appearance

Size
Separated
Striped

State

Hoverable rows