| 1 |
import { Fragment } from 'react'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import { Divider } from '../Divider'; |
| 4 |
import styles from '@patternfly/react-styles/css/components/TreeView/tree-view'; |
| 5 |
|
| 6 |
export interface TreeViewListProps extends React.HTMLProps<HTMLUListElement> { |
| 7 |
/** Child nodes of the current tree view. */ |
| 8 |
children: React.ReactNode; |
| 9 |
/** Flag indicating if the tree view is nested under another tree view. */ |
| 10 |
isNested?: boolean; |
| 11 |
/** Toolbar to display above the tree view. */ |
| 12 |
toolbar?: React.ReactNode; |
| 13 |
/** Flag indicating whether multiple nodes can be selected in the tree view. This will also set the |
| 14 |
* aria-multiselectable attribute on the tree view list which is required to be true when multiple selection is intended. |
| 15 |
* Can only be applied to the root tree view list. |
| 16 |
*/ |
| 17 |
isMultiSelectable?: boolean; |
| 18 |
/** A text string that sets the accessible name of the tree view list. Either this or the aria-labelledby property must |
| 19 |
* be passed in. |
| 20 |
*/ |
| 21 |
'aria-label'?: string; |
| 22 |
/** A space separated list of element id's that sets the accessible name of the tree view list. Either |
| 23 |
* this or the aria-label property must be passed in. |
| 24 |
*/ |
| 25 |
'aria-labelledby'?: string; |
| 26 |
} |
| 27 |
|
| 28 |
export const TreeViewList: React.FunctionComponent<TreeViewListProps> = ({ |
| 29 |
isNested = false, |
| 30 |
isMultiSelectable = false, |
| 31 |
toolbar, |
| 32 |
children, |
| 33 |
'aria-label': ariaLabel, |
| 34 |
'aria-labelledby': ariaLabelledby, |
| 35 |
...props |
| 36 |
}: TreeViewListProps) => ( |
| 37 |
<> |
| 38 |
{toolbar && ( |
| 39 |
<Fragment> |
| 40 |
{toolbar} |
| 41 |
<Divider /> |
| 42 |
</Fragment> |
| 43 |
)} |
| 44 |
<ul |
| 45 |
className={css(`${styles.treeView}__list`)} |
| 46 |
role={isNested ? 'group' : 'tree'} |
| 47 |
aria-multiselectable={isNested ? undefined : isMultiSelectable} |
| 48 |
aria-label={ariaLabel} |
| 49 |
aria-labelledby={ariaLabelledby} |
| 50 |
{...props} |
| 51 |
> |
| 52 |
{children} |
| 53 |
</ul> |
| 54 |
</> |
| 55 |
); |
| 56 |
TreeViewList.displayName = 'TreeViewList'; |