import { forwardRef } from 'react' import { tv } from 'tailwind-variants' import type { Merge } from 'type-fest' const table = tv({ slots: { rootWrapper: 'relative w-full overflow-auto', root: 'w-full caption-bottom text-sm', header: null, body: 'border-t', footer: 'border-t', row: 'border-b transition-colors hover:bg-bg--hover data-[state=selected]:bg-bg--active last:border-0', head: 'h-10 px-2 text-left align-middle font-medium text-fg-weaker', cell: 'p-2 align-middle', caption: 'mt-4 text-sm text-fg-weaker', }, }) const TableRoot = forwardRef< HTMLTableElement, Merge< React.HTMLAttributes, { wrapperProps?: React.ComponentProps<'div'> } > >(({ wrapperProps, ...props }, ref) => { const { root, rootWrapper } = table() return (
) }) TableRoot.displayName = 'Table' const TableHeader = forwardRef< HTMLTableSectionElement, React.HTMLAttributes >((props, ref) => { const { header } = table() return }) TableHeader.displayName = 'TableHeader' const TableBody = forwardRef< HTMLTableSectionElement, React.HTMLAttributes >((props, ref) => { const { body } = table() return }) TableBody.displayName = 'TableBody' const TableFooter = forwardRef< HTMLTableSectionElement, React.HTMLAttributes >((props, ref) => { const { footer } = table() return }) TableFooter.displayName = 'TableFooter' const TableRow = forwardRef>( (props, ref) => { const { row } = table() return }, ) TableRow.displayName = 'TableRow' const TableHead = forwardRef>( (props, ref) => { const { head } = table() return
}, ) TableHead.displayName = 'TableHead' const TableCell = forwardRef>( (props, ref) => { const { cell } = table() return }, ) TableCell.displayName = 'TableCell' const TableCaption = forwardRef< HTMLTableCaptionElement, React.HTMLAttributes >((props, ref) => { const { caption } = table() return
}) TableCaption.displayName = 'TableCaption' const Table = Object.assign(TableRoot, { Header: TableHeader, Body: TableBody, Footer: TableFooter, Caption: TableCaption, Head: TableHead, Row: TableRow, Cell: TableCell, }) export default Table export { table }