Table

A hairline table with a soft header row.

RequestFormatStatus
northwind.iowebp200
globex.com/pricingpdfTimeout

Install

$ npx shadcn@latest add @nudgekit/table

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/table.json

Usage

usage.tsx
import { Table, TableHead, TableRow, TableHeader, TableCell } from "@/components/ui/table"

<Table>
  <TableHead>
    <TableRow><TableHeader>Request</TableHeader><TableHeader>Status</TableHeader></TableRow>
  </TableHead>
  <tbody>
    <TableRow><TableCell>northwind.io</TableCell><TableCell><Status>200</Status></TableCell></TableRow>
  </tbody>
</Table>

Do

  • Use Status inside cells for state.
  • Use mono for URLs and IDs.

Don't

  • Stripe rows with colour.
  • Use uppercase column heads.

Code

What the CLI writes into your project. It is yours to change.

components/ui/table.tsx
import * as React from "react";

import { cn } from "@/lib/utils";

function Table({ className, ...props }: React.TableHTMLAttributes<HTMLTableElement>) {
  return (
    <div className="w-full overflow-x-auto rounded-xl border border-border">
      <table data-slot="table" className={cn("w-full border-collapse text-sm", className)} {...props} />
    </div>
  );
}

function TableHead({ className, ...props }: React.HTMLAttributes<HTMLTableSectionElement>) {
  return <thead className={cn("bg-surface", className)} {...props} />;
}

function TableRow({ className, ...props }: React.HTMLAttributes<HTMLTableRowElement>) {
  return <tr className={cn("border-b border-border last:border-0", className)} {...props} />;
}

function TableHeader({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
  return <th className={cn("px-4 py-2.5 text-left text-[13px] font-medium text-muted-foreground", className)} {...props} />;
}

function TableCell({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
  return <td className={cn("px-4 py-3 text-foreground", className)} {...props} />;
}

export { Table, TableHead, TableRow, TableHeader, TableCell };