| 1 |
/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 2 |
import React, { FormEvent, SyntheticEvent } from "react"; |
| 3 |
// PatternFly |
| 4 |
import { SearchInput } from "@patternfly/react-core"; |
| 5 |
|
| 6 |
interface SearchValueData { |
| 7 |
searchValue: string; |
| 8 |
updateSearchValue: (value: string) => void; |
| 9 |
submitSearchValue?: () => void; |
| 10 |
} |
| 11 |
|
| 12 |
interface PropsToSearchInput { |
| 13 |
name?: string; |
| 14 |
dataCy: string; |
| 15 |
ariaLabel?: string; |
| 16 |
placeholder?: string; |
| 17 |
searchValueData: SearchValueData; |
| 18 |
isDisabled?: boolean; |
| 19 |
} |
| 20 |
|
| 21 |
const SearchInputLayout = (props: PropsToSearchInput) => { |
| 22 |
const onSearchChange = ( |
| 23 |
_event: FormEvent<HTMLInputElement>, |
| 24 |
value: string |
| 25 |
) => { |
| 26 |
props.searchValueData.updateSearchValue(value); |
| 27 |
}; |
| 28 |
|
| 29 |
const onSearchClear = (_event: SyntheticEvent<HTMLButtonElement, Event>) => { |
| 30 |
props.searchValueData.updateSearchValue(""); |
| 31 |
}; |
| 32 |
|
| 33 |
return ( |
| 34 |
<SearchInput |
| 35 |
data-cy={props.dataCy} |
| 36 |
name={props.name} |
| 37 |
aria-label={props.ariaLabel} |
| 38 |
placeholder={props.placeholder} |
| 39 |
value={props.searchValueData.searchValue} |
| 40 |
onSearch={ |
| 41 |
props.searchValueData.submitSearchValue |
| 42 |
? props.searchValueData.submitSearchValue |
| 43 |
: () => void undefined |
| 44 |
} |
| 45 |
onChange={onSearchChange} |
| 46 |
onClear={onSearchClear} |
| 47 |
isDisabled={props.isDisabled} |
| 48 |
/> |
| 49 |
); |
| 50 |
}; |
| 51 |
|
| 52 |
export default SearchInputLayout; |