Skip to content

Commit 6733ef5

Browse files
authored
docs(TreeView): add example with unique icon per item (#11377)
* docs(TreeView): add example with unique icon per item * docs(TreeView): don't use expandedIcon prop
1 parent f53d2dd commit 6733ef5

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

packages/react-core/src/components/TreeView/examples/TreeView.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cssPrefix: pf-v6-c-tree-view
55
propComponents: ['TreeView', 'TreeViewDataItem', 'TreeViewSearch']
66
---
77

8-
import { FolderIcon, FolderOpenIcon, EllipsisVIcon, ClipboardIcon, HamburgerIcon } from '@patternfly/react-icons';
8+
import { FolderIcon, FolderOpenIcon, EllipsisVIcon, ClipboardIcon, HamburgerIcon, GitlabIcon, GithubIcon, GoogleIcon } from '@patternfly/react-icons';
99

1010
## Examples
1111

@@ -51,6 +51,12 @@ A search input can be used to filter tree view items. It is recommended that a t
5151

5252
```
5353

54+
### With unique icon per item
55+
56+
```ts file='./TreeViewWithIconPerItem.tsx'
57+
58+
```
59+
5460
### With badges
5561

5662
```ts file='./TreeViewWithBadges.tsx'
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from 'react';
2+
import { TreeView, TreeViewDataItem } from '@patternfly/react-core';
3+
import GitlabIcon from '@patternfly/react-icons/dist/esm/icons/gitlab-icon';
4+
import GithubIcon from '@patternfly/react-icons/dist/esm/icons/github-icon';
5+
import GoogleIcon from '@patternfly/react-icons/dist/esm/icons/google-icon';
6+
7+
export const TreeViewWithIconPerItem: React.FunctionComponent = () => {
8+
const [activeItems, setActiveItems] = React.useState<TreeViewDataItem[]>();
9+
10+
const onSelect = (_event: React.MouseEvent, treeViewItem: TreeViewDataItem) => {
11+
// Ignore folders for selection
12+
if (treeViewItem && !treeViewItem.children) {
13+
setActiveItems([treeViewItem]);
14+
}
15+
};
16+
const options: TreeViewDataItem[] = [
17+
{
18+
name: 'Github accounts',
19+
id: 'iconPerItem-Github',
20+
icon: <GithubIcon />,
21+
children: [
22+
{
23+
name: 'Account 1',
24+
id: 'iconPerItem-Acc1'
25+
},
26+
{
27+
name: 'Account 2',
28+
id: 'iconPerItem-Acc2'
29+
}
30+
],
31+
defaultExpanded: true
32+
},
33+
{
34+
name: 'Gitlab accounts',
35+
id: 'iconPerItem-Gitlab',
36+
icon: <GitlabIcon />,
37+
children: [
38+
{
39+
name: 'Account 3',
40+
id: 'iconPerItem-Acc3'
41+
}
42+
]
43+
},
44+
{
45+
name: 'Google accounts',
46+
id: 'iconPerItem-Google',
47+
icon: <GoogleIcon />,
48+
children: [
49+
{
50+
name: 'Account 4',
51+
id: 'iconPerItem-Acc4'
52+
}
53+
]
54+
}
55+
];
56+
return (
57+
<TreeView
58+
aria-label="Tree View with unique icon per item example"
59+
data={options}
60+
activeItems={activeItems}
61+
onSelect={onSelect}
62+
/>
63+
);
64+
};

0 commit comments

Comments
 (0)