Skip to content

Data Table

Typed generic table with hairline rows, sortable headers, optional row selection (select-all with indeterminate state) and a floating bulk-action bar. Custom cells, mobile column hiding, empty state.

minimal/ui/data-table
Open ↗

Source

"use client";

import { useId, useMemo, useState, type ReactNode } from "react";
import { ChevronDown, ChevronUp, ChevronsUpDown } from "lucide-react";
import { cn } from "@/lib/utils";

export interface DataTableColumn<T> {
  key: string;
  header: string;
  cell?: (row: T) => ReactNode;
  sortValue?: (row: T) => string | number;
  align?: "left" | "right";
  hideOnMobile?: boolean;
  /** Tailwind width class, e.g. "w-32". */
  width?: string;
}

export interface DataTableProps<T> {
  columns: DataTableColumn<T>[];
  rows: T[];
  getRowId: (row: T) => string;
  /** Accessible name of the table (rendered as a visually hidden caption). */
  label: string;
  /** Enables row checkboxes; called with the selected ids. */
  onSelectionChange?: (ids: string[]) => void;
  /** Content of the bar shown when rows are selected (receives the ids). */
  bulkActions?: (ids: string[]) => ReactNode;
  emptyState?: ReactNode;
  initialSort?: { key: string; direction: "asc" | "desc" };
  className?: string;
}

