forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelayPaginationControls.js
More file actions
90 lines (83 loc) · 2.04 KB
/
RelayPaginationControls.js
File metadata and controls
90 lines (83 loc) · 2.04 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
import { Button, Select, Stack, Text } from '@chakra-ui/core'
import { Trans } from '@lingui/macro'
import React from 'react'
import { array, bool, func, number } from 'prop-types'
export function RelayPaginationControls({
previous,
hasPreviousPage,
next,
hasNextPage,
resetToFirstPage,
selectedDisplayLimit,
setSelectedDisplayLimit,
displayLimitOptions,
onlyPagination,
isLoadingMore,
...props
}) {
let displayLimitControls = ''
if (!onlyPagination) {
const options = displayLimitOptions.map((limit) => {
return (
<option value={limit} key={`option-${limit}`}>
{limit}
</option>
)
})
displayLimitControls = (
<>
<Text ml="auto" mr={'1%'}>
<Trans>Items per page:</Trans>
</Text>
<Select
aria-label="Items per page"
isDisabled={isLoadingMore}
value={selectedDisplayLimit}
onChange={(e) => {
setSelectedDisplayLimit(parseInt(e.target.value))
resetToFirstPage() // Make sure to provide this as a prop if !onlyPagination
}}
width="fit-content"
variant="filled"
>
{options}
</Select>
</>
)
}
return (
<Stack isInline align="center" mb="4" {...props}>
<Button
id="previousPageBtn"
onClick={previous}
isDisabled={!hasPreviousPage}
isLoading={isLoadingMore}
aria-label="Previous page"
>
<Trans>Previous</Trans>
</Button>
<Button
id="nextPageBtn"
onClick={next}
isDisabled={!hasNextPage}
isLoading={isLoadingMore}
aria-label="Next page"
>
<Trans>Next</Trans>
</Button>
{displayLimitControls}
</Stack>
)
}
RelayPaginationControls.propTypes = {
previous: func,
hasPreviousPage: bool,
next: func,
hasNextPage: bool,
resetToFirstPage: func,
selectedDisplayLimit: number,
setSelectedDisplayLimit: func,
displayLimitOptions: array,
onlyPagination: bool,
isLoadingMore: bool,
}