-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.tsx
More file actions
98 lines (82 loc) · 2.45 KB
/
table.tsx
File metadata and controls
98 lines (82 loc) · 2.45 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as React from 'react'
import type { z } from 'zod/v4'
import type {
TableBodyProps,
TableCellProps,
TableFooterProps,
TableHeaderProps,
TableHeadProps,
TableProps,
TableRowProps,
TableVariantEnum
} from '../types'
import { cn } from '../utils'
const tableVariantClasses: Record<z.infer<typeof TableVariantEnum>, string> = {
ghost: 'bg-background',
primary: 'bg-accent',
striped: 'bg-background [&_tbody_tr:nth-child(odd)]:bg-accent/80'
}
const Table = React.forwardRef<HTMLTableElement, TableProps>(
({ children, variant = 'primary', className }, ref) => {
return (
<div className="w-full overflow-x-auto rounded-default border">
<table
ref={ref}
className={cn('w-full text-sm', variant && tableVariantClasses[variant], className)}
>
{children}
</table>
</div>
)
}
)
Table.displayName = 'Table'
const TableHeader = React.forwardRef<HTMLTableSectionElement, TableHeaderProps>(
({ children, className }, ref) => (
<thead ref={ref} className={cn('border-b bg-accent/5', className)}>
{children}
</thead>
)
)
TableHeader.displayName = 'TableHeader'
const TableBody = React.forwardRef<HTMLTableSectionElement, TableBodyProps>(
({ children, className }, ref) => (
<tbody ref={ref} className={cn('[&>tr:last-child]:border-b-0 [&>tr]:border-b', className)}>
{children}
</tbody>
)
)
TableBody.displayName = 'TableBody'
const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(
({ children, className }, ref) => (
<tr ref={ref} className={cn('transition-colors', className)}>
{children}
</tr>
)
)
TableRow.displayName = 'TableRow'
const TableFooter = React.forwardRef<HTMLTableSectionElement, TableFooterProps>(
({ children, className }, ref) => (
<tfoot ref={ref} className={cn('bg-accent/5 font-medium', className)}>
{children}
</tfoot>
)
)
TableFooter.displayName = 'TableFooter'
const TableHead = React.forwardRef<HTMLTableCellElement, TableHeadProps>(
({ children, className }, ref) => (
<th ref={ref} className={cn('px-2 py-1.5 text-left font-medium text-foreground/80', className)}>
{children}
</th>
)
)
TableHead.displayName = 'TableHead'
const TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(
({ children, className }, ref) => (
<td ref={ref} className={cn('p-2 py-1.5 text-foreground/80', className)}>
{children}
</td>
)
)
TableCell.displayName = 'TableCell'
export { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow }