| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/TreeView/tree-view'; |
| 3 |
import formStyles from '@patternfly/react-styles/css/components/FormControl/form-control'; |
| 4 |
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon'; |
| 5 |
|
| 6 |
/** Renders a search input for the tree view. This sub-component should be passed into the |
| 7 |
* tree view component's toolbar property. |
| 8 |
*/ |
| 9 |
|
| 10 |
export interface TreeViewSearchProps extends React.HTMLProps<HTMLInputElement> { |
| 11 |
/** Accessible label for the search input. */ |
| 12 |
'aria-label'?: string; |
| 13 |
/** Classes applied to the wrapper for the search input. */ |
| 14 |
className?: string; |
| 15 |
/** Id for the search input. */ |
| 16 |
id?: string; |
| 17 |
/** Name for the search input. */ |
| 18 |
name?: string; |
| 19 |
/** Callback for search input. */ |
| 20 |
onSearch?: (event: React.ChangeEvent<HTMLInputElement>) => void; |
| 21 |
} |
| 22 |
|
| 23 |
export const TreeViewSearch: React.FunctionComponent<TreeViewSearchProps> = ({ |
| 24 |
className, |
| 25 |
onSearch, |
| 26 |
id, |
| 27 |
name, |
| 28 |
'aria-label': ariaLabel, |
| 29 |
...props |
| 30 |
}: TreeViewSearchProps) => ( |
| 31 |
<div className={css(styles.treeViewSearch, className)}> |
| 32 |
<div className={css(formStyles.formControl, formStyles.modifiers.icon)}> |
| 33 |
<input onChange={onSearch} id={id} name={name} aria-label={ariaLabel} type="search" {...props} /> |
| 34 |
<div className={css(formStyles.formControlUtilities)}> |
| 35 |
<div className={css(formStyles.formControlIcon)}> |
| 36 |
<SearchIcon /> |
| 37 |
</div> |
| 38 |
</div> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
); |
| 42 |
TreeViewSearch.displayName = 'TreeViewSearch'; |