-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable.tsx
64 lines (55 loc) · 1.9 KB
/
table.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { ComponentProps } from "react";
import { cn } from "./cn";
function Table({
wrapperClassName,
className,
...rest
}: ComponentProps<"table"> & {
wrapperClassName?: string;
}) {
return (
<div className={cn("relative w-full overflow-auto", wrapperClassName)}>
<table className={cn("w-full caption-bottom text-sm", className)} {...rest} />
</div>
);
}
function TableHeader({ className, ...rest }: ComponentProps<"thead">) {
return <thead className={cn("[&_tr]:border-b", className)} {...rest} />;
}
function TableBody({ className, ...rest }: ComponentProps<"tbody">) {
return <tbody className={cn("[&_tr:last-child]:border-0", className)} {...rest} />;
}
function TableFooter({ className, ...rest }: ComponentProps<"tfoot">) {
return <tfoot className={cn("border-t bg-muted/50 last:[&>tr]:border-b-0", className)} {...rest} />;
}
function TableRow({ className, ...rest }: ComponentProps<"tr">) {
return (
<tr
className={cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className)}
{...rest}
/>
);
}
function TableHead({ className, ...rest }: ComponentProps<"th">) {
return (
<th
className={cn(
"h-10 px-2 text-left align-middle font-bold text-muted-foreground last:overflow-x-hidden [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className,
)}
{...rest}
/>
);
}
function TableCell({ className, ...rest }: ComponentProps<"td">) {
return (
<td
className={cn("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className)}
{...rest}
/>
);
}
function TableCaption({ className, ...rest }: ComponentProps<"caption">) {
return <caption className={cn("mt-4 text-muted-foreground text-sm", className)} {...rest} />;
}
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };