Data display

Table

Base table parts — sortable columns, selectable rows, header 40 on subtle, rows 48, horizontal rules only.

react-aria-componentslucide-react

Sortable and selectable

CompanyOwnerStageValue
LedgerlyJordan BlakeNegotiation$48,000
Fathom DataPriya RamanProposal$36,500
NorthpeakLeah MossDiscovery$22,000
PlinthSamuel OrtizDiscovery$12,000

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components lucide-react
  2. Create a table.tsx file and paste the following code into it.

    src/components/ui/table.tsx
    "use client";
    
    import { ArrowDown, ArrowUp, ChevronsUpDown } from "lucide-react";
    import type { ReactNode } from "react";
    import {
      Cell as AriaCell,
      type CellProps,
      Column as AriaColumn,
      type ColumnProps,
      Row as AriaRow,
      type RowProps,
      Table as AriaTable,
      TableBody as AriaTableBody,
      type TableBodyProps,
      TableHeader as AriaTableHeader,
      type TableHeaderProps,
      type TableProps,
    } from "react-aria-components";
    import { cx } from "@/utils/cx";
    
    /**
     * Base table, in the same language as every Vantu table: a rounded bg-subtle
     * header pill, 12px row padding and hairline separators between rows.
     * Wrap in <TableContainer> for horizontal scroll (and an optional panel).
     */
    export function TableContainer({ className, children }: { className?: string; children: ReactNode }) {
      return (
        <div className={cx("overflow-hidden", className)}>
          {/* `relative` contains React Aria's absolutely positioned hidden inputs. */}
          <div className="relative overflow-x-auto">{children}</div>
        </div>
      );
    }
    
    export function Table({ className, ...props }: Omit<TableProps, "className"> & { className?: string }) {
      return <AriaTable {...props} className={cx("w-full border-separate border-spacing-0 text-base", className)} />;
    }
    
    export function TableHeader<T extends object>({ className, ...props }: Omit<TableHeaderProps<T>, "className"> & { className?: string }) {
      return <AriaTableHeader {...props} className={cx("bg-subtle", className)} />;
    }
    
    export function Column({ className, children, ...props }: Omit<ColumnProps, "className" | "children"> & { className?: string; children: ReactNode }) {
      return (
        <AriaColumn
          {...props}
          className={cx(
            "h-10 px-3 text-left text-sm font-normal text-fg-muted outline-none first:rounded-l-[10px] last:rounded-r-[10px] data-focus-visible:shadow-[inset_0_0_0_2px_var(--color-accent)]",
            props.allowsSorting && "cursor-default data-hovered:text-fg",
            className,
          )}
        >
          {({ allowsSorting, sortDirection }) => (
            <span className="inline-flex items-center gap-1">
              {children}
              {allowsSorting &&
                (sortDirection === "ascending" ? (
                  <ArrowUp className="size-3 text-fg" aria-hidden />
                ) : sortDirection === "descending" ? (
                  <ArrowDown className="size-3 text-fg" aria-hidden />
                ) : (
                  <ChevronsUpDown className="size-3 text-fg-disabled" aria-hidden />
                ))}
            </span>
          )}
        </AriaColumn>
      );
    }
    
    export function TableBody<T extends object>({ className, ...props }: Omit<TableBodyProps<T>, "className"> & { className?: string }) {
      return <AriaTableBody {...props} className={className} />;
    }
    
    export function Row<T extends object>({ className, ...props }: Omit<RowProps<T>, "className"> & { className?: string }) {
      return (
        <AriaRow
          {...props}
          className={cx(
            "outline-none data-hovered:bg-subtle data-selected:bg-accent-soft/60 data-focus-visible:shadow-[inset_0_0_0_2px_var(--color-accent)] [&>td]:border-b [&>td]:border-line-subtle [&:last-child>td]:border-0",
            className,
          )}
        />
      );
    }
    
    export function Cell({ className, ...props }: Omit<CellProps, "className"> & { className?: string }) {
      return <AriaCell {...props} className={cx("px-3 py-3 text-fg outline-none data-focus-visible:shadow-[inset_0_0_0_2px_var(--color-accent)]", className)} />;
    }
  3. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.