151 lines
3.7 KiB
TypeScript
151 lines
3.7 KiB
TypeScript
import * as React from 'react';
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
const Table = React.forwardRef<HTMLTableElement, React.ComponentProps<'table'>>(
|
|
({ className, ...props }, ref) => {
|
|
return (
|
|
<div
|
|
data-slot="table-container"
|
|
className="relative w-full overflow-x-auto"
|
|
>
|
|
<table
|
|
ref={ref}
|
|
data-slot="table"
|
|
className={cn('w-full caption-bottom text-sm', className)}
|
|
{...props}
|
|
/>
|
|
</div>
|
|
);
|
|
},
|
|
);
|
|
Table.displayName = 'Table';
|
|
|
|
const TableHeader = React.forwardRef<
|
|
HTMLTableSectionElement,
|
|
React.ComponentProps<'thead'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<thead
|
|
ref={ref}
|
|
data-slot="table-header"
|
|
className={cn('[&_tr]:border-b', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableHeader.displayName = 'TableHeader';
|
|
|
|
const TableBody = React.forwardRef<
|
|
HTMLTableSectionElement,
|
|
React.ComponentProps<'tbody'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<tbody
|
|
ref={ref}
|
|
data-slot="table-body"
|
|
className={cn('[&_tr:last-child]:border-0', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableBody.displayName = 'TableBody';
|
|
|
|
const TableFooter = React.forwardRef<
|
|
HTMLTableSectionElement,
|
|
React.ComponentProps<'tfoot'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<tfoot
|
|
ref={ref}
|
|
data-slot="table-footer"
|
|
className={cn(
|
|
'bg-muted/50 border-t font-medium [&>tr]:last:border-b-0',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableFooter.displayName = 'TableFooter';
|
|
|
|
const TableRow = React.forwardRef<
|
|
HTMLTableRowElement,
|
|
React.ComponentProps<'tr'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<tr
|
|
ref={ref}
|
|
data-slot="table-row"
|
|
className={cn(
|
|
'hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableRow.displayName = 'TableRow';
|
|
|
|
const TableHead = React.forwardRef<
|
|
HTMLTableCellElement,
|
|
React.ComponentProps<'th'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<th
|
|
ref={ref}
|
|
data-slot="table-head"
|
|
className={cn(
|
|
'text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableHead.displayName = 'TableHead';
|
|
|
|
const TableCell = React.forwardRef<
|
|
HTMLTableCellElement,
|
|
React.ComponentProps<'td'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<td
|
|
ref={ref}
|
|
data-slot="table-cell"
|
|
className={cn(
|
|
'p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableCell.displayName = 'TableCell';
|
|
|
|
const TableCaption = React.forwardRef<
|
|
HTMLTableCaptionElement,
|
|
React.ComponentProps<'caption'>
|
|
>(({ className, ...props }, ref) => {
|
|
return (
|
|
<caption
|
|
ref={ref}
|
|
data-slot="table-caption"
|
|
className={cn('text-muted-foreground mt-4 text-sm', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
});
|
|
TableCaption.displayName = 'TableCaption';
|
|
|
|
export {
|
|
Table,
|
|
TableHeader,
|
|
TableBody,
|
|
TableFooter,
|
|
TableHead,
|
|
TableRow,
|
|
TableCell,
|
|
TableCaption,
|
|
};
|