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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
"use client"
import { cn } from "@/lib/utils"
import { Skeleton } from "@/components/ui/skeleton"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
interface DataTableSkeletonProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* The number of columns in the table.
* @type number
*/
columnCount: number
/**
* The number of rows in the table.
* @default 10
* @type number | undefined
*/
rowCount?: number
/**
* The number of searchable columns in the table.
* @default 0
* @type number | undefined
*/
searchableColumnCount?: number
/**
* The number of filterable columns in the table.
* @default 0
* @type number | undefined
*/
filterableColumnCount?: number
/**
* Flag to show the table view options.
* @default undefined
* @type boolean | undefined
*/
showViewOptions?: boolean
/**
* The width of each cell in the table.
* The length of the array should be equal to the columnCount.
* Any valid CSS width value is accepted.
* @default ["auto"]
* @type string[] | undefined
*/
cellWidths?: string[]
/**
* Flag to show the pagination bar.
* @default true
* @type boolean | undefined
*/
withPagination?: boolean
/**
* Flag to prevent the table cells from shrinking.
* @default false
* @type boolean | undefined
*/
shrinkZero?: boolean
}
export function DataTableSkeleton(props: DataTableSkeletonProps) {
const {
columnCount,
rowCount = 10,
searchableColumnCount = 0,
filterableColumnCount = 0,
showViewOptions = true,
cellWidths = ["auto"],
withPagination = true,
shrinkZero = false,
className,
...skeletonProps
} = props
return (
<div
className={cn("w-full space-y-2.5 overflow-auto", className)}
{...skeletonProps}
>
<div className="flex w-full items-center justify-between space-x-2 overflow-auto p-1">
<div className="flex flex-1 items-center space-x-2">
{searchableColumnCount > 0
? Array.from({ length: searchableColumnCount }).map((_, i) => (
<Skeleton key={i} className="h-7 w-40 lg:w-60" />
))
: null}
{filterableColumnCount > 0
? Array.from({ length: filterableColumnCount }).map((_, i) => (
<Skeleton key={i} className="h-7 w-[4.5rem] border-dashed" />
))
: null}
</div>
{showViewOptions ? (
<Skeleton className="ml-auto hidden h-7 w-[4.5rem] lg:flex" />
) : null}
</div>
<div className="rounded-md border">
<Table>
<TableHeader>
{Array.from({ length: 1 }).map((_, i) => (
<TableRow key={i} className="hover:bg-transparent">
{Array.from({ length: columnCount }).map((_, j) => (
<TableHead
key={j}
style={{
width: cellWidths[j],
minWidth: shrinkZero ? cellWidths[j] : "auto",
}}
>
<Skeleton className="h-6 w-full" />
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{Array.from({ length: rowCount }).map((_, i) => (
<TableRow key={i} className="hover:bg-transparent">
{Array.from({ length: columnCount }).map((_, j) => (
<TableCell
key={j}
style={{
width: cellWidths[j],
minWidth: shrinkZero ? cellWidths[j] : "auto",
}}
>
<Skeleton className="h-6 w-full" />
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</div>
{withPagination ? (
<div className="flex w-full items-center justify-between gap-4 overflow-auto p-1 sm:gap-8">
<Skeleton className="h-7 w-40 shrink-0" />
<div className="flex items-center gap-4 sm:gap-6 lg:gap-8">
<div className="flex items-center space-x-2">
<Skeleton className="h-7 w-24" />
<Skeleton className="h-7 w-[4.5rem]" />
</div>
<div className="flex items-center justify-center text-sm font-medium">
<Skeleton className="h-7 w-20" />
</div>
<div className="flex items-center space-x-2">
<Skeleton className="hidden size-7 lg:block" />
<Skeleton className="size-7" />
<Skeleton className="size-7" />
<Skeleton className="hidden size-7 lg:block" />
</div>
</div>
</div>
) : null}
</div>
)
}
|