Skip to content
Shaken UI
Sign in

Table

Save

Semantic table parts with hairline rows, right-aligned tabular numbers, a framed option, and a header that can stay pinned while the body scrolls.

Category
Data display
Version
0.1.0
Frameworks
Next.js, Vite + React
Styling
Tailwind CSS v4

Preview

Table preview
Usage invoices for October 2026, by workspace.
InvoiceWorkspaceTokensRunsAmount
INV-2041Acme Docs18,420,0001,284$412.60
INV-2042Support triage6,905,0003,117$158.20
INV-2043Release notes bot1,210,50096$27.45
INV-2044Data pipeline42,870,000512$961.00
Total$1,559.25

Installation

npx @shakenui/cli add table

Review the plan first. A dry run lists every file and package without changing anything:

npx @shakenui/cli add table --dry-run

Usage

table-example.tsx
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@/components/shaken/ui/table";

const invoices = [
  { id: "INV-2041", workspace: "Acme Docs", period: "Oct 2026", tokens: 18_420_000, runs: 1_284, amount: 412.6 },
  { id: "INV-2042", workspace: "Support triage", period: "Oct 2026", tokens: 6_905_000, runs: 3_117, amount: 158.2 },
  { id: "INV-2043", workspace: "Release notes bot", period: "Oct 2026", tokens: 1_210_500, runs: 96, amount: 27.45 },
  { id: "INV-2044", workspace: "Data pipeline", period: "Oct 2026", tokens: 42_870_000, runs: 512, amount: 961.0 },
];

const number = new Intl.NumberFormat("en-US");
const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });

export default function TableExample() {
  const total = invoices.reduce((sum, invoice) => sum + invoice.amount, 0);
  return (
    <Table framed containerClassName="w-full max-w-2xl">
      <TableCaption>Usage invoices for October 2026, by workspace.</TableCaption>
      <TableHeader>
        <TableRow>
          <TableHead>Invoice</TableHead>
          <TableHead>Workspace</TableHead>
          <TableHead numeric>Tokens</TableHead>
          <TableHead numeric>Runs</TableHead>
          <TableHead numeric>Amount</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {invoices.map((invoice) => (
          <TableRow key={invoice.id}>
            <TableCell className="font-mono text-xs text-zinc-600 dark:text-zinc-400">{invoice.id}</TableCell>
            <TableCell className="font-medium whitespace-nowrap">{invoice.workspace}</TableCell>
            <TableCell numeric className="text-zinc-600 dark:text-zinc-400">
              {number.format(invoice.tokens)}
            </TableCell>
            <TableCell numeric className="text-zinc-600 dark:text-zinc-400">
              {number.format(invoice.runs)}
            </TableCell>
            <TableCell numeric>{money.format(invoice.amount)}</TableCell>
          </TableRow>
        ))}
      </TableBody>
      <TableFooter>
        <TableRow>
          <TableCell colSpan={4}>Total</TableCell>
          <TableCell numeric>{money.format(total)}</TableCell>
        </TableRow>
      </TableFooter>
    </Table>
  );
}

API

PropTypeDefaultDescription
Table stickyHeaderbooleanfalsePins the header row while the body scrolls. Give containerClassName a max height to scroll in.
Table framedbooleanfalseDraws the container hairline, radius, and surface around the table.
Table density"default" | "compact""default"Row height: 44px or 36px.
Table containerClassNamestring—Classes for the scrolling wrapper; className styles the <table>.
TableHead / TableCell numericbooleanfalseRight-aligns the cell and uses tabular figures so digits line up.
TableHead / TableCell align"start" | "center" | "end"—Horizontal alignment. numeric implies end.
TableRow selectedbooleanfalseApplies the selected tint and aria-selected.
TableHeader / TableBody / TableFooter / TableCaptionnative thead / tbody / tfoot / caption props—Semantic parts; the caption names the table and renders below it.

Accessibility

  • Renders native table, thead, tbody, tfoot, th, td, and caption elements, so screen readers announce rows, columns, and headers.
  • TableHead defaults to scope="col".
  • TableCaption names the table; hide it visually with className="sr-only" when a heading already describes it.
  • The wrapper scrolls sideways on narrow screens instead of squeezing columns.
  • Rows separate by hairlines rather than color alone; the hover tint is decorative.

Files

Installed into src/components/shaken, or components/shaken when the project has no src directory.

  • src/components/shaken/ui/table.tsxtable
  • npm packages: noneReact and Tailwind CSS v4 required

Source

The exact source the CLI installs, from /r/items/react/table/0.1.0.json.

ui/table.tsxShow
ui/table.tsx
import type { ComponentProps } from "react";

function cx(...classes: (string | false | null | undefined)[]) {
  return classes.filter(Boolean).join(" ");
}

export interface TableProps extends ComponentProps<"table"> {
  /**
   * Keeps the header row pinned while the body scrolls. Give the table a height to scroll in,
   * for example `containerClassName="max-h-80"`.
   */
  stickyHeader?: boolean;
  /** Draws the container hairline, radius, and surface around the table. */
  framed?: boolean;
  /** Row height. `compact` suits dense logs and side panels. */
  density?: "default" | "compact";
  /** Classes for the scrolling wrapper. `className` styles the `<table>` itself. */
  containerClassName?: string;
}

/**
 * A semantic `<table>` inside a scrolling wrapper. Rows are separated by hairlines, never by
 * zebra fills. The wrapper scrolls sideways on narrow screens instead of squeezing columns.
 */
export function Table({
  stickyHeader = false,
  framed = false,
  density = "default",
  containerClassName,
  className,
  ...props
}: TableProps) {
  return (
    <div
      data-slot="table-container"
      className={cx(
        "relative w-full overflow-auto",
        framed &&
          cx(
            "rounded-xl border border-zinc-950/10 bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)]",
            "dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]",
          ),
        containerClassName,
      )}
    >
      <table
        data-sticky={stickyHeader || undefined}
        data-density={density}
        data-framed={framed || undefined}
        className={cx(
          // Separate borders so hairlines stay attached to cells when the header sticks.
          "group/table w-full border-separate border-spacing-0 text-left text-sm text-zinc-950 dark:text-white",
          className,
        )}
        {...props}
      />
    </div>
  );
}

/** The `<thead>`. Holds one or more rows of `TableHead` cells. */
export function TableHeader({ className, ...props }: ComponentProps<"thead">) {
  return <thead className={cx("[&>tr]:hover:bg-transparent dark:[&>tr]:hover:bg-transparent", className)} {...props} />;
}

/** The `<tbody>`. The last row drops its bottom hairline so it meets the container edge cleanly. */
export function TableBody({ className, ...props }: ComponentProps<"tbody">) {
  return (
    <tbody
      className={cx(
        "group-data-[framed]/table:[&>tr:last-child>*]:border-b-0",
        className,
      )}
      {...props}
    />
  );
}

/** The `<tfoot>`, for totals. Set off from the body by a stronger hairline. */
export function TableFooter({ className, ...props }: ComponentProps<"tfoot">) {
  return (
    <tfoot
      className={cx(
        "font-medium [&>tr>*]:border-b-0 [&>tr:first-child>*]:border-t [&>tr:first-child>*]:border-zinc-950/10 dark:[&>tr:first-child>*]:border-white/10",
        "[&>tr]:hover:bg-transparent dark:[&>tr]:hover:bg-transparent",
        className,
      )}
      {...props}
    />
  );
}

export interface TableRowProps extends ComponentProps<"tr"> {
  /** Marks the row as selected: a tint and `aria-selected`. */
  selected?: boolean;
}

/** A `<tr>` with a hairline under each cell and a quiet hover tint. */
export function TableRow({ selected, className, ...props }: TableRowProps) {
  return (
    <tr
      data-selected={selected || undefined}
      aria-selected={selected}
      className={cx(
        "[&>*]:border-b [&>*]:border-zinc-950/[0.07] dark:[&>*]:border-white/[0.08]",
        "transition-[background-color] duration-150 ease-out motion-reduce:transition-none",
        "hover:bg-zinc-950/[0.025] dark:hover:bg-white/[0.04]",
        "data-[selected]:bg-zinc-950/[0.045] dark:data-[selected]:bg-white/[0.07]",
        className,
      )}
      {...props}
    />
  );
}

type Align = "start" | "center" | "end";

const alignment: Record<Align, string> = {
  start: "text-left",
  center: "text-center",
  end: "text-right",
};

export interface TableCellProps extends Omit<ComponentProps<"td">, "align"> {
  /** Right-aligns the cell and uses tabular figures, so digits line up down the column. */
  numeric?: boolean;
  /** Horizontal alignment. `numeric` implies `end`. */
  align?: Align;
}

export interface TableHeadProps extends Omit<ComponentProps<"th">, "align"> {
  /** Right-aligns the header to sit over a numeric column. */
  numeric?: boolean;
  /** Horizontal alignment. `numeric` implies `end`. */
  align?: Align;
}

/** A header cell (`<th>`). Sentence case meta text; sticks to the top when the table has `stickyHeader`. */
export function TableHead({ numeric = false, align, scope = "col", className, ...props }: TableHeadProps) {
  return (
    <th
      scope={scope}
      className={cx(
        "h-9 px-3 align-middle text-xs font-medium whitespace-nowrap text-zinc-500 group-data-[density=compact]/table:h-8",
        "border-b border-zinc-950/10 dark:border-white/10",
        "first:pl-4 last:pr-4",
        "group-data-[sticky]/table:sticky group-data-[sticky]/table:top-0 group-data-[sticky]/table:z-10",
        "group-data-[sticky]/table:bg-white dark:group-data-[sticky]/table:bg-black",
        alignment[align ?? (numeric ? "end" : "start")],
        numeric && "tabular-nums",
        className,
      )}
      {...props}
    />
  );
}

/** A body cell (`<td>`). */
export function TableCell({ numeric = false, align, className, ...props }: TableCellProps) {
  return (
    <td
      className={cx(
        "h-11 px-3 align-middle group-data-[density=compact]/table:h-9",
        "first:pl-4 last:pr-4",
        alignment[align ?? (numeric ? "end" : "start")],
        numeric && "tabular-nums",
        className,
      )}
      {...props}
    />
  );
}

/** The `<caption>`. Names the table for assistive technology; rendered below it as meta text. */
export function TableCaption({ className, ...props }: ComponentProps<"caption">) {
  return <caption className={cx("caption-bottom px-4 py-3 text-left text-xs text-zinc-500", className)} {...props} />;
}