Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

table.tsx

87 lines2.2 KB

1import * as React from "react";
2​
3import { cn } from "~/lib/utils";
4​
5function Table({ className, ...props }: React.ComponentProps<"table">) {
6 return (
7 <div data-slot="table-container" className="relative w-full overflow-x-auto">
8 <table
9 data-slot="table"
10 className={cn("w-full caption-bottom text-xs", className)}
11 {...props}
12 />
13 </div>
14 );
16​
17function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
18 return <thead data-slot="table-header" className={cn("[&_tr]:border-b", className)} {...props} />;
20​
21function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
22 return (
23 <tbody
24 data-slot="table-body"
25 className={cn("[&_tr:last-child]:border-0", className)}
26 {...props}
27 />
28 );
30​
31function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
32 return (
33 <tfoot
34 data-slot="table-footer"
35 className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
36 {...props}
37 />
38 );
40​
41function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
42 return (
43 <tr
44 data-slot="table-row"
45 className={cn(
46 "border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
47 className,
48 )}
49 {...props}
50 />
51 );
53​
54function TableHead({ className, ...props }: React.ComponentProps<"th">) {
55 return (
56 <th
57 data-slot="table-head"
58 className={cn(
59 "h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
60 className,
61 )}
62 {...props}
63 />
64 );
66​
67function TableCell({ className, ...props }: React.ComponentProps<"td">) {
68 return (
69 <td
70 data-slot="table-cell"
71 className={cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className)}
72 {...props}
73 />
74 );
76​
77function TableCaption({ className, ...props }: React.ComponentProps<"caption">) {
78 return (
79 <caption
80 data-slot="table-caption"
81 className={cn("mt-4 text-xs text-muted-foreground", className)}
82 {...props}
83 />
84 );
86​
87export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };