forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInputAdvanced.tsx
More file actions
57 lines (54 loc) · 2.02 KB
/
SearchInputAdvanced.tsx
File metadata and controls
57 lines (54 loc) · 2.02 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
import { useState } from 'react';
import { Button, Checkbox, FormGroup, SearchInput } from '@patternfly/react-core';
import ExternalLinkSquareAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-square-alt-icon';
export const SearchInputAdvanced: React.FunctionComponent = () => {
const [value, setValue] = useState('username:player firstname:john');
const [useEqualsAsDelimiter, setUseEqualsAsDelimiter] = useState(false);
const [useCustomFooter, setUseCustomFooter] = useState(false);
const toggleDelimiter = (checked: boolean) => {
setValue(value.replace(/:|=/g, checked ? '=' : ':'));
setUseEqualsAsDelimiter(checked);
};
return (
<>
<Checkbox
label="Use equal sign as search attribute delimiter"
isChecked={useEqualsAsDelimiter}
onChange={(_event, checked) => toggleDelimiter(checked)}
aria-label="change delimiter checkbox"
id="toggle-delimiter"
name="toggle-delimiter"
/>
<Checkbox
label="Add custom footer element after the attributes in the menu"
isChecked={useCustomFooter}
onChange={(_event, checked) => setUseCustomFooter(checked)}
aria-label="change use custom footer checkbox"
id="toggle-custom-footer"
name="toggle-custom-footer"
/>
<br />
<SearchInput
aria-label="Advanced search"
attributes={[
{ attr: 'username', display: 'Username' },
{ attr: 'firstname', display: 'First name' }
]}
advancedSearchDelimiter={useEqualsAsDelimiter ? '=' : ':'}
value={value}
onChange={(_event, value) => setValue(value)}
onSearch={(_event, value) => setValue(value)}
onClear={() => setValue('')}
formAdditionalItems={
useCustomFooter ? (
<FormGroup>
<Button variant="link" isInline icon={<ExternalLinkSquareAltIcon />} iconPosition="end">
Link
</Button>
</FormGroup>
) : null
}
/>
</>
);
};