|
| 1 | +import * as React from "react"; |
| 2 | +import { cn } from "../../utilities"; |
| 3 | + |
| 4 | +const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>( |
| 5 | + ({ className, ...props }, ref) => ( |
| 6 | + <div className="w-full overflow-auto"> |
| 7 | + <table ref={ref} className={cn("w-full text-text-sm", className)} {...props} /> |
| 8 | + </div> |
| 9 | + ) |
| 10 | +); |
| 11 | +Table.displayName = "Table"; |
| 12 | + |
| 13 | +const TableHeader = React.forwardRef< |
| 14 | + HTMLTableSectionElement, |
| 15 | + React.HTMLAttributes<HTMLTableSectionElement> |
| 16 | +>(({ className, ...props }, ref) => ( |
| 17 | + <thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} /> |
| 18 | +)); |
| 19 | +TableHeader.displayName = "TableHeader"; |
| 20 | + |
| 21 | +const TableBody = React.forwardRef< |
| 22 | + HTMLTableSectionElement, |
| 23 | + React.HTMLAttributes<HTMLTableSectionElement> |
| 24 | +>(({ className, ...props }, ref) => ( |
| 25 | + <tbody ref={ref} className={cn("[&_tr:last-child]:border-0", className)} {...props} /> |
| 26 | +)); |
| 27 | +TableBody.displayName = "TableBody"; |
| 28 | + |
| 29 | +const TableFooter = React.forwardRef< |
| 30 | + HTMLTableSectionElement, |
| 31 | + React.HTMLAttributes<HTMLTableSectionElement> |
| 32 | +>(({ className, ...props }, ref) => ( |
| 33 | + <tfoot |
| 34 | + ref={ref} |
| 35 | + className={cn("bg-primary text-primary-foreground font-medium", className)} |
| 36 | + {...props} |
| 37 | + /> |
| 38 | +)); |
| 39 | +TableFooter.displayName = "TableFooter"; |
| 40 | + |
| 41 | +const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>( |
| 42 | + ({ className, ...props }, ref) => ( |
| 43 | + <tr |
| 44 | + ref={ref} |
| 45 | + className={cn( |
| 46 | + "hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", |
| 47 | + className |
| 48 | + )} |
| 49 | + {...props} |
| 50 | + /> |
| 51 | + ) |
| 52 | +); |
| 53 | +TableRow.displayName = "TableRow"; |
| 54 | + |
| 55 | +const TableHead = React.forwardRef< |
| 56 | + HTMLTableCellElement, |
| 57 | + React.ThHTMLAttributes<HTMLTableCellElement> |
| 58 | +>(({ className, ...props }, ref) => ( |
| 59 | + <th |
| 60 | + ref={ref} |
| 61 | + className={cn( |
| 62 | + "h-8 px-4 py-2 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", |
| 63 | + className |
| 64 | + )} |
| 65 | + {...props} |
| 66 | + /> |
| 67 | +)); |
| 68 | +TableHead.displayName = "TableHead"; |
| 69 | + |
| 70 | +const TableCell = React.forwardRef< |
| 71 | + HTMLTableCellElement, |
| 72 | + React.TdHTMLAttributes<HTMLTableCellElement> |
| 73 | +>(({ className, ...props }, ref) => ( |
| 74 | + <td |
| 75 | + ref={ref} |
| 76 | + className={cn( |
| 77 | + "h-9 px-4 py-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", |
| 78 | + className |
| 79 | + )} |
| 80 | + {...props} |
| 81 | + /> |
| 82 | +)); |
| 83 | +TableCell.displayName = "TableCell"; |
| 84 | + |
| 85 | +const TableCaption = React.forwardRef< |
| 86 | + HTMLTableCaptionElement, |
| 87 | + React.HTMLAttributes<HTMLTableCaptionElement> |
| 88 | +>(({ className, ...props }, ref) => ( |
| 89 | + <caption |
| 90 | + ref={ref} |
| 91 | + className={cn("text-muted-foreground mt-4 text-text-sm", className)} |
| 92 | + {...props} |
| 93 | + /> |
| 94 | +)); |
| 95 | +TableCaption.displayName = "TableCaption"; |
| 96 | + |
| 97 | +export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption }; |
0 commit comments