@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
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MenuToggle,
|
|
4
|
+
Menu,
|
|
5
|
+
MenuContent,
|
|
6
|
+
MenuFooter,
|
|
7
|
+
MenuList,
|
|
8
|
+
MenuItem,
|
|
9
|
+
MenuInput,
|
|
10
|
+
Popper,
|
|
11
|
+
Divider,
|
|
12
|
+
TextInput,
|
|
13
|
+
InputGroup,
|
|
14
|
+
Button,
|
|
15
|
+
ButtonVariant
|
|
16
|
+
} from '@patternfly/react-core';
|
|
17
|
+
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
|
|
18
|
+
|
|
19
|
+
interface ItemData {
|
|
20
|
+
text: string;
|
|
21
|
+
href?: string;
|
|
22
|
+
isDisabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ItemArrayType = (ItemData | string)[];
|
|
26
|
+
|
|
27
|
+
export const ComposableContextSelector: React.FunctionComponent = () => {
|
|
28
|
+
const items: ItemArrayType = [
|
|
29
|
+
{
|
|
30
|
+
text: 'Action'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
text: 'Link',
|
|
34
|
+
href: '#'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
text: 'Disabled action',
|
|
38
|
+
isDisabled: true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
text: 'Disabled link',
|
|
42
|
+
href: '#',
|
|
43
|
+
isDisabled: true
|
|
44
|
+
},
|
|
45
|
+
'My project',
|
|
46
|
+
'OpenShift cluster',
|
|
47
|
+
'Production Ansible',
|
|
48
|
+
'AWS',
|
|
49
|
+
'Azure',
|
|
50
|
+
'My project 2',
|
|
51
|
+
'OpenShift cluster ',
|
|
52
|
+
'Production Ansible 2 ',
|
|
53
|
+
'AWS 2',
|
|
54
|
+
'Azure 2'
|
|
55
|
+
];
|
|
56
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
57
|
+
const [selected, setSelected] = React.useState<ItemData | string>(
|
|
58
|
+
typeof items[0] === 'string' ? items[0] : items[0].text
|
|
59
|
+
);
|
|
60
|
+
const [filteredItems, setFilteredItems] = React.useState<ItemArrayType>(items);
|
|
61
|
+
const [searchInputValue, setSearchInputValue] = React.useState<string>('');
|
|
62
|
+
const menuRef = React.useRef<HTMLDivElement>();
|
|
63
|
+
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
64
|
+
const menuFooterBtnRef = React.useRef<HTMLButtonElement>();
|
|
65
|
+
|
|
66
|
+
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
67
|
+
if (!isOpen) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (menuFooterBtnRef.current.contains(event.target as Node)) {
|
|
71
|
+
if (event.key === 'Tab') {
|
|
72
|
+
if (event.shiftKey) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
setIsOpen(!isOpen);
|
|
76
|
+
toggleRef.current.focus();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (menuRef.current.contains(event.target as Node)) {
|
|
80
|
+
if (event.key === 'Escape') {
|
|
81
|
+
setIsOpen(!isOpen);
|
|
82
|
+
toggleRef.current.focus();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
88
|
+
if (isOpen && !menuRef.current.contains(event.target as Node)) {
|
|
89
|
+
setIsOpen(false);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
95
|
+
window.addEventListener('click', handleClickOutside);
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
99
|
+
window.removeEventListener('click', handleClickOutside);
|
|
100
|
+
};
|
|
101
|
+
}, [isOpen, menuRef]);
|
|
102
|
+
|
|
103
|
+
const onToggleClick = (ev: React.MouseEvent) => {
|
|
104
|
+
ev.stopPropagation(); // Stop handleClickOutside from handling
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
if (menuRef.current) {
|
|
107
|
+
const firstElement = menuRef.current.querySelector('li > button,input:not(:disabled)');
|
|
108
|
+
firstElement && (firstElement as HTMLElement).focus();
|
|
109
|
+
}
|
|
110
|
+
}, 0);
|
|
111
|
+
setIsOpen(!isOpen);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const toggle = (
|
|
115
|
+
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
|
|
116
|
+
{selected}
|
|
117
|
+
</MenuToggle>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: string) => {
|
|
121
|
+
setSelected(itemId);
|
|
122
|
+
setIsOpen(!isOpen);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const onSearchInputChange = (value: string) => {
|
|
126
|
+
setSearchInputValue(value);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const onSearchButtonClick = () => {
|
|
130
|
+
const filtered =
|
|
131
|
+
searchInputValue === ''
|
|
132
|
+
? items
|
|
133
|
+
: items.filter(item => {
|
|
134
|
+
const str = typeof item === 'string' ? item : item.text;
|
|
135
|
+
return str.toLowerCase().indexOf(searchInputValue.toLowerCase()) !== -1;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
setFilteredItems(filtered || []);
|
|
139
|
+
setIsOpen(true); // Keep menu open after search executed
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const onEnterPressed = (event: React.KeyboardEvent) => {
|
|
143
|
+
if (event.key === 'Enter') {
|
|
144
|
+
onSearchButtonClick();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const menu = (
|
|
149
|
+
<Menu
|
|
150
|
+
ref={menuRef}
|
|
151
|
+
id="context-selector"
|
|
152
|
+
onSelect={onSelect}
|
|
153
|
+
isScrollable
|
|
154
|
+
style={
|
|
155
|
+
{
|
|
156
|
+
'--pf-c-menu--Width': '300px'
|
|
157
|
+
} as React.CSSProperties
|
|
158
|
+
}
|
|
159
|
+
>
|
|
160
|
+
<MenuInput>
|
|
161
|
+
<InputGroup>
|
|
162
|
+
<TextInput
|
|
163
|
+
value={searchInputValue}
|
|
164
|
+
type="search"
|
|
165
|
+
placeholder="Search"
|
|
166
|
+
onChange={onSearchInputChange}
|
|
167
|
+
onKeyPress={onEnterPressed}
|
|
168
|
+
aria-labelledby="pf-context-selector-search-button-id-1"
|
|
169
|
+
/>
|
|
170
|
+
<Button
|
|
171
|
+
variant={ButtonVariant.control}
|
|
172
|
+
aria-label="Search menu items"
|
|
173
|
+
id="pf-context-selector-search-button-id-1"
|
|
174
|
+
onClick={onSearchButtonClick}
|
|
175
|
+
>
|
|
176
|
+
<SearchIcon aria-hidden="true" />
|
|
177
|
+
</Button>
|
|
178
|
+
</InputGroup>
|
|
179
|
+
</MenuInput>
|
|
180
|
+
<Divider />
|
|
181
|
+
<MenuContent maxMenuHeight="200px">
|
|
182
|
+
<MenuList>
|
|
183
|
+
{filteredItems.map((item, index) => {
|
|
184
|
+
const [itemText, isDisabled, href] =
|
|
185
|
+
typeof item === 'string' ? [item, null, null] : [item.text, item.isDisabled || null, item.href || null];
|
|
186
|
+
return (
|
|
187
|
+
<MenuItem itemId={itemText} key={index} isDisabled={isDisabled} to={href}>
|
|
188
|
+
{itemText}
|
|
189
|
+
</MenuItem>
|
|
190
|
+
);
|
|
191
|
+
})}
|
|
192
|
+
</MenuList>
|
|
193
|
+
</MenuContent>
|
|
194
|
+
<MenuFooter>
|
|
195
|
+
<Button ref={menuFooterBtnRef} variant="link" isInline>
|
|
196
|
+
Action
|
|
197
|
+
</Button>
|
|
198
|
+
</MenuFooter>
|
|
199
|
+
</Menu>
|
|
200
|
+
);
|
|
201
|
+
return <Popper trigger={toggle} popper={menu} isVisible={isOpen} popperMatchesTriggerWidth={false} />;
|
|
202
|
+
};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MenuToggle,
|
|
4
|
+
Menu,
|
|
5
|
+
MenuContent,
|
|
6
|
+
MenuList,
|
|
7
|
+
MenuItem,
|
|
8
|
+
DrilldownMenu,
|
|
9
|
+
Divider,
|
|
10
|
+
Popper
|
|
11
|
+
} from '@patternfly/react-core';
|
|
12
|
+
import StorageDomainIcon from '@patternfly/react-icons/dist/esm/icons/storage-domain-icon';
|
|
13
|
+
import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
|
|
14
|
+
import LayerGroupIcon from '@patternfly/react-icons/dist/esm/icons/layer-group-icon';
|
|
15
|
+
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
|
|
16
|
+
|
|
17
|
+
interface MenuHeightsType {
|
|
18
|
+
[id: string]: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ComposableDrilldownMenu: React.FunctionComponent = () => {
|
|
22
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
23
|
+
const [activeMenu, setActiveMenu] = React.useState<string>('rootMenu');
|
|
24
|
+
const [menuDrilledIn, setMenuDrilledIn] = React.useState<string[]>([]);
|
|
25
|
+
const [drilldownPath, setDrilldownPath] = React.useState<string[]>([]);
|
|
26
|
+
const [menuHeights, setMenuHeights] = React.useState<MenuHeightsType>({});
|
|
27
|
+
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
28
|
+
const menuRef = React.useRef<HTMLDivElement>();
|
|
29
|
+
|
|
30
|
+
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
31
|
+
if (isOpen && menuRef.current.contains(event.target as Node)) {
|
|
32
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
33
|
+
setIsOpen(!isOpen);
|
|
34
|
+
toggleRef.current.focus();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
40
|
+
if (isOpen && !menuRef.current.contains(event.target as Node)) {
|
|
41
|
+
setIsOpen(false);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
47
|
+
window.addEventListener('click', handleClickOutside);
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
50
|
+
window.removeEventListener('click', handleClickOutside);
|
|
51
|
+
};
|
|
52
|
+
}, [isOpen, menuRef]);
|
|
53
|
+
|
|
54
|
+
const onToggleClick = (ev: React.MouseEvent) => {
|
|
55
|
+
ev.stopPropagation(); // Stop handleClickOutside from handling
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
if (menuRef.current) {
|
|
58
|
+
const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
|
|
59
|
+
firstElement && (firstElement as HTMLElement).focus();
|
|
60
|
+
}
|
|
61
|
+
}, 0);
|
|
62
|
+
setIsOpen(!isOpen);
|
|
63
|
+
setMenuDrilledIn([]);
|
|
64
|
+
setDrilldownPath([]);
|
|
65
|
+
setActiveMenu('rootMenu');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const drillIn = (fromMenuId: string, toMenuId: string, pathId: string) => {
|
|
69
|
+
setMenuDrilledIn([...menuDrilledIn, fromMenuId]);
|
|
70
|
+
setDrilldownPath([...drilldownPath, pathId]);
|
|
71
|
+
setActiveMenu(toMenuId);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const drillOut = (toMenuId: string) => {
|
|
75
|
+
setMenuDrilledIn(menuDrilledIn.slice(0, menuDrilledIn.length - 1));
|
|
76
|
+
setDrilldownPath(drilldownPath.slice(0, drilldownPath.length - 1));
|
|
77
|
+
setActiveMenu(toMenuId);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const setHeight = (menuId: string, height: number) => {
|
|
81
|
+
if (!menuHeights[menuId]) {
|
|
82
|
+
setMenuHeights({
|
|
83
|
+
...menuHeights,
|
|
84
|
+
[menuId]: height
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const toggle = (
|
|
90
|
+
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
|
|
91
|
+
{isOpen ? 'Expanded' : 'Collapsed'}
|
|
92
|
+
</MenuToggle>
|
|
93
|
+
);
|
|
94
|
+
const menu = (
|
|
95
|
+
<Menu
|
|
96
|
+
id="rootMenu"
|
|
97
|
+
containsDrilldown
|
|
98
|
+
drilldownItemPath={drilldownPath}
|
|
99
|
+
drilledInMenus={menuDrilledIn}
|
|
100
|
+
activeMenu={activeMenu}
|
|
101
|
+
onDrillIn={drillIn}
|
|
102
|
+
onDrillOut={drillOut}
|
|
103
|
+
onGetMenuHeight={setHeight}
|
|
104
|
+
ref={menuRef}
|
|
105
|
+
style={
|
|
106
|
+
{
|
|
107
|
+
'--pf-c-menu--Width': '300px'
|
|
108
|
+
} as React.CSSProperties
|
|
109
|
+
}
|
|
110
|
+
>
|
|
111
|
+
<MenuContent menuHeight={`${menuHeights[activeMenu]}px`}>
|
|
112
|
+
<MenuList>
|
|
113
|
+
<MenuItem
|
|
114
|
+
itemId="group:start_rollout"
|
|
115
|
+
direction="down"
|
|
116
|
+
drilldownMenu={
|
|
117
|
+
<DrilldownMenu id="drilldownMenuStart">
|
|
118
|
+
<MenuItem itemId="group:start_rollout_breadcrumb" direction="up">
|
|
119
|
+
Start rollout
|
|
120
|
+
</MenuItem>
|
|
121
|
+
<Divider component="li" />
|
|
122
|
+
<MenuItem
|
|
123
|
+
itemId="group:app_grouping"
|
|
124
|
+
description="Groups A-C"
|
|
125
|
+
direction="down"
|
|
126
|
+
drilldownMenu={
|
|
127
|
+
<DrilldownMenu id="drilldownMenuStartGrouping">
|
|
128
|
+
<MenuItem itemId="group:app_grouping_breadcrumb" direction="up">
|
|
129
|
+
Application Grouping
|
|
130
|
+
</MenuItem>
|
|
131
|
+
<Divider component="li" />
|
|
132
|
+
<MenuItem itemId="group_a">Group A</MenuItem>
|
|
133
|
+
<MenuItem itemId="group_b">Group B</MenuItem>
|
|
134
|
+
<MenuItem itemId="group_c">Group C</MenuItem>
|
|
135
|
+
</DrilldownMenu>
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
Application Grouping
|
|
139
|
+
</MenuItem>
|
|
140
|
+
<MenuItem itemId="count">Count</MenuItem>
|
|
141
|
+
<MenuItem
|
|
142
|
+
itemId="group:labels"
|
|
143
|
+
direction="down"
|
|
144
|
+
drilldownMenu={
|
|
145
|
+
<DrilldownMenu id="drilldownMenuStartLabels">
|
|
146
|
+
<MenuItem itemId="group:labels_breadcrumb" direction="up">
|
|
147
|
+
Labels
|
|
148
|
+
</MenuItem>
|
|
149
|
+
<Divider component="li" />
|
|
150
|
+
<MenuItem itemId="label_1">Label 1</MenuItem>
|
|
151
|
+
<MenuItem itemId="label_2">Label 2</MenuItem>
|
|
152
|
+
<MenuItem itemId="label_3">Label 3</MenuItem>
|
|
153
|
+
</DrilldownMenu>
|
|
154
|
+
}
|
|
155
|
+
>
|
|
156
|
+
Labels
|
|
157
|
+
</MenuItem>
|
|
158
|
+
<MenuItem itemId="annotations">Annotations</MenuItem>
|
|
159
|
+
</DrilldownMenu>
|
|
160
|
+
}
|
|
161
|
+
>
|
|
162
|
+
Start rollout
|
|
163
|
+
</MenuItem>
|
|
164
|
+
<MenuItem
|
|
165
|
+
itemId="group:pause_rollout"
|
|
166
|
+
direction="down"
|
|
167
|
+
drilldownMenu={
|
|
168
|
+
<DrilldownMenu id="drilldownMenuPause">
|
|
169
|
+
<MenuItem itemId="group:pause_rollout_breadcrumb" direction="up">
|
|
170
|
+
Pause rollouts
|
|
171
|
+
</MenuItem>
|
|
172
|
+
<Divider component="li" />
|
|
173
|
+
<MenuItem
|
|
174
|
+
itemId="group:app_grouping"
|
|
175
|
+
description="Groups A-C"
|
|
176
|
+
direction="down"
|
|
177
|
+
drilldownMenu={
|
|
178
|
+
<DrilldownMenu id="drilldownMenuGrouping">
|
|
179
|
+
<MenuItem itemId="group:app_grouping_breadcrumb" direction="up">
|
|
180
|
+
Application Grouping
|
|
181
|
+
</MenuItem>
|
|
182
|
+
<Divider component="li" />
|
|
183
|
+
<MenuItem itemId="group_a">Group A</MenuItem>
|
|
184
|
+
<MenuItem itemId="group_b">Group B</MenuItem>
|
|
185
|
+
<MenuItem itemId="group_c">Group C</MenuItem>
|
|
186
|
+
</DrilldownMenu>
|
|
187
|
+
}
|
|
188
|
+
>
|
|
189
|
+
Application Grouping
|
|
190
|
+
</MenuItem>
|
|
191
|
+
<MenuItem itemId="count">Count</MenuItem>
|
|
192
|
+
<MenuItem
|
|
193
|
+
itemId="group:labels"
|
|
194
|
+
direction="down"
|
|
195
|
+
drilldownMenu={
|
|
196
|
+
<DrilldownMenu id="drilldownMenuLabels">
|
|
197
|
+
<MenuItem itemId="group:labels_breadcrumb" direction="up">
|
|
198
|
+
Labels
|
|
199
|
+
</MenuItem>
|
|
200
|
+
<Divider component="li" />
|
|
201
|
+
<MenuItem itemId="label_1">Label 1</MenuItem>
|
|
202
|
+
<MenuItem itemId="label_2">Label 2</MenuItem>
|
|
203
|
+
<MenuItem itemId="label_3">Label 3</MenuItem>
|
|
204
|
+
</DrilldownMenu>
|
|
205
|
+
}
|
|
206
|
+
>
|
|
207
|
+
Labels
|
|
208
|
+
</MenuItem>
|
|
209
|
+
<MenuItem itemId="annotations">Annotations</MenuItem>
|
|
210
|
+
</DrilldownMenu>
|
|
211
|
+
}
|
|
212
|
+
>
|
|
213
|
+
Pause rollouts
|
|
214
|
+
</MenuItem>
|
|
215
|
+
<MenuItem
|
|
216
|
+
itemId="group:storage"
|
|
217
|
+
icon={<StorageDomainIcon aria-hidden />}
|
|
218
|
+
direction="down"
|
|
219
|
+
drilldownMenu={
|
|
220
|
+
<DrilldownMenu id="drilldownMenuStorage">
|
|
221
|
+
<MenuItem itemId="group:storage_breadcrumb" icon={<StorageDomainIcon aria-hidden />} direction="up">
|
|
222
|
+
Add storage
|
|
223
|
+
</MenuItem>
|
|
224
|
+
<Divider component="li" />
|
|
225
|
+
<MenuItem icon={<CodeBranchIcon aria-hidden />} itemId="git">
|
|
226
|
+
From Git
|
|
227
|
+
</MenuItem>
|
|
228
|
+
<MenuItem icon={<LayerGroupIcon aria-hidden />} itemId="container">
|
|
229
|
+
Container Image
|
|
230
|
+
</MenuItem>
|
|
231
|
+
<MenuItem icon={<CubeIcon aria-hidden />} itemId="docker">
|
|
232
|
+
Docker File
|
|
233
|
+
</MenuItem>
|
|
234
|
+
</DrilldownMenu>
|
|
235
|
+
}
|
|
236
|
+
>
|
|
237
|
+
Add storage
|
|
238
|
+
</MenuItem>
|
|
239
|
+
<MenuItem itemId="edit">Edit</MenuItem>
|
|
240
|
+
<MenuItem itemId="delete_deployment">Delete deployment config</MenuItem>
|
|
241
|
+
</MenuList>
|
|
242
|
+
</MenuContent>
|
|
243
|
+
</Menu>
|
|
244
|
+
);
|
|
245
|
+
return <Popper trigger={toggle} popper={menu} isVisible={isOpen} popperMatchesTriggerWidth={false} />;
|
|
246
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
MenuToggle,
|
|
5
|
+
Menu,
|
|
6
|
+
MenuContent,
|
|
7
|
+
MenuList,
|
|
8
|
+
MenuItem,
|
|
9
|
+
MenuGroup,
|
|
10
|
+
Popper,
|
|
11
|
+
Divider,
|
|
12
|
+
ToggleGroup,
|
|
13
|
+
ToggleGroupItem,
|
|
14
|
+
Avatar,
|
|
15
|
+
MenuInput
|
|
16
|
+
} from '@patternfly/react-core';
|
|
17
|
+
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
|
|
18
|
+
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
19
|
+
import avatarImg from 'avatarImg.svg';
|
|
20
|
+
|
|
21
|
+
export const ComposableDropdwnVariants: React.FunctionComponent = () => {
|
|
22
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
23
|
+
const [toggleSelected, setToggleSelected] = React.useState<string>('basic');
|
|
24
|
+
const menuRef = React.useRef<HTMLDivElement>();
|
|
25
|
+
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
26
|
+
|
|
27
|
+
const handleToggleSwitch = (selected: boolean, e: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
|
|
28
|
+
setToggleSelected(e.currentTarget.id);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
32
|
+
if (isOpen && menuRef && menuRef.current && menuRef.current.contains(event.target as Node)) {
|
|
33
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
34
|
+
setIsOpen(!isOpen);
|
|
35
|
+
toggleRef.current.focus();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
41
|
+
if (isOpen && menuRef && menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
|
42
|
+
setIsOpen(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
48
|
+
window.addEventListener('click', handleClickOutside);
|
|
49
|
+
|
|
50
|
+
return () => {
|
|
51
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
52
|
+
window.removeEventListener('click', handleClickOutside);
|
|
53
|
+
};
|
|
54
|
+
}, [isOpen, menuRef]);
|
|
55
|
+
|
|
56
|
+
const onToggleClick = (ev: React.MouseEvent) => {
|
|
57
|
+
ev.stopPropagation(); // Stop handleClickOutside from handling
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
if (menuRef.current) {
|
|
60
|
+
const firstElement = menuRef.current.querySelector('li > button,input:not(:disabled),a');
|
|
61
|
+
firstElement && (firstElement as HTMLElement).focus();
|
|
62
|
+
}
|
|
63
|
+
}, 0);
|
|
64
|
+
setIsOpen(!isOpen);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const onSelect = (ev: React.MouseEvent<Element, MouseEvent>, itemId: string) => {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.log(`Menu item ${itemId} selected`);
|
|
70
|
+
setIsOpen(false);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const buildToggle = () => {
|
|
74
|
+
switch (toggleSelected) {
|
|
75
|
+
case 'basic':
|
|
76
|
+
return (
|
|
77
|
+
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
|
|
78
|
+
Dropdown
|
|
79
|
+
</MenuToggle>
|
|
80
|
+
);
|
|
81
|
+
case 'kebab':
|
|
82
|
+
return (
|
|
83
|
+
<MenuToggle
|
|
84
|
+
ref={toggleRef}
|
|
85
|
+
onClick={onToggleClick}
|
|
86
|
+
isExpanded={isOpen}
|
|
87
|
+
variant="plain"
|
|
88
|
+
aria-label="plain kebab"
|
|
89
|
+
>
|
|
90
|
+
<EllipsisVIcon />
|
|
91
|
+
</MenuToggle>
|
|
92
|
+
);
|
|
93
|
+
case 'badge':
|
|
94
|
+
return (
|
|
95
|
+
<MenuToggle
|
|
96
|
+
ref={toggleRef}
|
|
97
|
+
onClick={onToggleClick}
|
|
98
|
+
isExpanded={isOpen}
|
|
99
|
+
variant="plain"
|
|
100
|
+
aria-label="plain badge"
|
|
101
|
+
>
|
|
102
|
+
<Badge>
|
|
103
|
+
4
|
|
104
|
+
<span>
|
|
105
|
+
<CaretDownIcon />
|
|
106
|
+
</span>
|
|
107
|
+
</Badge>
|
|
108
|
+
</MenuToggle>
|
|
109
|
+
);
|
|
110
|
+
case 'image':
|
|
111
|
+
return (
|
|
112
|
+
<MenuToggle
|
|
113
|
+
ref={toggleRef}
|
|
114
|
+
icon={<Avatar src={avatarImg} alt="avatar" />}
|
|
115
|
+
onClick={onToggleClick}
|
|
116
|
+
isExpanded={isOpen}
|
|
117
|
+
>
|
|
118
|
+
Ned Username
|
|
119
|
+
</MenuToggle>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const menu =
|
|
125
|
+
toggleSelected === 'image' ? (
|
|
126
|
+
<Menu ref={menuRef} id="dropdown-menu" onSelect={onSelect}>
|
|
127
|
+
<MenuInput>Unselectable text displayed at the top of the menu</MenuInput>
|
|
128
|
+
<Divider />
|
|
129
|
+
<MenuContent>
|
|
130
|
+
<MenuItem
|
|
131
|
+
itemId={0}
|
|
132
|
+
to="#default-link0"
|
|
133
|
+
// just for demo so that navigation is not triggered
|
|
134
|
+
onClick={event => event.preventDefault()}
|
|
135
|
+
>
|
|
136
|
+
My profile
|
|
137
|
+
</MenuItem>
|
|
138
|
+
<MenuItem
|
|
139
|
+
itemId={1}
|
|
140
|
+
to="#default-link1"
|
|
141
|
+
// just for demo so that navigation is not triggered
|
|
142
|
+
onClick={event => event.preventDefault()}
|
|
143
|
+
>
|
|
144
|
+
User management
|
|
145
|
+
</MenuItem>
|
|
146
|
+
<MenuItem
|
|
147
|
+
itemId={2}
|
|
148
|
+
to="#default-link2"
|
|
149
|
+
// just for demo so that navigation is not triggered
|
|
150
|
+
onClick={event => event.preventDefault()}
|
|
151
|
+
>
|
|
152
|
+
Logout
|
|
153
|
+
</MenuItem>
|
|
154
|
+
</MenuContent>
|
|
155
|
+
</Menu>
|
|
156
|
+
) : (
|
|
157
|
+
<Menu ref={menuRef} id="dropdown-menu" onSelect={onSelect}>
|
|
158
|
+
<MenuContent>
|
|
159
|
+
<MenuList>
|
|
160
|
+
<MenuItem
|
|
161
|
+
itemId={0}
|
|
162
|
+
to="#default-link0"
|
|
163
|
+
// just for demo so that navigation is not triggered
|
|
164
|
+
onClick={event => event.preventDefault()}
|
|
165
|
+
>
|
|
166
|
+
Link
|
|
167
|
+
</MenuItem>
|
|
168
|
+
<MenuItem itemId={1}>Action</MenuItem>
|
|
169
|
+
<MenuItem
|
|
170
|
+
itemId={2}
|
|
171
|
+
isDisabled
|
|
172
|
+
to="#default-link2"
|
|
173
|
+
// just for demo so that navigation is not triggered
|
|
174
|
+
onClick={event => event.preventDefault()}
|
|
175
|
+
>
|
|
176
|
+
Disabled link
|
|
177
|
+
</MenuItem>
|
|
178
|
+
<Divider key="group1-divider" />
|
|
179
|
+
<MenuGroup label="Group 1">
|
|
180
|
+
<MenuList>
|
|
181
|
+
<MenuItem itemId={3}>Group 1 action</MenuItem>
|
|
182
|
+
<MenuItem itemId={4} isDisabled>
|
|
183
|
+
Group 1 disabled action
|
|
184
|
+
</MenuItem>
|
|
185
|
+
</MenuList>
|
|
186
|
+
</MenuGroup>
|
|
187
|
+
<Divider key="group2-divider" />
|
|
188
|
+
<MenuGroup label="Group 2">
|
|
189
|
+
<MenuList>
|
|
190
|
+
<MenuItem itemId={5}>Option 1</MenuItem>
|
|
191
|
+
<MenuItem itemId={6}>Option 2</MenuItem>
|
|
192
|
+
</MenuList>
|
|
193
|
+
</MenuGroup>
|
|
194
|
+
</MenuList>
|
|
195
|
+
</MenuContent>
|
|
196
|
+
</Menu>
|
|
197
|
+
);
|
|
198
|
+
return (
|
|
199
|
+
<React.Fragment>
|
|
200
|
+
<ToggleGroup aria-label="Default with single selectable">
|
|
201
|
+
<ToggleGroupItem
|
|
202
|
+
text="Basic toggle"
|
|
203
|
+
buttonId="basic"
|
|
204
|
+
isSelected={toggleSelected === 'basic'}
|
|
205
|
+
onChange={handleToggleSwitch}
|
|
206
|
+
/>
|
|
207
|
+
<ToggleGroupItem
|
|
208
|
+
text="Kebab toggle"
|
|
209
|
+
buttonId="kebab"
|
|
210
|
+
isSelected={toggleSelected === 'kebab'}
|
|
211
|
+
onChange={handleToggleSwitch}
|
|
212
|
+
/>
|
|
213
|
+
<ToggleGroupItem
|
|
214
|
+
text="Badge toggle"
|
|
215
|
+
buttonId="badge"
|
|
216
|
+
isSelected={toggleSelected === 'badge'}
|
|
217
|
+
onChange={handleToggleSwitch}
|
|
218
|
+
/>
|
|
219
|
+
<ToggleGroupItem
|
|
220
|
+
text="Toggle with image"
|
|
221
|
+
buttonId="image"
|
|
222
|
+
isSelected={toggleSelected === 'image'}
|
|
223
|
+
onChange={handleToggleSwitch}
|
|
224
|
+
/>
|
|
225
|
+
</ToggleGroup>
|
|
226
|
+
<br />
|
|
227
|
+
<Popper
|
|
228
|
+
trigger={buildToggle()}
|
|
229
|
+
popper={menu}
|
|
230
|
+
isVisible={isOpen}
|
|
231
|
+
popperMatchesTriggerWidth={['image', 'checkbox'].includes(toggleSelected)}
|
|
232
|
+
/>
|
|
233
|
+
</React.Fragment>
|
|
234
|
+
);
|
|
235
|
+
};
|