-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRelayPaginationControls.js
More file actions
103 lines (98 loc) · 2.6 KB
/
RelayPaginationControls.js
File metadata and controls
103 lines (98 loc) · 2.6 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
99
100
101
102
103
import { Select, Flex, Text, IconButton, Divider } from '@chakra-ui/react'
import { Trans } from "@lingui/react/macro"
import React from 'react'
import { array, bool, func, number } from 'prop-types'
import { ChevronLeftIcon, ChevronRightIcon } from '@chakra-ui/icons'
export function RelayPaginationControls({
previous,
hasPreviousPage,
next,
hasNextPage,
resetToFirstPage,
selectedDisplayLimit,
setSelectedDisplayLimit,
displayLimitOptions,
onlyPagination,
isLoadingMore,
totalRecords,
...props
}) {
let displayLimitControls = ''
if (!onlyPagination) {
const options = displayLimitOptions.map((limit) => {
return (
<option value={limit} key={`option-${limit}`}>
{limit}
</option>
)
})
displayLimitControls = (
<>
<Text as="label" htmlFor="Items-per-page" mr={'1%'} ml="auto">
<Trans>Items per page:</Trans>
</Text>
<Select
id="Items-per-page"
aria-label="Items per page"
isDisabled={isLoadingMore}
value={selectedDisplayLimit}
borderColor="black"
onChange={(e) => {
setSelectedDisplayLimit(parseInt(e.target.value))
resetToFirstPage() // Make sure to provide this as a prop if !onlyPagination
}}
width="fit-content"
>
{options}
</Select>
</>
)
}
return (
<Flex align="center" {...props}>
<IconButton
id="previousPageBtn"
icon={<ChevronLeftIcon boxSize="2rem" />}
onClick={previous}
isDisabled={!hasPreviousPage}
isLoading={isLoadingMore}
aria-label="Previous page"
variant="primaryOutline"
bgColor="gray.50"
/>
<IconButton
id="nextPageBtn"
icon={<ChevronRightIcon boxSize="2rem" />}
onClick={next}
isDisabled={!hasNextPage}
isLoading={isLoadingMore}
aria-label="Next page"
ml="2"
variant="primaryOutline"
bgColor="gray.50"
/>
{totalRecords > 0 && (
<>
<Divider mx="2" orientation="vertical" borderLeftColor="gray.900" height="1.5rem" />
<Text>
<Trans>{totalRecords} total item(s)</Trans>
</Text>
</>
)}
{displayLimitControls}
</Flex>
)
}
RelayPaginationControls.propTypes = {
previous: func,
hasPreviousPage: bool,
next: func,
hasNextPage: bool,
resetToFirstPage: func,
selectedDisplayLimit: number,
setSelectedDisplayLimit: func,
displayLimitOptions: array,
onlyPagination: bool,
isLoadingMore: bool,
totalRecords: number,
}