blob: 12270a92f7b8cd18ce982b07e2a6947d943fcafc [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001import * as React from "react";
gio5f2f1002025-03-20 18:38:48 +04002
giod0026612025-05-08 13:00:36 +00003import { cn } from "@/lib/utils";
gio5f2f1002025-03-20 18:38:48 +04004
giod0026612025-05-08 13:00:36 +00005const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>(
6 ({ className, ...props }, ref) => (
7 <div className="relative w-full overflow-auto">
8 <table ref={ref} className={cn("w-full caption-top text-sm", className)} {...props} />
9 </div>
10 ),
11);
12Table.displayName = "Table";
gio5f2f1002025-03-20 18:38:48 +040013
giod0026612025-05-08 13:00:36 +000014const TableHeader = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
15 ({ className, ...props }, ref) => <thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />,
16);
17TableHeader.displayName = "TableHeader";
gio5f2f1002025-03-20 18:38:48 +040018
giod0026612025-05-08 13:00:36 +000019const TableBody = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
20 ({ className, ...props }, ref) => (
21 <tbody ref={ref} className={cn("[&_tr:last-child]:border-0", className)} {...props} />
22 ),
23);
24TableBody.displayName = "TableBody";
gio5f2f1002025-03-20 18:38:48 +040025
giod0026612025-05-08 13:00:36 +000026const TableFooter = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
27 ({ className, ...props }, ref) => (
28 <tfoot
29 ref={ref}
30 className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
31 {...props}
32 />
33 ),
34);
35TableFooter.displayName = "TableFooter";
gio5f2f1002025-03-20 18:38:48 +040036
giod0026612025-05-08 13:00:36 +000037const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>(
38 ({ className, ...props }, ref) => (
39 <tr
40 ref={ref}
41 className={cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className)}
42 {...props}
43 />
44 ),
45);
46TableRow.displayName = "TableRow";
gio5f2f1002025-03-20 18:38:48 +040047
giod0026612025-05-08 13:00:36 +000048const TableHead = React.forwardRef<HTMLTableCellElement, React.ThHTMLAttributes<HTMLTableCellElement>>(
49 ({ className, ...props }, ref) => (
50 <th
51 ref={ref}
52 className={cn(
53 "h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
54 className,
55 )}
56 {...props}
57 />
58 ),
59);
60TableHead.displayName = "TableHead";
gio5f2f1002025-03-20 18:38:48 +040061
giod0026612025-05-08 13:00:36 +000062const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>(
63 ({ className, ...props }, ref) => (
64 <td
65 ref={ref}
66 className={cn(
67 "p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
68 className,
69 )}
70 {...props}
71 />
72 ),
73);
74TableCell.displayName = "TableCell";
gio5f2f1002025-03-20 18:38:48 +040075
giod0026612025-05-08 13:00:36 +000076const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttributes<HTMLTableCaptionElement>>(
77 ({ className, ...props }, ref) => (
78 <caption ref={ref} className={cn("mt-4 text-sm text-muted-foreground", className)} {...props} />
79 ),
80);
81TableCaption.displayName = "TableCaption";
gio5f2f1002025-03-20 18:38:48 +040082
giod0026612025-05-08 13:00:36 +000083export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };