import { Badge, DataTable, type DataTableColumn } from "@replicas/ui";

type Invoice = { id: string; customer: string; status: string; variant: string; amount: number; date: Date };

const statuses = [
  { status: "Draft", variant: "default" },
  { status: "Pending", variant: "warning" },
  { status: "Sent", variant: "info" },
  { status: "Paid", variant: "success" },
  { status: "Overdue", variant: "error" },
];

const customers = [
  "Northwind Traders",
  "Bluebird Studio",
  "Fernway Labs",
  "Harbor & Co",
  "Oakline Media",
  "Pinecrest Health",
  "Quarry Design",
  "Redwood Supply",
  "Silverline Travel",
  "Tidewater Foods",
  "Upland Outdoors",
  "Willow Dental",
];

const invoices: Invoice[] = customers.map((customer, index) => ({
  id: `INV-${1042 - index * 3}`,
  customer,
  ...statuses[(index * 2) % statuses.length],
  amount: [120, 480, 960, 1500, 2400][(index * 3) % 5],
  date: new Date(2026, 10, 17 - index * 2),
}));

const columns: DataTableColumn<Invoice>[] = [
  { id: "id", header: "Invoice", value: (invoice) => invoice.id, sortable: true },
  { id: "customer", header: "Customer", value: (invoice) => invoice.customer, sortable: true },
  {
    id: "status",
    header: "Status",
    value: (invoice) => invoice.status,
    cell: (invoice) => <Badge variant={invoice.variant}>{invoice.status}</Badge>,
    sortable: true,
  },
  {
    id: "amount",
    header: "Amount",
    value: (invoice) => invoice.amount,
    cell: (invoice) => invoice.amount.toLocaleString("en-US", { style: "currency", currency: "USD" }),
    sortable: true,
    align: "end",
  },
  {
    id: "date",
    header: "Date",
    value: (invoice) => invoice.date,
    cell: (invoice) => invoice.date.toLocaleDateString("en-GB", { day: "numeric", month: "short" }),
    sortable: true,
    align: "end",
  },
];

export default function DataTableDemo() {
  return (
    <DataTable
      aria-label="Invoices"
      columns={columns}
      data={invoices}
      getRowId={(invoice) => invoice.id}
      selectable
      pageSize={5}
    />
  );
}

Examples

Sortable

function Sortable() {
  return <DataTable aria-label="Members" columns={memberColumns} data={members} getRowId={(member) => member.email} />;
}

Selectable

function Selectable() {
  return (
    <DataTable aria-label="Members" columns={memberColumns} data={members} getRowId={(member) => member.email} selectable />
  );
}

Empty

function Empty() {
  return (
    <DataTable
      aria-label="Members"
      columns={memberColumns}
      data={[]}
      getRowId={(member) => member.email}
      empty="No members match this filter."
    />
  );
}

Prompt

Copy Prompt hands your agent everything it needs to build the Data Table in the Linear style: the measured tokens, the CSS and the structure.

Show Prompt
# Linear Data Table

A table with sortable columns, row selection and pages, built on TanStack Table.

Build a Data Table in this project that looks and behaves like Linear's. Measured from the running Linear app (linear.app). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.

Fidelity: Derived from Linear's table, checkbox and pagination styles.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--bg-primary` | `lch(97.94% 0.5 282)` | `lch(5.52% 0.4 272)` |
| `--text-primary` | `lch(9.794% 0 282)` | `lch(100% 0 272)` |
| `--text-secondary` | `lch(19.588% 1.25 282)` | `lch(90.451% 1.2 272)` |
| `--text-tertiary` | `lch(39.176% 1.25 282)` | `lch(61.803% 1.2 272)` |
| `--text-quaternary` | `lch(64.64% 1.25 282)` | `lch(36.975% 1.2 272)` |
| `--accent` | `lch(53% 52.26 286.91)` | `lch(47.918% 59.303 288.421)` |
| `--focus-ring` | `#5e69d1` | `#5e69d1` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--font-weight-normal` | `450` | `450` |
| `--font-weight-medium` | `500` | `500` |
| `--speed-highlight-fade-in` | `0s` | `0s` |
| `--speed-highlight-fade-out` | `0.15s` | `0.15s` |

## CSS

Scoped under `[data-style="linear"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="linear"] {
  .ui-data-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .ui-data-table-sort {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-align: inherit;
    white-space: nowrap;
    cursor: default;
    transition: color var(--speed-highlight-fade-out);

    @media (hover: hover) {
      &:hover {
        color: var(--text-secondary);
        transition-duration: var(--speed-highlight-fade-in);
      }
    }

    &:focus-visible {
      outline: 1px solid var(--focus-ring);
      outline-offset: 2px;
    }

    &[data-sorted] {
      color: var(--text-secondary);
    }
  }

  .ui-data-table-sort-icon {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    color: var(--text-quaternary);
    transition: color var(--speed-highlight-fade-out);
  }

  .ui-data-table-sort:is(:hover, [data-sorted]) .ui-data-table-sort-icon {
    color: currentColor;
  }

  .ui-data-table .ui-table-head[data-align="end"],
  .ui-data-table .ui-table-cell[data-align="end"] {
    font-variant-numeric: tabular-nums;
    text-align: right;
  }

  .ui-data-table .ui-data-table-select {
    width: 14px;
    padding-right: 0;

    & > .ui-checkbox {
      display: flex;
    }
  }

  .ui-data-table[data-selectable] .ui-table-cell:first-child {
    color: inherit;
    font-weight: inherit;
  }

  .ui-data-table[data-selectable] .ui-table-cell:nth-child(2) {
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
  }

  .ui-data-table .ui-table-body .ui-table-row[data-selected] {
    background-color: color-mix(in lch, var(--accent) 6%, var(--bg-primary));

    @media (hover: hover) {
      &:hover {
        background-color: color-mix(in lch, var(--accent) 10%, var(--bg-primary));
      }
    }
  }

  .ui-data-table .ui-table-body .ui-table-row:has(.ui-data-table-empty) {
    background-color: transparent;
  }

  .ui-data-table .ui-table-cell.ui-data-table-empty {
    height: 120px;
    color: var(--text-tertiary);
    font-weight: var(--font-weight-normal);
    text-align: center;
  }

  .ui-data-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 28px;
    padding: 0 12px;
  }

  .ui-data-table-summary {
    color: var(--text-tertiary);
    font-size: var(--font-size-mini);
    font-variant-numeric: tabular-nums;
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
"use client";

import {
  type ColumnDef,
  createPaginatedRowModel,
  createSortedRowModel,
  type RowData,
  rowPaginationFeature,
  rowSelectionFeature,
  rowSortingFeature,
  sortFn_alphanumeric,
  sortFn_basic,
  sortFn_datetime,
  tableFeatures,
  useTable,
} from "@tanstack/react-table";
import { type ReactNode, useEffect, useMemo } from "react";
import { Checkbox } from "./checkbox";
import { Pagination } from "./pagination";
import { Table } from "./table";
import { join } from "./utils";

const features = tableFeatures({
  rowSortingFeature,
  rowSelectionFeature,
  rowPaginationFeature,
  sortedRowModel: createSortedRowModel(),
  paginatedRowModel: createPaginatedRowModel(),
  sortFns: { alphanumeric: sortFn_alphanumeric, basic: sortFn_basic, datetime: sortFn_datetime },
});

export type DataTableColumn<T> = {
  id: string;
  header: ReactNode;
  value?: (row: T) => string | number | Date | null | undefined;
  cell?: (row: T) => ReactNode;
  sortable?: boolean;
  align?: "start" | "end";
};

export type DataTableProps<T> = {
  columns: DataTableColumn<T>[];
  data: T[];
  getRowId: (row: T) => string;
  selectable?: boolean;
  onSelectionChange?: (ids: string[]) => void;
  pageSize?: number;
  empty?: ReactNode;
  variant?: string;
  className?: string;
  "aria-label"?: string;
};

const SELECT = "__select";

const icon = (d: string) => (
  <svg className="ui-data-table-sort-icon" viewBox="0 0 16 16" fill="none" aria-hidden>
    <path d={d} stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
  </svg>
);

const sortIcons = {
  none: icon("M5 6.5 8 3.5l3 3M5 9.5l3 3 3-3"),
  asc: icon("M8 12.5v-9M4.5 7 8 3.5 11.5 7"),
  desc: icon("M8 3.5v9M4.5 9 8 12.5 11.5 9"),
};

export function DataTable<T extends RowData>({
  columns,
  data,
  getRowId,
  selectable,
  onSelectionChange,
  pageSize,
  empty = "No results.",
  variant,
  className,
  "aria-label": ariaLabel,
}: DataTableProps<T>) {
  const byId = useMemo(() => new Map(columns.map((column) => [column.id, column])), [columns]);
  const defs = useMemo<ColumnDef<typeof features, T>[]>(
    () => [
      ...(selectable ? [{ id: SELECT, enableSorting: false }] : []),
      ...columns.map((column) => ({
        id: column.id,
        accessorFn: column.value,
        enableSorting: Boolean(column.sortable && column.value),
      })),
    ],
    [columns, selectable],
  );

  const table = useTable({
    features,
    columns: defs,
    data,
    getRowId,
    enableRowSelection: Boolean(selectable),
    manualPagination: !pageSize,
    initialState: { pagination: { pageIndex: 0, pageSize: pageSize ?? 10 } },
  });

  const { rowSelection, pagination } = table.state;
  const selected = Object.keys(rowSelection).filter((id) => rowSelection[id]);
  const selectedKey = selected.join(",");

  useEffect(() => {
    onSelectionChange?.(selectedKey ? selectedKey.split(",") : []);
  }, [selectedKey, onSelectionChange]);

  const rows = table.getRowModel().rows;
  const total = data.length;
  const pageCount = pageSize ? table.getPageCount() : 1;
  const first = pagination.pageIndex * pagination.pageSize + 1;
  const last = Math.min(first + rows.length - 1, total);

  return (
    <div className={join("ui-data-table", className)} data-selectable={selectable || undefined}>
      <Table.Root variant={variant} aria-label={ariaLabel}>
        <Table.Header>
          {table.getHeaderGroups().map((group) => (
            <Table.Row key={group.id}>
              {group.headers.map((header) => {
                if (header.id === SELECT) {
                  return (
                    <Table.Head key={header.id} className="ui-data-table-select">
                      <Checkbox
                        aria-label="Select all rows"
                        checked={table.getIsAllPageRowsSelected()}
                        indeterminate={table.getIsSomePageRowsSelected()}
                        onCheckedChange={(checked) => table.toggleAllPageRowsSelected(checked)}
                      />
                    </Table.Head>
                  );
                }
                const column = byId.get(header.id);
                const sorted = header.column.getIsSorted();
                return (
                  <Table.Head
                    key={header.id}
                    data-align={column?.align}
                    aria-sort={
                      header.column.getCanSort()
                        ? sorted === "asc"
                          ? "ascending"
                          : sorted === "desc"
                            ? "descending"
                            : "none"
                        : undefined
                    }
                  >
                    {header.column.getCanSort() ? (
                      <button
                        type="button"
                        className="ui-data-table-sort"
                        data-sorted={sorted || undefined}
                        onClick={header.column.getToggleSortingHandler()}
                      >
                        {column?.align === "end" && sortIcons[sorted || "none"]}
                        {column?.header}
                        {column?.align !== "end" && sortIcons[sorted || "none"]}
                      </button>
                    ) : (
                      column?.header
                    )}
                  </Table.Head>
                );
              })}
            </Table.Row>
          ))}
        </Table.Header>
        <Table.Body>
          {rows.length === 0 ? (
            <Table.Row>
              <Table.Cell className="ui-data-table-empty" colSpan={defs.length}>
                {empty}
              </Table.Cell>
            </Table.Row>
          ) : (
            rows.map((row) => (
              <Table.Row key={row.id} data-selected={row.getIsSelected() || undefined}>
                {row.getAllCells().map((cell) => {
                  if (cell.column.id === SELECT) {
                    return (
                      <Table.Cell key={cell.id} className="ui-data-table-select">
                        <Checkbox
                          aria-label="Select row"
                          checked={row.getIsSelected()}
                          onCheckedChange={(checked) => row.toggleSelected(checked)}
                        />
                      </Table.Cell>
                    );
                  }
                  const column = byId.get(cell.column.id);
                  const value = column?.value?.(row.original);
                  return (
                    <Table.Cell key={cell.id} data-align={column?.align}>
                      {column?.cell ? column.cell(row.original) : value instanceof Date ? value.toLocaleDateString() : value}
                    </Table.Cell>
                  );
                })}
              </Table.Row>
            ))
          )}
        </Table.Body>
      </Table.Root>
      {(selectable || pageCount > 1) && (
        <div className="ui-data-table-footer">
          <span className="ui-data-table-summary">
            {selectable && selected.length > 0
              ? `${selected.length} of ${total} selected`
              : total === 0
                ? "0 rows"
                : `${first}–${last} of ${total}`}
          </span>
          {pageCount > 1 && (
            <Pagination
              page={pagination.pageIndex + 1}
              pageCount={pageCount}
              onPageChange={(page) => table.setPageIndex(page - 1)}
            />
          )}
        </div>
      )}
    </div>
  );
}
```

## Example

```tsx
import { Badge, DataTable, type DataTableColumn } from "@replicas/ui";

type Invoice = { id: string; customer: string; status: string; variant: string; amount: number; date: Date };

const statuses = [
  { status: "Draft", variant: "default" },
  { status: "Pending", variant: "warning" },
  { status: "Sent", variant: "info" },
  { status: "Paid", variant: "success" },
  { status: "Overdue", variant: "error" },
];

const customers = [
  "Northwind Traders",
  "Bluebird Studio",
  "Fernway Labs",
  "Harbor & Co",
  "Oakline Media",
  "Pinecrest Health",
  "Quarry Design",
  "Redwood Supply",
  "Silverline Travel",
  "Tidewater Foods",
  "Upland Outdoors",
  "Willow Dental",
];

const invoices: Invoice[] = customers.map((customer, index) => ({
  id: `INV-${1042 - index * 3}`,
  customer,
  ...statuses[(index * 2) % statuses.length],
  amount: [120, 480, 960, 1500, 2400][(index * 3) % 5],
  date: new Date(2026, 10, 17 - index * 2),
}));

const columns: DataTableColumn<Invoice>[] = [
  { id: "id", header: "Invoice", value: (invoice) => invoice.id, sortable: true },
  { id: "customer", header: "Customer", value: (invoice) => invoice.customer, sortable: true },
  {
    id: "status",
    header: "Status",
    value: (invoice) => invoice.status,
    cell: (invoice) => <Badge variant={invoice.variant}>{invoice.status}</Badge>,
    sortable: true,
  },
  {
    id: "amount",
    header: "Amount",
    value: (invoice) => invoice.amount,
    cell: (invoice) => invoice.amount.toLocaleString("en-US", { style: "currency", currency: "USD" }),
    sortable: true,
    align: "end",
  },
  {
    id: "date",
    header: "Date",
    value: (invoice) => invoice.date,
    cell: (invoice) => invoice.date.toLocaleDateString("en-GB", { day: "numeric", month: "short" }),
    sortable: true,
    align: "end",
  },
];

export default function DataTableDemo() {
  return (
    <DataTable
      aria-label="Invoices"
      columns={columns}
      data={invoices}
      getRowId={(invoice) => invoice.id}
      selectable
      pageSize={5}
    />
  );
}
```

## Foundations

The rest of the Linear style, as a skill: https://replicas.raphaelsalaja.com/skills/linear/SKILL.md