| 1 |
import { useState } from 'react'; |
| 2 |
import { Button, Checkbox, FormGroup, SearchInput } from '@patternfly/react-core'; |
| 3 |
import RhUiExternalLinkFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-external-link-fill-icon'; |
| 4 |
|
| 5 |
export const SearchInputAdvanced: React.FunctionComponent = () => { |
| 6 |
const [value, setValue] = useState('username:player firstname:john'); |
| 7 |
const [useEqualsAsDelimiter, setUseEqualsAsDelimiter] = useState(false); |
| 8 |
const [useCustomFooter, setUseCustomFooter] = useState(false); |
| 9 |
|
| 10 |
const toggleDelimiter = (checked: boolean) => { |
| 11 |
setValue(value.replace(/:|=/g, checked ? '=' : ':')); |
| 12 |
setUseEqualsAsDelimiter(checked); |
| 13 |
}; |
| 14 |
|
| 15 |
return ( |
| 16 |
<> |
| 17 |
<Checkbox |
| 18 |
label="Use equal sign as search attribute delimiter" |
| 19 |
isChecked={useEqualsAsDelimiter} |
| 20 |
onChange={(_event, checked) => toggleDelimiter(checked)} |
| 21 |
aria-label="change delimiter checkbox" |
| 22 |
id="toggle-delimiter" |
| 23 |
name="toggle-delimiter" |
| 24 |
/> |
| 25 |
<Checkbox |
| 26 |
label="Add custom footer element after the attributes in the menu" |
| 27 |
isChecked={useCustomFooter} |
| 28 |
onChange={(_event, checked) => setUseCustomFooter(checked)} |
| 29 |
aria-label="change use custom footer checkbox" |
| 30 |
id="toggle-custom-footer" |
| 31 |
name="toggle-custom-footer" |
| 32 |
/> |
| 33 |
<br /> |
| 34 |
<SearchInput |
| 35 |
aria-label="Advanced search" |
| 36 |
attributes={[ |
| 37 |
{ attr: 'username', display: 'Username' }, |
| 38 |
{ attr: 'firstname', display: 'First name' } |
| 39 |
]} |
| 40 |
advancedSearchDelimiter={useEqualsAsDelimiter ? '=' : ':'} |
| 41 |
value={value} |
| 42 |
onChange={(_event, value) => setValue(value)} |
| 43 |
onSearch={(_event, value) => setValue(value)} |
| 44 |
onClear={() => setValue('')} |
| 45 |
formAdditionalItems={ |
| 46 |
useCustomFooter ? ( |
| 47 |
<FormGroup> |
| 48 |
<Button variant="link" isInline icon={<RhUiExternalLinkFillIcon />} iconPosition="end"> |
| 49 |
Link |
| 50 |
</Button> |
| 51 |
</FormGroup> |
| 52 |
) : null |
| 53 |
} |
| 54 |
/> |
| 55 |
</> |
| 56 |
); |
| 57 |
}; |