export function DataTable<T>({
  columns,
  rows,
  getRowId,
  label,
  onSelectionChange,
  bulkActions,
  emptyState = "No results.",
  initialSort,
  className,
}: DataTableProps<T>) {
  const [sort, setSort] = useState(initialSort ?? null);
  const [selected, setSelected] = useState<string[]>([]);
  const selectable = Boolean(onSelectionChange || bulkActions);
  const baseId = useId();

  const sorted = useMemo(() => {
    const col = sort && columns.find((c) => c.key === sort.key);
    if (!sort || !col?.sortValue) return rows;
    const get = col.sortValue;
    const f = sort.direction === "asc" ? 1 : -1;
    return [...rows].sort((a, b) => (get(a) < get(b) ? -f : get(a) > get(b) ? f : 0));
  }, [rows, columns, sort]);

  const update = (next: string[]) => {
    setSelected(next);
    onSelectionChange?.(next);
  };
  const allIds = sorted.map(getRowId);
  const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
  const someSelected = selected.length > 0 && !allSelected;

  return (
    <div className={cn("da-stroke relative overflow-hidden rounded-da-lg bg-da-surface text-da-surface-fg", className)}>
      <div className="overflow-x-auto">
        <table className="w-full text-sm">
          <caption className="sr-only">{label}</caption>
          <thead className="border-b border-da-border bg-da-surface-2/60 text-[13px] text-da-muted-fg">
            <tr>
              {selectable && (
                <th scope="col" className="w-10 pl-4">
                  <input
                    type="checkbox"
                    aria-label="Select all rows"
                    checked={allSelected}
                    ref={(el) => {
                      if (el) el.indeterminate = someSelected;
                    }}
                    onChange={() => update(allSelected ? [] : allIds)}
                    className="da-focus size-3.5 accent-da-primary"
                  />
                </th>
              )}
              {columns.map((col) => {
                const active = sort?.key === col.key;
                return (
                  <th
                    key={col.key}
                    scope="col"
                    aria-sort={active ? (sort.direction === "asc" ? "ascending" : "descending") : col.sortValue ? "none" : undefined}
                    className={cn("h-9 px-4 font-medium whitespace-nowrap", col.align === "right" ? "text-right" : "text-left", col.hideOnMobile && "hidden md:table-cell", col.width)}
                  >
                    {col.sortValue ? (
                      <button
                        type="button"
                        onClick={() =>
                          setSort((s) => (s?.key !== col.key ? { key: col.key, direction: "asc" } : s.direction === "asc" ? { key: col.key, direction: "desc" } : null))
                        }
                        className={cn("da-focus da-transition -mx-1 inline-flex items-center gap-1 rounded-da-sm px-1 hover:text-da-fg", active && "text-da-fg", col.align === "right" && "flex-row-reverse")}
                      >
                        {col.header}
                        {active ? (
                          sort.direction === "asc" ? (
                            <ChevronUp aria-hidden className="size-3.5" />
                          ) : (
                            <ChevronDown aria-hidden className="size-3.5" />
                          )
                        ) : (
                          <ChevronsUpDown aria-hidden className="size-3.5 opacity-40" />
                        )}
                      </button>
                    ) : (
                      col.header
                    )}
                  </th>
                );
              })}
            </tr>
          </thead>
          <tbody className="divide-y divide-da-border">
            {sorted.length === 0 ? (
              <tr>
                <td colSpan={columns.length + (selectable ? 1 : 0)} className="px-4 py-14 text-center text-da-muted-fg">
                  {emptyState}
                </td>
              </tr>
            ) : (
              sorted.map((row) => {
                const id = getRowId(row);
                const isSelected = selected.includes(id);
                return (
                  <tr key={id} aria-selected={selectable ? isSelected : undefined} className={cn("da-transition hover:bg-da-fg/[0.025]", isSelected && "bg-da-accent/60 hover:bg-da-accent/70")}>
                    {selectable && (
                      <td className="pl-4">
                        <input
                          id={`${baseId}-${id}`}
                          type="checkbox"
                          aria-label={`Select row ${id}`}
                          checked={isSelected}
                          onChange={() => update(isSelected ? selected.filter((s) => s !== id) : [...selected, id])}
                          className="da-focus size-3.5 accent-da-primary"
                        />
                      </td>
                    )}
                    {columns.map((col) => (
                      <td key={col.key} className={cn("h-11 px-4", col.align === "right" && "text-right", col.hideOnMobile && "hidden md:table-cell")}>
                        {col.cell ? col.cell(row) : String((row as Record<string, unknown>)[col.key] ?? "")}
                      </td>
                    ))}
                  </tr>
                );
              })
            )}
          </tbody>
        </table>
      </div>

      {bulkActions && selected.length > 0 && (
        <div
          role="region"
          aria-label="Bulk actions"
          className="da-stroke absolute bottom-3 left-1/2 flex -translate-x-1/2 items-center gap-3 rounded-da-md bg-da-surface py-1.5 pr-1.5 pl-3 text-sm shadow-da-lg transition-[opacity,translate] duration-(--da-duration) starting:translate-y-2 starting:opacity-0"
        >
          <span className="whitespace-nowrap text-da-muted-fg">{selected.length} selected</span>
          {bulkActions(selected)}
        </div>
      )}
    </div>
  );
}

export default DataTable;

modules/minimal/ui/data-table/index.tsx

Props

PropTypeDefaultDescription
columns*DataTableColumn<T>[]—{ key, header, cell?, sortValue?, align?, hideOnMobile?, width? }.
rows*T[]—Data rows.
getRowId*(row: T) => string—Stable id per row.
label*string—Accessible name (sr-only caption).
onSelectionChange(ids: string[]) => void—Enables selection and reports selected ids.
bulkActions(ids: string[]) => ReactNode—Floating action bar content when rows are selected (also enables selection).
emptyStateReactNode"No results."Rendered when rows is empty.
initialSort{ key: string; direction: "asc" | "desc" }—Initial sort.
classNamestring—Classes on the wrapper.

Other table variants in Minimal

Table in other art directions

Data Table

Typed generic table with a yellow caption bar + toolbar slot, ruled rows, sortable columns (asc → desc → none), custom cell renderers, mobile column hiding, empty state and optional row click.

BrutalistTable

Expandable Table

Table with expandable rows: a ruled chevron square per row reveals a detail row underneath; the open row floods yellow. Single or multiple open rows.

BrutalistTable

Leaderboard Table

