A table component in neobrutalism style.
1import * as React from "react"
2
3import { cn } from "@/lib/utils"
4
5function Table({ className, ...props }: React.ComponentProps<"table">) {
6 return (
7 <div className="relative w-full overflow-auto">
8 <table
9 data-slot="table"
10 className={cn(
11 "w-full caption-bottom border-2 border-border text-sm",
12 className,
13 )}
14 {...props}
15 />
16 </div>
17 )
18}
19
20function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
21 return (
22 <thead
23 data-slot="table-header"
24 className={cn("[&_tr]:border-b-2 [&_tr]:border-border", className)}
25 {...props}
26 />
27 )
28}
29
30function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
31 return (
32 <tbody
33 data-slot="table-body"
34 className={cn("[&_tr:last-child]:border-0", className)}
35 {...props}
36 />
37 )
38}
39
40function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
41 return (
42 <tfoot
43 data-slot="table-footer"
44 className={cn(
45 "border-t-2 border-border bg-main font-base text-main-foreground last:[&>tr]:border-b-0",
46 className,
47 )}
48 {...props}
49 />
50 )
51}
52
53function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
54 return (
55 <tr
56 data-slot="table-row"
57 className={cn(
58 "border-b-2 border-border transition-colors text-main-foreground bg-main font-base data-[state=selected]:bg-secondary-background data-[state=selected]:text-main-foreground",
59 className,
60 )}
61 {...props}
62 />
63 )
64}
65
66function TableHead({ className, ...props }: React.ComponentProps<"th">) {
67 return (
68 <th
69 data-slot="table-head"
70 className={cn(
71 "h-12 px-4 text-left align-middle font-heading text-main-foreground [&:has([role=checkbox])]:pr-0",
72 className,
73 )}
74 {...props}
75 />
76 )
77}
78
79function TableCell({ className, ...props }: React.ComponentProps<"td">) {
80 return (
81 <td
82 data-slot="table-cell"
83 className={cn(
84 "p-4 align-middle [&:has([role=checkbox])]:pr-0",
85 className,
86 )}
87 {...props}
88 />
89 )
90}
91
92function TableCaption({
93 className,
94 ...props
95}: React.ComponentProps<"caption">) {
96 return (
97 <caption
98 data-slot="table-caption"
99 className={cn("mt-4 text-sm text-foreground font-base", className)}
100 {...props}
101 />
102 )
103}
104
105export {
106 Table,
107 TableHeader,
108 TableBody,
109 TableFooter,
110 TableHead,
111 TableRow,
112 TableCell,
113 TableCaption,
114}
115