import * as React from 'react'; import { cn } from '../../../lib/utils'; const Table = React.forwardRef< HTMLTableElement, React.HTMLAttributes & { containerClassName?: string /** * Wrap the table in the card-style frame (border + radius + `--card` * surface). Default `true` — a standalone `` reads as a contained * data panel against the page background. Set `false` when an outer * container (e.g. `DataTable`) already supplies the frame, to avoid a * double border and a radius that doesn't match the parent's. */ frame?: boolean } >(({ className, containerClassName, frame = true, ...props }, ref) => { // Scroll container. Cap its height via `containerClassName` // (e.g. "max-h-80") to get a scrollable body with a sticky header. const scroll = (
) if (!frame) return scroll // Card-style frame: matches ui-core `Card` (`--radius-popover` corner + // `--shadow-card`) so a standalone table reads as the same kind of contained // panel as every other surface in the app — the page `--background` alone // gives no separation. `overflow-hidden` clips the header band and row // borders to the rounded corners. return (
{scroll}
) }) Table.displayName = "Table" const TableHeader = React.forwardRef< HTMLTableSectionElement, React.HTMLAttributes & { sticky?: boolean } >(({ className, sticky = false, ...props }, ref) => ( // Tinted header band with a solid bottom border so the column labels // separate clearly from the body in both light and dark. // When `sticky`, the band must be fully opaque (solid `bg-muted`, not the // /50 tint) so scrolled body rows don't bleed through it. )) TableHeader.displayName = "TableHeader" const TableBody = React.forwardRef< HTMLTableSectionElement, React.HTMLAttributes & { striped?: boolean } >(({ className, striped = false, ...props }, ref) => ( // `striped` opts into zebra rows via a structural selector on the body, so // callers don't have to compute `i % 2` per row. Keeps the headless API: // per-row className still wins and the default (false) is unchanged. )) TableBody.displayName = "TableBody" const TableFooter = React.forwardRef< HTMLTableSectionElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( tr]:last:border-b-0", className )} {...props} /> )) TableFooter.displayName = "TableFooter" const TableRow = React.forwardRef< HTMLTableRowElement, React.HTMLAttributes & { key?: React.Key } >(({ className, ...props }, ref) => ( )) TableRow.displayName = "TableRow" const TableHead = React.forwardRef< HTMLTableCellElement, React.ThHTMLAttributes & { key?: React.Key } >(({ className, ...props }, ref) => (
[role=checkbox]]:translate-y-[2px]", className )} {...props} /> )) TableHead.displayName = "TableHead" const TableCell = React.forwardRef< HTMLTableCellElement, React.TdHTMLAttributes & { key?: React.Key } >(({ className, ...props }, ref) => ( [role=checkbox]]:translate-y-[2px]", className )} {...props} /> )) TableCell.displayName = "TableCell" const TableCaption = React.forwardRef< HTMLTableCaptionElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( // Caption sits at the bottom inside the card frame; a top border + padding // make it read as a footer strip rather than floating text.
)) TableCaption.displayName = "TableCaption" export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption, }