|
| 1 | + |
| 2 | +import * as React from "react" |
| 3 | +import { cn } from "@/lib/utils" |
| 4 | + |
| 5 | +const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>(({ className, ...props }, ref) => ( |
| 6 | + <div className="relative w-full overflow-auto"> |
| 7 | + <table ref={ref} className={cn("w-full caption-bottom text-sm", className)} {...props} /> |
| 8 | + </div> |
| 9 | +)) |
| 10 | +Table.displayName = "Table" |
| 11 | + |
| 12 | +const TableHeader = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => ( |
| 13 | + <thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} /> |
| 14 | +)) |
| 15 | +TableHeader.displayName = "TableHeader" |
| 16 | + |
| 17 | +const TableBody = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => ( |
| 18 | + <tbody ref={ref} className={cn("[&_tr:last-child]:border-0", className)} {...props} /> |
| 19 | +)) |
| 20 | +TableBody.displayName = "TableBody" |
| 21 | + |
| 22 | +const TableFooter = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => ( |
| 23 | + <tfoot ref={ref} className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)} {...props} /> |
| 24 | +)) |
| 25 | +TableFooter.displayName = "TableFooter" |
| 26 | + |
| 27 | +const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>(({ className, ...props }, ref) => ( |
| 28 | + <tr ref={ref} className={cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className)} {...props} /> |
| 29 | +)) |
| 30 | +TableRow.displayName = "TableRow" |
| 31 | + |
| 32 | +const TableHead = React.forwardRef<HTMLTableCellElement, React.ThHTMLAttributes<HTMLTableCellElement>>(({ className, ...props }, ref) => ( |
| 33 | + <th ref={ref} className={cn("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", className)} {...props} /> |
| 34 | +)) |
| 35 | +TableHead.displayName = "TableHead" |
| 36 | + |
| 37 | +const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>(({ className, ...props }, ref) => ( |
| 38 | + <td ref={ref} className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)} {...props} /> |
| 39 | +)) |
| 40 | +TableCell.displayName = "TableCell" |
| 41 | + |
| 42 | +const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttributes<HTMLTableCaptionElement>>(({ className, ...props }, ref) => ( |
| 43 | + <caption ref={ref} className={cn("mt-4 text-sm text-muted-foreground", className)} {...props} /> |
| 44 | +)) |
| 45 | +TableCaption.displayName = "TableCaption" |
| 46 | + |
| 47 | +export { |
| 48 | + Table, |
| 49 | + TableHeader, |
| 50 | + TableBody, |
| 51 | + TableFooter, |
| 52 | + TableHead, |
| 53 | + TableRow, |
| 54 | + TableCell, |
| 55 | + TableCaption, |
| 56 | +} |
0 commit comments