-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSearchBox.js
More file actions
147 lines (145 loc) · 4.34 KB
/
SearchBox.js
File metadata and controls
147 lines (145 loc) · 4.34 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
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
import React from 'react'
import {
Box,
Divider,
Flex,
IconButton,
Input,
InputGroup,
InputLeftElement,
Select,
Stack,
Text,
} from '@chakra-ui/react'
import { Trans } from "@lingui/react/macro"
import { ArrowDownIcon, ArrowUpIcon, SearchIcon } from '@chakra-ui/icons'
import { RelayPaginationControls } from './RelayPaginationControls'
import { array, bool, element, func, number, string } from 'prop-types'
import { InfoButton } from './InfoPanel'
export function SearchBox({
selectedDisplayLimit,
setSelectedDisplayLimit,
hasNextPage,
hasPreviousPage,
next,
previous,
isLoadingMore,
orderDirection,
setSearchTerm,
setOrderField,
setOrderDirection,
resetToFirstPage,
orderByOptions,
placeholder,
onToggle,
searchTip,
totalRecords,
...props
}) {
const orderIconName = orderDirection === 'ASC' ? <ArrowUpIcon /> : <ArrowDownIcon />
return (
<Box className="search-box" {...props} bg="gray.100" p="2" mb="4" borderColor="gray.300" borderWidth="1px">
<Flex direction={{ base: 'column', md: 'row' }} alignItems={{ base: 'stretch', md: 'center' }} mb={2}>
<Flex direction="row" minW={{ base: '100%', md: '50%' }} alignItems="center" flexGrow={1}>
<Text as="label" htmlFor="Search-for-field" fontSize="md" fontWeight="bold" textAlign="center" mr={2}>
<Trans>Search: </Trans>
</Text>
<InputGroup flexGrow={1}>
<InputLeftElement aria-hidden="true">
<SearchIcon color="black" />
</InputLeftElement>
<Input
id="Search-for-field"
type="text"
placeholder={placeholder}
onChange={(e) => {
setSearchTerm(e.target.value)
resetToFirstPage()
}}
aria-label="Search-for-field"
borderColor="black"
/>
</InputGroup>
</Flex>
{onToggle && <InfoButton bg="gray.50" onToggle={onToggle} className="glossary-button" />}
<Stack isInline align="center" ml={{ md: '5%' }}>
<Text as="label" htmlFor="Sort-by-field" fontSize="md" fontWeight="bold" textAlign="center">
<Trans>Sort by: </Trans>
</Text>
<Select
id="Sort-by-field"
aria-label="Sort by field"
w="fit-content"
borderColor="black"
size="md"
onChange={(e) => {
setOrderField(e.target.value)
resetToFirstPage()
}}
>
{orderByOptions.map(({ value, text }) => {
return (
<option key={value} value={value}>
{text}
</option>
)
})}
</Select>
<IconButton
aria-label="Toggle sort direction"
icon={orderIconName}
color="primary"
bg="white"
borderColor="black"
borderWidth="1px"
onClick={() => {
const newOrderDirection = orderDirection === 'ASC' ? 'DESC' : 'ASC'
setOrderDirection(newOrderDirection)
resetToFirstPage()
}}
ml="auto"
/>
</Stack>
</Flex>
{searchTip && (
<Box backgroundColor="gray.200" padding={1} borderRadius="sm" fontSize="sm">
{searchTip}
</Box>
)}
<Divider borderBottomWidth="1px" borderBottomColor="black" />
<RelayPaginationControls
onlyPagination={false}
selectedDisplayLimit={selectedDisplayLimit}
setSelectedDisplayLimit={setSelectedDisplayLimit}
displayLimitOptions={[5, 10, 20, 50, 100]}
resetToFirstPage={resetToFirstPage}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
next={next}
previous={previous}
isLoadingMore={isLoadingMore}
totalRecords={totalRecords}
/>
</Box>
)
}
SearchBox.propTypes = {
orderDirection: string,
selectedDisplayLimit: number,
setSelectedDisplayLimit: func,
hasNextPage: bool,
hasPreviousPage: bool,
next: func,
previous: func,
isLoadingMore: bool,
setSearchTerm: func,
setOrderField: func,
setOrderDirection: func,
resetToFirstPage: func,
orderByOptions: array,
placeholder: string,
inputAriaLabel: string,
onToggle: func,
searchTip: element,
totalRecords: number,
}