@patternfly/react-core 4.233.1 → 4.234.0
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 +11 -0
- package/dist/esm/components/MenuToggle/MenuToggle.js +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/esm/components/Timestamp/Timestamp.d.ts +72 -0
- package/dist/esm/components/Timestamp/Timestamp.d.ts.map +1 -0
- package/dist/esm/components/Timestamp/Timestamp.js +33 -0
- package/dist/esm/components/Timestamp/Timestamp.js.map +1 -0
- package/dist/esm/components/Timestamp/index.d.ts +2 -0
- package/dist/esm/components/Timestamp/index.d.ts.map +1 -0
- package/dist/esm/components/Timestamp/index.js +2 -0
- package/dist/esm/components/Timestamp/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.js +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/js/components/Timestamp/Timestamp.d.ts +72 -0
- package/dist/js/components/Timestamp/Timestamp.d.ts.map +1 -0
- package/dist/js/components/Timestamp/Timestamp.js +37 -0
- package/dist/js/components/Timestamp/Timestamp.js.map +1 -0
- package/dist/js/components/Timestamp/index.d.ts +2 -0
- package/dist/js/components/Timestamp/index.d.ts.map +1 -0
- package/dist/js/components/Timestamp/index.js +5 -0
- package/dist/js/components/Timestamp/index.js.map +1 -0
- package/dist/js/components/index.d.ts +1 -0
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +1 -0
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/react-core.css +22392 -22354
- package/dist/umd/react-core.js +798 -757
- package/dist/umd/react-core.min.css +372 -334
- package/dist/umd/react-core.min.js +4 -4
- package/package.json +5 -5
- package/src/components/Button/examples/Button.md +55 -24
- package/src/components/ContextSelector/examples/ContextSelectorBasic.tsx +4 -4
- package/src/components/ContextSelector/examples/ContextSelectorPlainText.tsx +3 -3
- package/src/components/ContextSelector/examples/ContextSelectorWithFooter.tsx +4 -4
- package/src/components/DualListSelector/examples/DualListSelectorComposable.tsx +8 -2
- package/src/components/DualListSelector/examples/DualListSelectorComposableDragDrop.tsx +3 -9
- package/src/components/DualListSelector/examples/DualListSelectorComposableTree.tsx +3 -3
- package/src/components/DualListSelector/examples/DualListSelectorTreeExample.tsx +8 -5
- package/src/components/MenuToggle/MenuToggle.tsx +2 -2
- package/src/components/Timestamp/Timestamp.tsx +134 -0
- package/src/components/Timestamp/__tests__/Timestamp.test.tsx +177 -0
- package/src/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap +17 -0
- package/src/components/Timestamp/examples/Timestamp.md +57 -0
- package/src/components/Timestamp/examples/TimestampBasicFormats.tsx +26 -0
- package/src/components/Timestamp/examples/TimestampCustomContent.tsx +20 -0
- package/src/components/Timestamp/examples/TimestampCustomFormat.tsx +6 -0
- package/src/components/Timestamp/examples/TimestampCustomTooltip.tsx +19 -0
- package/src/components/Timestamp/examples/TimestampDefault.tsx +4 -0
- package/src/components/Timestamp/examples/TimestampDefaultTooltip.tsx +18 -0
- package/src/components/Timestamp/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/demos/Button.md +5 -1
- package/src/demos/ComposableMenu/examples/ComposableActionsMenu.tsx +12 -8
- package/src/demos/ComposableMenu/examples/ComposableApplicationLauncher.tsx +12 -11
- package/src/demos/ComposableMenu/examples/ComposableContextSelector.tsx +10 -12
- package/src/demos/ComposableMenu/examples/ComposableDrilldownMenu.tsx +7 -7
- package/src/demos/ComposableMenu/examples/ComposableFlyout.tsx +8 -8
- package/src/demos/ComposableMenu/examples/ComposableSimpleCheckboxSelect.tsx +11 -8
- package/src/demos/ComposableMenu/examples/ComposableSimpleDropdown.tsx +7 -7
- package/src/demos/ComposableMenu/examples/ComposableSimpleSelect.tsx +17 -8
- package/src/demos/ComposableMenu/examples/ComposableTreeViewMenu.tsx +11 -10
- package/src/demos/ComposableMenu/examples/ComposableTypeaheadSelect.tsx +2 -2
|
@@ -4,8 +4,8 @@ import { MenuToggle, Menu, MenuContent, MenuList, MenuItem, Popper, Badge } from
|
|
|
4
4
|
export const ComposableSimpleCheckboxSelect: React.FunctionComponent = () => {
|
|
5
5
|
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
6
6
|
const [selectedItems, setSelectedItems] = React.useState<number[]>([]);
|
|
7
|
-
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
8
|
-
const menuRef = React.useRef<HTMLDivElement>();
|
|
7
|
+
const toggleRef = React.useRef<HTMLButtonElement>(null);
|
|
8
|
+
const menuRef = React.useRef<HTMLDivElement>(null);
|
|
9
9
|
|
|
10
10
|
const handleMenuKeys = React.useCallback(
|
|
11
11
|
event => {
|
|
@@ -50,12 +50,15 @@ export const ComposableSimpleCheckboxSelect: React.FunctionComponent = () => {
|
|
|
50
50
|
setIsOpen(!isOpen);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
const onSelect = (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const onSelect = (event?: React.MouseEvent, itemId?: string | number) => {
|
|
54
|
+
if (typeof itemId === 'string' || typeof itemId === 'undefined') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (selectedItems.includes(itemId)) {
|
|
59
|
+
setSelectedItems(selectedItems.filter(id => id !== itemId));
|
|
57
60
|
} else {
|
|
58
|
-
setSelectedItems([...selectedItems,
|
|
61
|
+
setSelectedItems([...selectedItems, itemId]);
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
|
|
@@ -94,5 +97,5 @@ export const ComposableSimpleCheckboxSelect: React.FunctionComponent = () => {
|
|
|
94
97
|
</MenuContent>
|
|
95
98
|
</Menu>
|
|
96
99
|
);
|
|
97
|
-
return <Popper appendTo={toggleRef.current} trigger={toggle} popper={menu} isVisible={isOpen} />;
|
|
100
|
+
return <Popper appendTo={toggleRef.current || undefined} trigger={toggle} popper={menu} isVisible={isOpen} />;
|
|
98
101
|
};
|
|
@@ -3,24 +3,24 @@ import { MenuToggle, Menu, MenuContent, MenuList, MenuItem, Popper } from '@patt
|
|
|
3
3
|
|
|
4
4
|
export const ComposableSimpleDropdown: React.FunctionComponent = () => {
|
|
5
5
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
6
|
-
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
7
|
-
const menuRef = React.useRef<HTMLDivElement>();
|
|
8
|
-
const containerRef = React.useRef<HTMLDivElement>();
|
|
6
|
+
const toggleRef = React.useRef<HTMLButtonElement>(null);
|
|
7
|
+
const menuRef = React.useRef<HTMLDivElement>(null);
|
|
8
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
9
9
|
|
|
10
10
|
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
11
11
|
if (!isOpen) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
if (menuRef.current
|
|
14
|
+
if (menuRef.current?.contains(event.target as Node) || toggleRef.current?.contains(event.target as Node)) {
|
|
15
15
|
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
16
16
|
setIsOpen(!isOpen);
|
|
17
|
-
toggleRef.current
|
|
17
|
+
toggleRef.current?.focus();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const handleClickOutside = (event: MouseEvent) => {
|
|
23
|
-
if (isOpen && !menuRef.current
|
|
23
|
+
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
|
|
24
24
|
setIsOpen(false);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
@@ -69,7 +69,7 @@ export const ComposableSimpleDropdown: React.FunctionComponent = () => {
|
|
|
69
69
|
);
|
|
70
70
|
return (
|
|
71
71
|
<div ref={containerRef}>
|
|
72
|
-
<Popper trigger={toggle} popper={menu} appendTo={containerRef.current} isVisible={isOpen} />
|
|
72
|
+
<Popper trigger={toggle} popper={menu} appendTo={containerRef.current || undefined} isVisible={isOpen} />
|
|
73
73
|
</div>
|
|
74
74
|
);
|
|
75
75
|
};
|
|
@@ -5,21 +5,21 @@ import TableIcon from '@patternfly/react-icons/dist/esm/icons/table-icon';
|
|
|
5
5
|
export const ComposableSimpleSelect: React.FunctionComponent = () => {
|
|
6
6
|
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
7
7
|
const [selected, setSelected] = React.useState<string>('Select a value');
|
|
8
|
-
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
9
|
-
const menuRef = React.useRef<HTMLDivElement>();
|
|
10
|
-
const containerRef = React.useRef<HTMLDivElement>();
|
|
8
|
+
const toggleRef = React.useRef<HTMLButtonElement>(null);
|
|
9
|
+
const menuRef = React.useRef<HTMLDivElement>(null);
|
|
10
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
11
11
|
|
|
12
12
|
const handleMenuKeys = (event: KeyboardEvent) => {
|
|
13
|
-
if (isOpen && menuRef.current
|
|
13
|
+
if (isOpen && menuRef.current?.contains(event.target as Node)) {
|
|
14
14
|
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
15
15
|
setIsOpen(!isOpen);
|
|
16
|
-
toggleRef.current
|
|
16
|
+
toggleRef.current?.focus();
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const handleClickOutside = (event: MouseEvent) => {
|
|
22
|
-
if (isOpen && !menuRef.current
|
|
22
|
+
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
|
|
23
23
|
setIsOpen(false);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
@@ -58,8 +58,17 @@ export const ComposableSimpleSelect: React.FunctionComponent = () => {
|
|
|
58
58
|
{selected}
|
|
59
59
|
</MenuToggle>
|
|
60
60
|
);
|
|
61
|
+
|
|
62
|
+
function onSelect(event?: React.MouseEvent, itemId?: string | number) {
|
|
63
|
+
if (typeof itemId === 'undefined') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setSelected(itemId.toString());
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
const menu = (
|
|
62
|
-
<Menu ref={menuRef} id="select-menu" onSelect={
|
|
71
|
+
<Menu ref={menuRef} id="select-menu" onSelect={onSelect} selected={selected}>
|
|
63
72
|
<MenuContent>
|
|
64
73
|
<MenuList>
|
|
65
74
|
<MenuItem itemId="Option 1">Option 1</MenuItem>
|
|
@@ -73,7 +82,7 @@ export const ComposableSimpleSelect: React.FunctionComponent = () => {
|
|
|
73
82
|
);
|
|
74
83
|
return (
|
|
75
84
|
<div ref={containerRef}>
|
|
76
|
-
<Popper trigger={toggle} popper={menu} appendTo={containerRef.current} isVisible={isOpen} />
|
|
85
|
+
<Popper trigger={toggle} popper={menu} appendTo={containerRef.current || undefined} isVisible={isOpen} />
|
|
77
86
|
</div>
|
|
78
87
|
);
|
|
79
88
|
};
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
14
14
|
const [isOpen, setIsOpen] = React.useState<boolean>(false);
|
|
15
15
|
const [checkedItems, setCheckedItems] = React.useState<TreeViewDataItem[]>([]);
|
|
16
|
-
const toggleRef = React.useRef<HTMLButtonElement>();
|
|
17
|
-
const containerRef = React.useRef<HTMLDivElement>();
|
|
16
|
+
const toggleRef = React.useRef<HTMLButtonElement>(null);
|
|
17
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
18
18
|
const menuRef = React.useRef<HTMLDivElement>();
|
|
19
19
|
|
|
20
20
|
const statusOptions: TreeViewDataItem[] = [
|
|
@@ -93,7 +93,7 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
93
93
|
const areSomeDescendantsChecked = (dataItem: TreeViewDataItem) =>
|
|
94
94
|
dataItem.children ? dataItem.children.some(child => areSomeDescendantsChecked(child)) : isChecked(dataItem);
|
|
95
95
|
const flattenTree = (tree: TreeViewDataItem[]) => {
|
|
96
|
-
let result = [];
|
|
96
|
+
let result: TreeViewDataItem[] = [];
|
|
97
97
|
tree.forEach(item => {
|
|
98
98
|
result.push(item);
|
|
99
99
|
if (item.children) {
|
|
@@ -105,6 +105,7 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
105
105
|
|
|
106
106
|
const mapTree = (item: TreeViewDataItem) => {
|
|
107
107
|
const hasCheck = areAllDescendantsChecked(item);
|
|
108
|
+
item.checkProps = item.checkProps || {};
|
|
108
109
|
// Reset checked properties to be updated
|
|
109
110
|
item.checkProps.checked = false;
|
|
110
111
|
|
|
@@ -143,7 +144,7 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
143
144
|
const onCheck = (evt: React.ChangeEvent, treeViewItem: TreeViewDataItem, treeType: string) => {
|
|
144
145
|
const checked = (evt.target as HTMLInputElement).checked;
|
|
145
146
|
|
|
146
|
-
let options = [];
|
|
147
|
+
let options: TreeViewDataItem[] = [];
|
|
147
148
|
switch (treeType) {
|
|
148
149
|
case 'status':
|
|
149
150
|
options = statusOptions;
|
|
@@ -169,21 +170,21 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
169
170
|
if (!isOpen) {
|
|
170
171
|
return;
|
|
171
172
|
}
|
|
172
|
-
if (menuRef.current
|
|
173
|
+
if (menuRef.current?.contains(event.target as Node) || toggleRef.current?.contains(event.target as Node)) {
|
|
173
174
|
// The escape key when pressed while inside the menu should close the menu and refocus the toggle
|
|
174
175
|
if (event.key === 'Escape') {
|
|
175
176
|
setIsOpen(!isOpen);
|
|
176
|
-
toggleRef.current
|
|
177
|
+
toggleRef.current?.focus();
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
// The tab key when pressed while inside the menu and on the contained last tree view should close the menu and refocus the toggle
|
|
180
181
|
// Shift tab should keep the default behavior to return to a previous tree view
|
|
181
182
|
if (event.key === 'Tab' && !event.shiftKey) {
|
|
182
|
-
const treeList = menuRef.current
|
|
183
|
+
const treeList = menuRef.current?.querySelectorAll('.pf-c-tree-view') || [];
|
|
183
184
|
if (treeList[treeList.length - 1].contains(event.target as Node)) {
|
|
184
185
|
event.preventDefault();
|
|
185
186
|
setIsOpen(!isOpen);
|
|
186
|
-
toggleRef.current
|
|
187
|
+
toggleRef.current?.focus();
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
}
|
|
@@ -191,7 +192,7 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
191
192
|
|
|
192
193
|
// Controls that a click outside the menu while the menu is open should close the menu
|
|
193
194
|
const handleClickOutside = (event: MouseEvent) => {
|
|
194
|
-
if (isOpen && !menuRef.current
|
|
195
|
+
if (isOpen && !menuRef.current?.contains(event.target as Node)) {
|
|
195
196
|
setIsOpen(false);
|
|
196
197
|
}
|
|
197
198
|
};
|
|
@@ -266,7 +267,7 @@ export const ComposableTreeViewMenu: React.FunctionComponent = () => {
|
|
|
266
267
|
trigger={toggle}
|
|
267
268
|
popper={menu}
|
|
268
269
|
isVisible={isOpen}
|
|
269
|
-
appendTo={containerRef.current}
|
|
270
|
+
appendTo={containerRef.current || undefined}
|
|
270
271
|
popperMatchesTriggerWidth={false}
|
|
271
272
|
/>
|
|
272
273
|
</div>
|
|
@@ -55,7 +55,7 @@ export const ComposableTypeaheadSelect: React.FunctionComponent = () => {
|
|
|
55
55
|
|
|
56
56
|
const focusOnInput = () => menuToggleRef.current?.querySelector('input')?.focus();
|
|
57
57
|
|
|
58
|
-
const onMenuSelect = (
|
|
58
|
+
const onMenuSelect = (event?: React.MouseEvent, itemId?: string | number) => {
|
|
59
59
|
if (itemId) {
|
|
60
60
|
setInputValue(itemId.toString());
|
|
61
61
|
setIsSelected(true);
|
|
@@ -124,7 +124,7 @@ export const ComposableTypeaheadSelect: React.FunctionComponent = () => {
|
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
// Close the menu when a click occurs outside of the menu toggle content
|
|
127
|
-
const onDocumentClick = (event
|
|
127
|
+
const onDocumentClick = (event?: MouseEvent) => {
|
|
128
128
|
if (!menuToggleRef.current?.contains(event?.target as HTMLElement)) {
|
|
129
129
|
setIsMenuOpen(false);
|
|
130
130
|
}
|