Table
Presents related records in a responsive, scan-friendly grid.
Preview
Example code
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV-1048 | Paid | Visa · 4242 | $248.00 |
| INV-1047 | Pending | Bank transfer | $96.00 |
| INV-1046 | Paid | Mastercard · 9012 | $312.00 |
| Total | $656.00 | ||
Usage
tsx
import {
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from "earthling-ui/table";
export function Example() {
return (
<>
<Table>
<TableCaption>Recent invoices</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead numeric>Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>INV-1048</TableCell>
<TableCell numeric>$248.00</TableCell>
</TableRow>
</TableBody>
<TableFooter>
<TableRow>
<TableCell>Total</TableCell>
<TableCell numeric>$248.00</TableCell>
</TableRow>
</TableFooter>
</Table>
</>
);
}
- Use TableHead for column labels and TableCaption to give the dataset a concise name.
- Set numeric on both the header and cells of numeric columns for right alignment and tabular figures.
- Keep cell content concise; move dense detail into a dedicated view when horizontal scanning becomes difficult.
Installation
Start with the project setup for React and Tailwind CSS 4. Both paths use the same component and theme.
Import package
Own the source
bash
npm install earthling-uiUse the component import shown above. Package updates keep the implementation current.
API reference
Declarations from the current library build, including inherited primitive props. Playground controls above show selected options; they are not the complete API.
tsx
// Generated by dts-bundle-generator v9.5.1
import { ComponentProps } from 'react';
export declare const Table: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, "ref"> & import("react").RefAttributes<HTMLTableElement>>;
export declare const TableHeader: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & import("react").RefAttributes<HTMLTableSectionElement>>;
export declare const TableBody: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & import("react").RefAttributes<HTMLTableSectionElement>>;
export declare const TableFooter: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & import("react").RefAttributes<HTMLTableSectionElement>>;
export declare const TableRow: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, "ref"> & import("react").RefAttributes<HTMLTableRowElement>>;
export interface TableHeadProps extends ComponentProps<"th"> {
numeric?: boolean;
}
export declare const TableHead: import("react").ForwardRefExoticComponent<Omit<TableHeadProps, "ref"> & import("react").RefAttributes<HTMLTableCellElement>>;
export interface TableCellProps extends ComponentProps<"td"> {
numeric?: boolean;
}
export declare const TableCell: import("react").ForwardRefExoticComponent<Omit<TableCellProps, "ref"> & import("react").RefAttributes<HTMLTableCellElement>>;
export declare const TableCaption: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & import("react").RefAttributes<HTMLTableCaptionElement>>;
export {};Runtime dependencies: cnfast.
Source
Use the eject command to copy this implementation with its required helpers and project-specific imports.
View Table implementation
tsx
"use client";
import { forwardRef, type ComponentProps } from "react";
import { cn } from "@/utils/cn";
const Table = forwardRef<HTMLTableElement, ComponentProps<"table">>(
({ className, ...props }, ref) => (
<div className="relative w-full overflow-auto">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
),
);
Table.displayName = "Table";
const TableHeader = forwardRef<
HTMLTableSectionElement,
ComponentProps<"thead">
>(({ className, ...props }, ref) => (
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
));
TableHeader.displayName = "TableHeader";
const TableBody = forwardRef<HTMLTableSectionElement, ComponentProps<"tbody">>(
({ className, ...props }, ref) => (
<tbody
ref={ref}
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
),
);
TableBody.displayName = "TableBody";
const TableFooter = forwardRef<
HTMLTableSectionElement,
ComponentProps<"tfoot">
>(({ className, ...props }, ref) => (
<tfoot
ref={ref}
className={cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className,
)}
{...props}
/>
));
TableFooter.displayName = "TableFooter";
const TableRow = forwardRef<HTMLTableRowElement, ComponentProps<"tr">>(
({ className, ...props }, ref) => (
<tr
ref={ref}
className={cn(
"border-b hover:bg-muted/50 data-[state=selected]:bg-muted",
className,
)}
{...props}
/>
),
);
TableRow.displayName = "TableRow";
export interface TableHeadProps extends ComponentProps<"th"> {
numeric?: boolean;
}
const TableHead = forwardRef<HTMLTableCellElement, TableHeadProps>(
({ className, numeric = false, ...props }, ref) => (
<th
ref={ref}
data-numeric={numeric || undefined}
className={cn(
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
numeric && "text-right tabular-nums",
className,
)}
{...props}
/>
),
);
TableHead.displayName = "TableHead";
export interface TableCellProps extends ComponentProps<"td"> {
numeric?: boolean;
}
const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
({ className, numeric = false, ...props }, ref) => (
<td
ref={ref}
data-numeric={numeric || undefined}
className={cn(
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
numeric && "text-right tabular-nums",
className,
)}
{...props}
/>
),
);
TableCell.displayName = "TableCell";
const TableCaption = forwardRef<
HTMLTableCaptionElement,
ComponentProps<"caption">
>(({ className, ...props }, ref) => (
<caption
ref={ref}
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
));
TableCaption.displayName = "TableCaption";
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
};