Ranked list with ink header, colored podium squares for the top 3, proportional background bars behind each row, rank-change chips (▲/▼) and big tabular values. Sorts by value automatically.

BrutalistTable

Simple Table

Server-safe static table: uppercase caption, ink header row with column rules, zebra rows, right-aligned mono numeric columns and an optional yellow totals footer.

BrutalistTable

Action Items Table

Action items table with Open / Done / All filter pills and counts, gradient checkboxes that strike tasks through, owner, due chip (overdue in red) and source meeting; empty state.

GlassTable

Data Table

Frosted table panel with title, description, pill search field and actions slot; rows are separated translucent rounded strips that brighten on hover. Typed generic columns, sorting, mobile hiding, empty state.

GlassTable

Meetings Table

Recent meetings glass table: title with gradient video icon and platform, date, mono duration, participant avatar stack and a recap status pill (ready, processing, private).

GlassTable

Usage Table

Team usage glass table: member, inline gradient bar of recorded hours relative to the top member, meetings count and hours saved, with a tinted totals row.

GlassTable

Changelog Table

Release log laid out as a table: mono version + ISO date column, a square type tag (New in signal color, Improved outlined, Fixed gray) and dash-listed notes; hairline rows.

Mono CleanTable

Data Table

Analytics table in pure typography: mono headers that sort (↑/↓ glyph, aria-sort), hairline rows, tabular numbers, inline hairline bars for share of views, and an ink total row.

Mono CleanTable

Projects Table

Studio project index (the classic portfolio list): large titles with client, discipline and year in mono columns; each row is one link that inverts to ink on hover with an ↗.

Mono CleanTable

Sites Table

Sites dashboard table: name + domain link, dot status in mono, template, updated time and a “…” Radix dropdown (open, duplicate, archive); hairline rows.

Mono CleanTable

Approvals Table

Bill approval queue: vendor + requester, category, mono amount and inline Approve / Reject buttons that turn the row into a decided state (with Undo); pending count in the header.

Neo CorporateTable

Data Table

Customer data table: sortable headers (aria-sort), row checkboxes with select-all (indeterminate), bulk-action bar when rows are selected, mono amounts and pagination.

Neo CorporateTable

Invoice Table

Receivables table with status pills, days-late aging text, mono amounts, a totals footer and a per-row Radix dropdown (view, send reminder, duplicate, void).

Neo CorporateTable

Ledger Table

General-ledger table grouped by date: journal ref and memo, GL account, debit/credit columns in mono, credits indented, and balanced totals row with a “Balanced” check.

Neo CorporateTable

Actions Table

Reduction plan table: round checkboxes mark actions done (row softens), owner and due date, mono savings, and a progress header showing tonnes secured toward the target.

Organic SoftTable

Emissions Table

Emissions by category: rounded cream table with scope leaf chips, inline sage share bars behind the tonnes, mono figures, colored year-over-year change and a total row.

Organic SoftTable

Monthly Table

Month × scope heat table: each cell tinted by intensity along a sand→sage→forest scale with mono values; row totals and a legend; readable without color.

Organic SoftTable

Supplier Table

Supplier engagement table: filter pills by status, arch avatars, share of footprint, status pill and 3-dot data quality meter, with a per-row “Nudge” pill that turns into “Sent”.

Organic SoftTable

Activity Table

Activity log table: kind icon in a pastel circle, emoji avatar and sentence (“Ana completed …”), board chip and relative time; rows highlight softly on hover.

Soft FlatTable

Simple Table

Plain friendly data table in a rounded white card: soft header well, roomy rows, gentle zebra and right-aligned numbers; generic columns and rows props.

Soft FlatTable

Task Table

“My tasks” table where each row is a soft rounded strip: round done checkbox, title (struck when done), pastel board chip, owner initial avatar and due chip (red when overdue).

Soft FlatTable

Workload Table

Team workload heat table: a row per person (emoji + name), one rounded cell per weekday tinted mint → butter → peach by number of tasks, with a legend.

Soft FlatTable