@patternfly/react-core 4.192.5 → 4.192.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/esm/components/Menu/MenuContent.js +1 -1
- package/dist/esm/components/Menu/MenuContent.js.map +1 -1
- package/dist/js/components/Menu/MenuContent.js +1 -1
- package/dist/js/components/Menu/MenuContent.js.map +1 -1
- package/dist/umd/react-core.css +910 -910
- package/dist/umd/react-core.js +1 -1
- package/dist/umd/react-core.min.css +72 -72
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/Menu/MenuContent.tsx +2 -2
- package/src/components/Menu/examples/Menu.md +7 -7
- package/src/demos/ComposableMenu/ComposableMenu.md +88 -0
- package/src/demos/ComposableMenu/examples/ComposableActionsMenu.tsx +122 -0
- package/src/demos/ComposableMenu/examples/ComposableApplicationLauncher.tsx +282 -0
- package/src/demos/ComposableMenu/examples/ComposableContextSelector.tsx +202 -0
- package/src/demos/ComposableMenu/examples/ComposableDrilldownMenu.tsx +246 -0
- package/src/demos/ComposableMenu/examples/ComposableDropdwnVariants.tsx +235 -0
- package/src/demos/ComposableMenu/examples/ComposableFlyout.tsx +103 -0
- package/src/demos/ComposableMenu/examples/ComposableOptionsMenuVariants.tsx +94 -0
- package/src/demos/ComposableMenu/examples/ComposableSimpleDropdown.tsx +70 -0
- package/src/demos/ComposableMenu/examples/ComposableSimpleSelect.tsx +74 -0
- package/src/demos/ComposableMenu/examples/ComposableTreeViewMenu.tsx +240 -0
- package/src/demos/ComposableMenu/examples/avatarImg.svg +18 -0
- package/src/demos/ComposableMenu/examples/pf-logo-small.svg +23 -0
- package/src/demos/ComposableMenu.md +0 -1443
- package/src/demos/composable-menu.css +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.192.
|
|
3
|
+
"version": "4.192.6",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.43.
|
|
38
|
-
"@patternfly/react-styles": "^4.42.
|
|
39
|
-
"@patternfly/react-tokens": "^4.44.
|
|
37
|
+
"@patternfly/react-icons": "^4.43.6",
|
|
38
|
+
"@patternfly/react-styles": "^4.42.6",
|
|
39
|
+
"@patternfly/react-tokens": "^4.44.6",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "8eb5ba0e6fbf8b780055ed857294cdb470361be1"
|
|
64
64
|
}
|
|
@@ -19,10 +19,10 @@ export interface MenuContentProps extends React.HTMLProps<HTMLElement> {
|
|
|
19
19
|
export const MenuContent = React.forwardRef((props: MenuContentProps, ref: React.Ref<HTMLDivElement>) => {
|
|
20
20
|
const { getHeight, children, menuHeight, maxMenuHeight, ...rest } = props;
|
|
21
21
|
const menuContentRef = React.createRef<HTMLDivElement>();
|
|
22
|
-
const refCallback = (el:
|
|
22
|
+
const refCallback = (el: HTMLElement, menuId: string, onGetMenuHeight: (menuId: string, height: number) => void) => {
|
|
23
23
|
if (el) {
|
|
24
24
|
onGetMenuHeight && onGetMenuHeight(menuId, el.clientHeight);
|
|
25
|
-
getHeight && getHeight(el.clientHeight);
|
|
25
|
+
getHeight && getHeight(el.clientHeight.toString());
|
|
26
26
|
}
|
|
27
27
|
return ref || menuContentRef;
|
|
28
28
|
};
|
|
@@ -749,7 +749,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
749
749
|
direction="down"
|
|
750
750
|
drilldownMenu={
|
|
751
751
|
<DrilldownMenu id="drilldownMenuStart">
|
|
752
|
-
<MenuItem itemId="group:
|
|
752
|
+
<MenuItem itemId="group:start_rollout_breadcrumb" direction="up">
|
|
753
753
|
Start rollout
|
|
754
754
|
</MenuItem>
|
|
755
755
|
<Divider component="li" />
|
|
@@ -759,7 +759,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
759
759
|
direction="down"
|
|
760
760
|
drilldownMenu={
|
|
761
761
|
<DrilldownMenu id="drilldownMenuStartGrouping">
|
|
762
|
-
<MenuItem itemId="group:
|
|
762
|
+
<MenuItem itemId="group:app_grouping_breadcrumb" direction="up">
|
|
763
763
|
Application grouping
|
|
764
764
|
</MenuItem>
|
|
765
765
|
<Divider component="li" />
|
|
@@ -777,7 +777,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
777
777
|
direction="down"
|
|
778
778
|
drilldownMenu={
|
|
779
779
|
<DrilldownMenu id="drilldownMenuStartLabels">
|
|
780
|
-
<MenuItem itemId="group:
|
|
780
|
+
<MenuItem itemId="group:labels_breadcrumb" direction="up">
|
|
781
781
|
Labels
|
|
782
782
|
</MenuItem>
|
|
783
783
|
<Divider component="li" />
|
|
@@ -800,7 +800,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
800
800
|
direction="down"
|
|
801
801
|
drilldownMenu={
|
|
802
802
|
<DrilldownMenu id="drilldownMenuPause">
|
|
803
|
-
<MenuItem itemId="group:
|
|
803
|
+
<MenuItem itemId="group:pause_rollout_breadcrumb" direction="up">
|
|
804
804
|
Pause rollouts
|
|
805
805
|
</MenuItem>
|
|
806
806
|
<Divider component="li" />
|
|
@@ -810,7 +810,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
810
810
|
direction="down"
|
|
811
811
|
drilldownMenu={
|
|
812
812
|
<DrilldownMenu id="drilldownMenuGrouping">
|
|
813
|
-
<MenuItem itemId="group:
|
|
813
|
+
<MenuItem itemId="group:app_grouping_breadcrumb" direction="up">
|
|
814
814
|
Application grouping
|
|
815
815
|
</MenuItem>
|
|
816
816
|
<Divider component="li" />
|
|
@@ -828,7 +828,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
828
828
|
direction="down"
|
|
829
829
|
drilldownMenu={
|
|
830
830
|
<DrilldownMenu id="drilldownMenuLabels">
|
|
831
|
-
<MenuItem itemId="group:
|
|
831
|
+
<MenuItem itemId="group:labels_breadcrumb" direction="up">
|
|
832
832
|
Labels
|
|
833
833
|
</MenuItem>
|
|
834
834
|
<Divider component="li" />
|
|
@@ -852,7 +852,7 @@ class MenuWithDrilldown extends React.Component {
|
|
|
852
852
|
direction="down"
|
|
853
853
|
drilldownMenu={
|
|
854
854
|
<DrilldownMenu id="drilldownMenuStorage">
|
|
855
|
-
<MenuItem itemId="group:
|
|
855
|
+
<MenuItem itemId="group:storage_breadcrumb" icon={<StorageDomainIcon aria-hidden />} direction="up">
|
|
856
856
|
Add storage
|
|
857
857
|
</MenuItem>
|
|
858
858
|
<Divider component="li" />
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Composable menu
|
|
3
|
+
section: demos
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Link } from '@reach/router';
|
|
7
|
+
|
|
8
|
+
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
|
|
9
|
+
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
|
|
10
|
+
import TableIcon from '@patternfly/react-icons/dist/esm/icons/table-icon';
|
|
11
|
+
import StorageDomainIcon from '@patternfly/react-icons/dist/esm/icons/storage-domain-icon';
|
|
12
|
+
import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
|
|
13
|
+
import LayerGroupIcon from '@patternfly/react-icons/dist/esm/icons/layer-group-icon';
|
|
14
|
+
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
|
|
15
|
+
import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon';
|
|
16
|
+
import ClipboardIcon from '@patternfly/react-icons/dist/esm/icons/clipboard-icon';
|
|
17
|
+
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
|
|
18
|
+
import ThIcon from '@patternfly/react-icons/dist/esm/icons/th-icon';
|
|
19
|
+
import pfIcon from './examples/pf-logo-small.svg';
|
|
20
|
+
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
|
|
21
|
+
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
22
|
+
import avatarImg from './examples/avatarImg.svg';
|
|
23
|
+
|
|
24
|
+
## Demos
|
|
25
|
+
|
|
26
|
+
Composable menus currently require consumer keyboard handling and use of our undocumented [popper.js](https://popper.js.org/) wrapper component called Popper. We understand this is inconvientent boilerplate and these examples will be updated to use [Dropdown](/components/dropdown) in a future release.
|
|
27
|
+
|
|
28
|
+
### Composable simple dropdown
|
|
29
|
+
|
|
30
|
+
```ts file="./examples/ComposableSimpleDropdown.tsx"
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Composable actions menu
|
|
35
|
+
|
|
36
|
+
```ts file="./examples/ComposableActionsMenu.tsx"
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Composable simple select
|
|
41
|
+
|
|
42
|
+
```ts file="./examples/ComposableSimpleSelect.tsx"
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Composable drilldown menu
|
|
47
|
+
|
|
48
|
+
```ts isBeta file="./examples/ComposableDrilldownMenu.tsx"
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Composable tree view menu
|
|
53
|
+
|
|
54
|
+
```ts file="./examples/ComposableTreeViewMenu.tsx"
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Composable flyout
|
|
59
|
+
|
|
60
|
+
The flyout will automatically position to the left or top if it would otherwise go outside the window. The menu must be placed in a container outside the main content like Popper, [Popover](/components/popover) or [Tooltip](/components/tooltip) since it may go over the side nav.
|
|
61
|
+
|
|
62
|
+
```ts isBeta file="./examples/ComposableFlyout.tsx"
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Composable application launcher
|
|
67
|
+
|
|
68
|
+
```ts file="./examples/ComposableApplicationLauncher.tsx"
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Composable context selector
|
|
73
|
+
|
|
74
|
+
```ts file="./examples/ComposableContextSelector.tsx"
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Composable options menu variants
|
|
79
|
+
|
|
80
|
+
```ts file="./examples/ComposableOptionsMenuVariants.tsx"
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Composable dropdown variants
|
|
85
|
+
|
|
86
|
+
```ts file="./examples/ComposableDropdwnVariants.tsx"
|
|
87
|
+
|
|
88
|
+
```
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggle, Menu, MenuList, MenuItem, MenuGroup, MenuItemAction, Popper } from '@patternfly/react-core';
|
|
3
|
+
import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon';
|
|
4
|
+
import ClipboardIcon from '@patternfly/react-icons/dist/esm/icons/clipboard-icon';
|
|
5
|
+
import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
|
|
6
|
+
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
|
|
7
|
+
|
|
8
|
+
export const ComposableActionsMenu: React.FunctionComponent = () => {
|
|
9
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
10
|
+
const [selectedItems, setSelectedItems] = React.useState<number[]>([]);
|
|
11
|
+
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
12
|
+
const menuRef = React.useRef<HTMLDivElement>();
|
|
13
|
+
|
|
14
|
+
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
15
|
+
if (isOpen && menuRef.current.contains(event.target as Node)) {
|
|
16
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
17
|
+
setIsOpen(!isOpen);
|
|
18
|
+
toggleRef.current.focus();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
24
|
+
if (isOpen && !menuRef.current.contains(event.target as Node)) {
|
|
25
|
+
setIsOpen(false);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
31
|
+
window.addEventListener('click', handleClickOutside);
|
|
32
|
+
return () => {
|
|
33
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
34
|
+
window.removeEventListener('click', handleClickOutside);
|
|
35
|
+
};
|
|
36
|
+
}, [isOpen, menuRef]);
|
|
37
|
+
|
|
38
|
+
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: number) => {
|
|
39
|
+
if (selectedItems.includes(itemId)) {
|
|
40
|
+
setSelectedItems(selectedItems.filter(id => id !== itemId));
|
|
41
|
+
} else {
|
|
42
|
+
setSelectedItems([...selectedItems, itemId]);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const onToggleClick = (ev: React.MouseEvent) => {
|
|
47
|
+
ev.stopPropagation(); // Stop handleClickOutside from handling
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
if (menuRef.current) {
|
|
50
|
+
const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
|
|
51
|
+
firstElement && (firstElement as HTMLElement).focus();
|
|
52
|
+
}
|
|
53
|
+
}, 0);
|
|
54
|
+
setIsOpen(!isOpen);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const toggle = (
|
|
58
|
+
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
|
|
59
|
+
{isOpen ? 'Expanded' : 'Collapsed'}
|
|
60
|
+
</MenuToggle>
|
|
61
|
+
);
|
|
62
|
+
const menu = (
|
|
63
|
+
<Menu
|
|
64
|
+
ref={menuRef}
|
|
65
|
+
// eslint-disable-next-line no-console
|
|
66
|
+
onActionClick={(event, itemId, actionId) => console.log(`clicked on ${itemId} - ${actionId}`)}
|
|
67
|
+
onSelect={onSelect}
|
|
68
|
+
style={
|
|
69
|
+
{
|
|
70
|
+
'--pf-c-menu--Width': '300px'
|
|
71
|
+
} as React.CSSProperties
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<MenuGroup label="Actions">
|
|
75
|
+
<MenuList>
|
|
76
|
+
<MenuItem
|
|
77
|
+
isSelected={selectedItems.includes(0)}
|
|
78
|
+
actions={
|
|
79
|
+
<MenuItemAction
|
|
80
|
+
icon={<CodeBranchIcon aria-hidden />}
|
|
81
|
+
actionId="code"
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
onClick={() => console.log('clicked on code icon')}
|
|
84
|
+
aria-label="Code"
|
|
85
|
+
/>
|
|
86
|
+
}
|
|
87
|
+
description="This is a description"
|
|
88
|
+
itemId={0}
|
|
89
|
+
>
|
|
90
|
+
Item 1
|
|
91
|
+
</MenuItem>
|
|
92
|
+
<MenuItem
|
|
93
|
+
isDisabled
|
|
94
|
+
isSelected={selectedItems.includes(1)}
|
|
95
|
+
actions={<MenuItemAction icon={<BellIcon aria-hidden />} actionId="alert" aria-label="Alert" />}
|
|
96
|
+
description="This is a description"
|
|
97
|
+
itemId={1}
|
|
98
|
+
>
|
|
99
|
+
Item 2
|
|
100
|
+
</MenuItem>
|
|
101
|
+
<MenuItem
|
|
102
|
+
isSelected={selectedItems.includes(2)}
|
|
103
|
+
actions={<MenuItemAction icon={<ClipboardIcon aria-hidden />} actionId="copy" aria-label="Copy" />}
|
|
104
|
+
itemId={2}
|
|
105
|
+
>
|
|
106
|
+
Item 3
|
|
107
|
+
</MenuItem>
|
|
108
|
+
<MenuItem
|
|
109
|
+
isSelected={selectedItems.includes(3)}
|
|
110
|
+
actions={<MenuItemAction icon={<BarsIcon aria-hidden />} actionId="expand" aria-label="Expand" />}
|
|
111
|
+
description="This is a description"
|
|
112
|
+
itemId={3}
|
|
113
|
+
>
|
|
114
|
+
Item 4
|
|
115
|
+
</MenuItem>
|
|
116
|
+
</MenuList>
|
|
117
|
+
</MenuGroup>
|
|
118
|
+
</Menu>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return <Popper trigger={toggle} popper={menu} isVisible={isOpen} popperMatchesTriggerWidth={false} />;
|
|
122
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MenuToggle,
|
|
4
|
+
Menu,
|
|
5
|
+
MenuContent,
|
|
6
|
+
MenuList,
|
|
7
|
+
MenuItem,
|
|
8
|
+
MenuGroup,
|
|
9
|
+
MenuInput,
|
|
10
|
+
Popper,
|
|
11
|
+
Tooltip,
|
|
12
|
+
Divider,
|
|
13
|
+
TextInput
|
|
14
|
+
} from '@patternfly/react-core';
|
|
15
|
+
import { Link } from '@reach/router';
|
|
16
|
+
import ThIcon from '@patternfly/react-icons/dist/js/icons/th-icon';
|
|
17
|
+
import pfIcon from 'pf-logo-small.svg';
|
|
18
|
+
|
|
19
|
+
export const ComposableApplicationLauncher: React.FunctionComponent = () => {
|
|
20
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
21
|
+
const [refFullOptions, setRefFullOptions] = React.useState<Element[]>();
|
|
22
|
+
const [favorites, setFavorites] = React.useState<string[]>([]);
|
|
23
|
+
const [filteredIds, setFilteredIds] = React.useState<string[]>(['*']);
|
|
24
|
+
const menuRef = React.useRef<HTMLDivElement>();
|
|
25
|
+
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
26
|
+
const containerRef = React.useRef<HTMLDivElement>();
|
|
27
|
+
|
|
28
|
+
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
29
|
+
if (!isOpen) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (menuRef.current.contains(event.target as Node) || toggleRef.current.contains(event.target as Node)) {
|
|
33
|
+
if (event.key === 'Escape') {
|
|
34
|
+
setIsOpen(!isOpen);
|
|
35
|
+
toggleRef.current.focus();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
41
|
+
if (isOpen && !menuRef.current.contains(event.target as Node)) {
|
|
42
|
+
setIsOpen(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const onToggleClick = (ev: React.MouseEvent) => {
|
|
47
|
+
ev.stopPropagation(); // Stop handleClickOutside from handling
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
if (menuRef.current) {
|
|
50
|
+
const firstElement = menuRef.current.querySelector('li > button,input:not(:disabled)');
|
|
51
|
+
firstElement && (firstElement as HTMLElement).focus();
|
|
52
|
+
setRefFullOptions(Array.from(menuRef.current.querySelectorAll('li:not(li[role=separator])')));
|
|
53
|
+
}
|
|
54
|
+
}, 0);
|
|
55
|
+
setIsOpen(!isOpen);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
60
|
+
window.addEventListener('click', handleClickOutside);
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
64
|
+
window.removeEventListener('click', handleClickOutside);
|
|
65
|
+
};
|
|
66
|
+
}, [isOpen, menuRef]);
|
|
67
|
+
|
|
68
|
+
const toggle = (
|
|
69
|
+
<MenuToggle
|
|
70
|
+
aria-label="Toggle"
|
|
71
|
+
ref={toggleRef}
|
|
72
|
+
variant="plain"
|
|
73
|
+
onClick={onToggleClick}
|
|
74
|
+
isExpanded={isOpen}
|
|
75
|
+
style={{ width: 'auto' }}
|
|
76
|
+
>
|
|
77
|
+
<ThIcon />
|
|
78
|
+
</MenuToggle>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const menuItems = [
|
|
82
|
+
<MenuGroup key="group1" label="Group 1">
|
|
83
|
+
<MenuList>
|
|
84
|
+
<MenuItem itemId="0" id="0" isFavorited={favorites.includes('0')}>
|
|
85
|
+
Application 1
|
|
86
|
+
</MenuItem>
|
|
87
|
+
<MenuItem
|
|
88
|
+
itemId="1"
|
|
89
|
+
id="1"
|
|
90
|
+
isFavorited={favorites.includes('1')}
|
|
91
|
+
to="#default-link2"
|
|
92
|
+
onClick={ev => ev.preventDefault()}
|
|
93
|
+
>
|
|
94
|
+
Application 2
|
|
95
|
+
</MenuItem>
|
|
96
|
+
</MenuList>
|
|
97
|
+
</MenuGroup>,
|
|
98
|
+
<Divider key="group1-divider" />,
|
|
99
|
+
<MenuGroup key="group2" label="Group 2">
|
|
100
|
+
<MenuList>
|
|
101
|
+
<MenuItem
|
|
102
|
+
itemId="2"
|
|
103
|
+
id="2"
|
|
104
|
+
isFavorited={favorites.includes('2')}
|
|
105
|
+
component={props => <Link {...props} to="#router-link" />}
|
|
106
|
+
>
|
|
107
|
+
@reach/router Link
|
|
108
|
+
</MenuItem>
|
|
109
|
+
<MenuItem
|
|
110
|
+
itemId="3"
|
|
111
|
+
id="3"
|
|
112
|
+
isFavorited={favorites.includes('3')}
|
|
113
|
+
isExternalLink
|
|
114
|
+
icon={<img src={pfIcon} />}
|
|
115
|
+
component={props => <Link {...props} to="#router-link2" />}
|
|
116
|
+
>
|
|
117
|
+
@reach/router Link with icon
|
|
118
|
+
</MenuItem>
|
|
119
|
+
</MenuList>
|
|
120
|
+
</MenuGroup>,
|
|
121
|
+
<Divider key="group2-divider" />,
|
|
122
|
+
<MenuList key="other-items">
|
|
123
|
+
<MenuItem key="tooltip-app" isFavorited={favorites.includes('4')} itemId="4" id="4">
|
|
124
|
+
<Tooltip content={<div>Launch Application 3</div>} position="right">
|
|
125
|
+
<span>Application 3 with tooltip</span>
|
|
126
|
+
</Tooltip>
|
|
127
|
+
</MenuItem>
|
|
128
|
+
<MenuItem key="disabled-app" itemId="5" id="5" isDisabled>
|
|
129
|
+
Unavailable Application
|
|
130
|
+
</MenuItem>
|
|
131
|
+
</MenuList>
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const createFavorites = (favIds: string[]) => {
|
|
135
|
+
const favorites = [];
|
|
136
|
+
|
|
137
|
+
menuItems.forEach(item => {
|
|
138
|
+
if (item.type === MenuList) {
|
|
139
|
+
item.props.children.filter(child => {
|
|
140
|
+
if (favIds.includes(child.props.itemId)) {
|
|
141
|
+
favorites.push(child);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} else if (item.type === MenuGroup) {
|
|
145
|
+
item.props.children.props.children.filter(child => {
|
|
146
|
+
if (favIds.includes(child.props.itemId)) {
|
|
147
|
+
favorites.push(child);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
if (favIds.includes(item.props.itemId)) {
|
|
152
|
+
favorites.push(item);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return favorites;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const filterItems = (items: any[], filteredIds: string[]) => {
|
|
161
|
+
if (filteredIds.length === 1 && filteredIds[0] === '*') {
|
|
162
|
+
return items;
|
|
163
|
+
}
|
|
164
|
+
let keepDivider = false;
|
|
165
|
+
const filteredCopy = items
|
|
166
|
+
.map(group => {
|
|
167
|
+
if (group.type === MenuGroup) {
|
|
168
|
+
const filteredGroup = React.cloneElement(group, {
|
|
169
|
+
children: React.cloneElement(group.props.children, {
|
|
170
|
+
children: group.props.children.props.children.filter(child => {
|
|
171
|
+
if (filteredIds.includes(child.props.itemId)) {
|
|
172
|
+
return child;
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
});
|
|
177
|
+
const filteredList = filteredGroup.props.children;
|
|
178
|
+
if (filteredList.props.children.length > 0) {
|
|
179
|
+
keepDivider = true;
|
|
180
|
+
return filteredGroup;
|
|
181
|
+
} else {
|
|
182
|
+
keepDivider = false;
|
|
183
|
+
}
|
|
184
|
+
} else if (group.type === MenuList) {
|
|
185
|
+
const filteredGroup = React.cloneElement(group, {
|
|
186
|
+
children: group.props.children.filter(child => {
|
|
187
|
+
if (filteredIds.includes(child.props.itemId)) {
|
|
188
|
+
return child;
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
if (filteredGroup.props.children.length > 0) {
|
|
193
|
+
keepDivider = true;
|
|
194
|
+
return filteredGroup;
|
|
195
|
+
} else {
|
|
196
|
+
keepDivider = false;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if ((keepDivider && group.type === Divider) || filteredIds.includes(group.props.itemId)) {
|
|
200
|
+
return group;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
.filter(newGroup => newGroup);
|
|
205
|
+
|
|
206
|
+
if (filteredCopy.length > 0) {
|
|
207
|
+
const lastGroup = filteredCopy.pop();
|
|
208
|
+
if (lastGroup.type !== Divider) {
|
|
209
|
+
filteredCopy.push(lastGroup);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return filteredCopy;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const onTextChange = (textValue: string) => {
|
|
217
|
+
if (textValue === '') {
|
|
218
|
+
setFilteredIds(['*']);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const filteredIds = refFullOptions
|
|
223
|
+
.filter(item => (item as HTMLElement).innerText.toLowerCase().includes(textValue.toString().toLowerCase()))
|
|
224
|
+
.map(item => item.id);
|
|
225
|
+
setFilteredIds(filteredIds);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const onFavorite = (event: any, itemId: string, actionId: string) => {
|
|
229
|
+
event.stopPropagation();
|
|
230
|
+
if (actionId === 'fav') {
|
|
231
|
+
const isFavorite = favorites.includes(itemId);
|
|
232
|
+
if (isFavorite) {
|
|
233
|
+
setFavorites(favorites.filter(fav => fav !== itemId));
|
|
234
|
+
} else {
|
|
235
|
+
setFavorites([...favorites, itemId]);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const filteredFavorites = filterItems(createFavorites(favorites), filteredIds);
|
|
241
|
+
const filteredItems = filterItems(menuItems, filteredIds);
|
|
242
|
+
if (filteredItems.length === 0) {
|
|
243
|
+
filteredItems.push(<MenuItem key="no-items">No results found</MenuItem>);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const menu = (
|
|
247
|
+
// eslint-disable-next-line no-console
|
|
248
|
+
<Menu ref={menuRef} onActionClick={onFavorite} onSelect={(_ev, itemId) => console.log('selected', itemId)}>
|
|
249
|
+
<MenuInput>
|
|
250
|
+
<TextInput
|
|
251
|
+
aria-label="Filter menu items"
|
|
252
|
+
iconVariant="search"
|
|
253
|
+
type="search"
|
|
254
|
+
onChange={value => onTextChange(value)}
|
|
255
|
+
/>
|
|
256
|
+
</MenuInput>
|
|
257
|
+
<Divider />
|
|
258
|
+
<MenuContent>
|
|
259
|
+
{filteredFavorites.length > 0 && (
|
|
260
|
+
<React.Fragment>
|
|
261
|
+
<MenuGroup key="favorites-group" label="Favorites">
|
|
262
|
+
<MenuList>{filteredFavorites}</MenuList>
|
|
263
|
+
</MenuGroup>
|
|
264
|
+
<Divider key="favorites-divider" />
|
|
265
|
+
</React.Fragment>
|
|
266
|
+
)}
|
|
267
|
+
{filteredItems}
|
|
268
|
+
</MenuContent>
|
|
269
|
+
</Menu>
|
|
270
|
+
);
|
|
271
|
+
return (
|
|
272
|
+
<div ref={containerRef}>
|
|
273
|
+
<Popper
|
|
274
|
+
trigger={toggle}
|
|
275
|
+
popper={menu}
|
|
276
|
+
isVisible={isOpen}
|
|
277
|
+
popperMatchesTriggerWidth={false}
|
|
278
|
+
appendTo={containerRef.current}
|
|
279
|
+
/>
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
};
|