This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPaginatedTable.tsx
78 lines (76 loc) · 2.26 KB
/
PaginatedTable.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { ReactNode } from 'react'
import { Box, BoxProps, Center, Text, Spinner, VStack, Skeleton } from '@chakra-ui/react'
import { Pagination } from '@/lib/shared/components/pagination/Pagination'
interface Props<T> extends BoxProps {
items: T[]
loading: boolean
renderTableHeader: () => ReactNode
renderTableRow: (item: T, index: number) => ReactNode
showPagination: boolean
paginationProps: any // TODO: type this
noItemsFoundLabel: string
}
export function PaginatedTable({
items,
loading,
renderTableRow,
renderTableHeader,
showPagination,
paginationProps,
noItemsFoundLabel,
}: Props<any>) {
return (
<>
<VStack w="full" overflowX="scroll" className="hide-scrollbar">
{renderTableHeader()}
<Box w="full" position="relative">
{items.length > 0 && (
<VStack gap="0">
{items.map((item, index) => (
<Box key={`${item.id}-${index}`} w="full">
{renderTableRow(item, index)}
</Box>
))}
</VStack>
)}
{!loading && items.length === 0 && (
<Center py="2xl">
<Text color="font.secondary">{noItemsFoundLabel}</Text>
</Center>
)}
{loading &&
items.length === 0 &&
Array.from({ length: 20 }).map((_, index) => (
<Box key={index} w="full" py="xs">
<Skeleton height="68px" w="full" />
</Box>
))}
{loading && items.length > 0 && (
<Box>
<Box
style={{
position: 'absolute',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
top: 0,
left: 0,
borderRadius: 10,
zIndex: 10,
backdropFilter: 'blur(3px)',
}}
>
<Center py="4xl">
<Spinner size="xl" />
</Center>
</Box>
</Box>
)}
</Box>
</VStack>
{showPagination && <Pagination p="md" {...paginationProps} />}
</>
)
}