@patternfly/react-core 4.183.8 → 4.184.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/esm/components/Dropdown/Dropdown.d.ts +2 -0
  3. package/dist/esm/components/Dropdown/Dropdown.d.ts.map +1 -1
  4. package/dist/esm/components/Dropdown/Dropdown.js.map +1 -1
  5. package/dist/esm/components/Dropdown/DropdownToggle.d.ts +2 -0
  6. package/dist/esm/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  7. package/dist/esm/components/Dropdown/DropdownToggle.js +3 -3
  8. package/dist/esm/components/Dropdown/DropdownToggle.js.map +1 -1
  9. package/dist/esm/components/Dropdown/DropdownWithContext.d.ts.map +1 -1
  10. package/dist/esm/components/Dropdown/DropdownWithContext.js +4 -2
  11. package/dist/esm/components/Dropdown/DropdownWithContext.js.map +1 -1
  12. package/dist/esm/components/Dropdown/Toggle.d.ts +2 -0
  13. package/dist/esm/components/Dropdown/Toggle.d.ts.map +1 -1
  14. package/dist/esm/components/Dropdown/Toggle.js +4 -3
  15. package/dist/esm/components/Dropdown/Toggle.js.map +1 -1
  16. package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
  17. package/dist/esm/components/Tabs/Tabs.js +0 -2
  18. package/dist/esm/components/Tabs/Tabs.js.map +1 -1
  19. package/dist/js/components/Dropdown/Dropdown.d.ts +2 -0
  20. package/dist/js/components/Dropdown/Dropdown.d.ts.map +1 -1
  21. package/dist/js/components/Dropdown/Dropdown.js.map +1 -1
  22. package/dist/js/components/Dropdown/DropdownToggle.d.ts +2 -0
  23. package/dist/js/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  24. package/dist/js/components/Dropdown/DropdownToggle.js +3 -3
  25. package/dist/js/components/Dropdown/DropdownToggle.js.map +1 -1
  26. package/dist/js/components/Dropdown/DropdownWithContext.d.ts.map +1 -1
  27. package/dist/js/components/Dropdown/DropdownWithContext.js +4 -2
  28. package/dist/js/components/Dropdown/DropdownWithContext.js.map +1 -1
  29. package/dist/js/components/Dropdown/Toggle.d.ts +2 -0
  30. package/dist/js/components/Dropdown/Toggle.d.ts.map +1 -1
  31. package/dist/js/components/Dropdown/Toggle.js +4 -3
  32. package/dist/js/components/Dropdown/Toggle.js.map +1 -1
  33. package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
  34. package/dist/js/components/Tabs/Tabs.js +0 -2
  35. package/dist/js/components/Tabs/Tabs.js.map +1 -1
  36. package/dist/umd/react-core.css +1 -0
  37. package/dist/umd/react-core.js +11 -10
  38. package/dist/umd/react-core.min.css +180 -179
  39. package/dist/umd/react-core.min.js +2 -2
  40. package/package.json +6 -6
  41. package/src/components/ApplicationLauncher/__tests__/Generated/__snapshots__/ApplicationLauncher.test.tsx.snap +1 -0
  42. package/src/components/ApplicationLauncher/__tests__/__snapshots__/ApplicationLauncher.test.tsx.snap +18 -0
  43. package/src/components/Dropdown/Dropdown.tsx +2 -0
  44. package/src/components/Dropdown/DropdownToggle.tsx +4 -0
  45. package/src/components/Dropdown/DropdownWithContext.tsx +3 -0
  46. package/src/components/Dropdown/Toggle.tsx +5 -0
  47. package/src/components/Dropdown/__tests__/DropdownToggle.test.tsx +11 -0
  48. package/src/components/Dropdown/__tests__/Generated/__snapshots__/Dropdown.test.tsx.snap +1 -0
  49. package/src/components/Dropdown/__tests__/Generated/__snapshots__/KebabToggle.test.tsx.snap +1 -0
  50. package/src/components/Dropdown/__tests__/__snapshots__/Dropdown.test.tsx.snap +45 -0
  51. package/src/components/Dropdown/__tests__/__snapshots__/DropdownToggle.test.tsx.snap +94 -8
  52. package/src/components/Dropdown/__tests__/__snapshots__/Toggle.test.tsx.snap +2 -0
  53. package/src/components/Dropdown/examples/Dropdown.md +57 -0
  54. package/src/components/OptionsMenu/__tests__/Generated/__snapshots__/OptionsMenu.test.tsx.snap +1 -0
  55. package/src/components/OptionsMenu/__tests__/__snapshots__/OptionsMenu.test.tsx.snap +31 -0
  56. package/src/components/Pagination/__tests__/Generated/__snapshots__/PaginationOptionsMenu.test.tsx.snap +1 -0
  57. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +47 -0
  58. package/src/components/Tabs/Tabs.tsx +0 -2
  59. package/src/components/Tabs/examples/Tabs.md +6 -6
  60. package/src/components/TextInputGroup/examples/TextInputGroup.md +4 -123
  61. package/src/components/TextInputGroup/examples/TextInputGroupBasic.tsx +8 -0
  62. package/src/components/TextInputGroup/examples/TextInputGroupDisabled.tsx +8 -0
  63. package/src/components/TextInputGroup/examples/TextInputGroupFilters.tsx +69 -0
  64. package/src/components/TextInputGroup/examples/TextInputGroupUtilitiesAndIcon.tsx +34 -0
  65. package/src/demos/TextInputGroupDemo.md +2 -2
  66. package/src/demos/examples/TextInputGroup/{AttributeValueFiltering.js → AttributeValueFiltering.tsx} +22 -18
  67. package/src/demos/examples/TextInputGroup/{AutoCompleteSearch.js → AutoCompleteSearch.tsx} +18 -18
@@ -16,14 +16,18 @@ import {
16
16
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
17
17
  import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
18
18
 
19
- export const AttributeValueFiltering = () => {
19
+ export const AttributeValueFiltering: React.FunctionComponent = () => {
20
20
  const [inputValue, setInputValue] = React.useState('');
21
21
  const [selectedKey, setSelectedKey] = React.useState('');
22
22
  const [menuIsOpen, setMenuIsOpen] = React.useState(false);
23
- const [currentChips, setCurrentChips] = React.useState([]);
23
+ const [currentChips, setCurrentChips] = React.useState<string[]>([]);
24
+
25
+ interface attributeValueData {
26
+ [attribute: string]: string[];
27
+ }
24
28
 
25
29
  /** key and value data to be shown in the menu */
26
- const data = {
30
+ const data: attributeValueData = {
27
31
  Cluster: ['acmeqe-managed-1', 'local-cluster'],
28
32
  Kind: ['Template', 'ReplicationController', 'ReplicaSet', 'Deployment'],
29
33
  Label: ['release', 'environment', 'partition'],
@@ -33,19 +37,19 @@ export const AttributeValueFiltering = () => {
33
37
  };
34
38
  const keyNames = ['Cluster', 'Kind', 'Label', 'Name', 'Namespace', 'Status'];
35
39
  const [menuItemsText, setMenuItemsText] = React.useState(keyNames);
36
- const [menuItems, setMenuItems] = React.useState([]);
40
+ const [menuItems, setMenuItems] = React.useState<React.ReactElement[]>([]);
37
41
 
38
42
  /** refs used to detect when clicks occur inside vs outside of the textInputGroup and menu popper */
39
- const menuRef = React.useRef();
40
- const textInputGroupRef = React.useRef();
43
+ const menuRef = React.useRef<HTMLDivElement>();
44
+ const textInputGroupRef = React.useRef<HTMLDivElement>();
41
45
 
42
46
  /** callback for updating the inputValue state in this component so that the input can be controlled */
43
- const handleInputChange = (value, _event) => {
47
+ const handleInputChange = (value: string, _event: React.FormEvent<HTMLInputElement>) => {
44
48
  setInputValue(value);
45
49
  };
46
50
 
47
51
  /** callback for removing a chip from the chip selections */
48
- const deleteChip = chipToDelete => {
52
+ const deleteChip = (chipToDelete: string) => {
49
53
  const newChips = currentChips.filter(chip => !Object.is(chip, chipToDelete));
50
54
  setCurrentChips(newChips);
51
55
  };
@@ -106,13 +110,13 @@ export const AttributeValueFiltering = () => {
106
110
  }, [inputValue]);
107
111
 
108
112
  /** add selected key/value pair as a chip in the chip group */
109
- const selectValue = selectedValue => {
113
+ const selectValue = (selectedValue: string) => {
110
114
  setCurrentChips([...currentChips, `${selectedKey}: ${selectedValue}`]);
111
115
  clearSelectedKey();
112
116
  };
113
117
 
114
118
  /** update the input to show the selected key and the menu to show the values associated with that specific key */
115
- const selectKey = selectedText => {
119
+ const selectKey = (selectedText: string) => {
116
120
  setInputValue(`${selectedText}: `);
117
121
  setSelectedKey(selectedText);
118
122
  setMenuItemsText(data[selectedText]);
@@ -150,13 +154,13 @@ export const AttributeValueFiltering = () => {
150
154
  /** allow the user to focus on the menu and navigate using the arrow keys */
151
155
  const handleArrowKey = () => {
152
156
  if (menuRef.current) {
153
- const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
157
+ const firstElement = menuRef.current.querySelector<HTMLButtonElement>('li > button:not(:disabled)');
154
158
  firstElement && firstElement.focus();
155
159
  }
156
160
  };
157
161
 
158
162
  /** enable keyboard only usage */
159
- const handleTextInputKeyDown = event => {
163
+ const handleTextInputKeyDown = (event: React.KeyboardEvent) => {
160
164
  switch (event.key) {
161
165
  case 'Enter':
162
166
  handleEnter();
@@ -178,8 +182,8 @@ export const AttributeValueFiltering = () => {
178
182
  };
179
183
 
180
184
  /** perform the proper key or value selection when a menu item is selected */
181
- const onSelect = (event, _itemId) => {
182
- const selectedText = event.target.innerText;
185
+ const onSelect = (event: React.MouseEvent<Element, MouseEvent>, _itemId: string | number) => {
186
+ const selectedText = (event.target as HTMLElement).innerText;
183
187
 
184
188
  if (selectedKey.length) {
185
189
  selectValue(selectedText);
@@ -191,11 +195,11 @@ export const AttributeValueFiltering = () => {
191
195
  };
192
196
 
193
197
  /** close the menu when a click occurs outside of the menu or text input group */
194
- const handleClick = event => {
198
+ const handleClick = (event: MouseEvent) => {
195
199
  if (
196
200
  menuRef.current &&
197
- !menuRef.current.contains(event.target) &&
198
- !textInputGroupRef.current.contains(event.target)
201
+ !menuRef.current.contains(event.target as HTMLElement) &&
202
+ !textInputGroupRef.current.contains(event.target as HTMLElement)
199
203
  ) {
200
204
  setMenuIsOpen(false);
201
205
  }
@@ -205,7 +209,7 @@ export const AttributeValueFiltering = () => {
205
209
  const showSearchIcon = !currentChips.length;
206
210
 
207
211
  /** only show the clear button when there is something that can be cleared */
208
- const showClearButton = inputValue || !!currentChips.length;
212
+ const showClearButton = !!inputValue || !!currentChips.length;
209
213
 
210
214
  const inputGroup = (
211
215
  <div ref={textInputGroupRef}>
@@ -16,26 +16,26 @@ import {
16
16
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
17
17
  import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
18
18
 
19
- export const AutoCompleteSearch = () => {
19
+ export const AutoCompleteSearch: React.FunctionComponent = () => {
20
20
  const [inputValue, setInputValue] = React.useState('');
21
21
  const [menuIsOpen, setMenuIsOpen] = React.useState(false);
22
- const [currentChips, setCurrentChips] = React.useState([]);
22
+ const [currentChips, setCurrentChips] = React.useState<string[]>([]);
23
23
 
24
24
  /** auto-completing suggestion text items to be shown in the menu */
25
25
  const suggestionItems = ['Cluster', 'Kind', 'Label', 'Name', 'Namespace', 'Status'];
26
- const [menuItems, setMenuItems] = React.useState([]);
26
+ const [menuItems, setMenuItems] = React.useState<React.ReactElement[]>([]);
27
27
 
28
28
  /** refs used to detect when clicks occur inside vs outside of the textInputGroup and menu popper */
29
- const menuRef = React.useRef();
30
- const textInputGroupRef = React.useRef();
29
+ const menuRef = React.useRef<HTMLDivElement>();
30
+ const textInputGroupRef = React.useRef<HTMLDivElement>();
31
31
 
32
32
  /** callback for updating the inputValue state in this component so that the input can be controlled */
33
- const handleInputChange = (value, _event) => {
33
+ const handleInputChange = (value: string, _event: React.FormEvent<HTMLInputElement>) => {
34
34
  setInputValue(value);
35
35
  };
36
36
 
37
37
  /** callback for removing a chip from the chip selections */
38
- const deleteChip = chipToDelete => {
38
+ const deleteChip = (chipToDelete: string) => {
39
39
  const newChips = currentChips.filter(chip => !Object.is(chip, chipToDelete));
40
40
  setCurrentChips(newChips);
41
41
  };
@@ -80,7 +80,7 @@ export const AutoCompleteSearch = () => {
80
80
  }, [inputValue]);
81
81
 
82
82
  /** add the given string as a chip in the chip group and clear the input */
83
- const addChip = newChipText => {
83
+ const addChip = (newChipText: string) => {
84
84
  setCurrentChips([...currentChips, `${newChipText}`]);
85
85
  setInputValue('');
86
86
  };
@@ -92,7 +92,7 @@ export const AutoCompleteSearch = () => {
92
92
  }
93
93
  };
94
94
 
95
- const handleTab = event => {
95
+ const handleTab = (event: React.KeyboardEvent) => {
96
96
  if (menuItems.length === 3) {
97
97
  setInputValue(menuItems[2].props.children);
98
98
  event.preventDefault();
@@ -107,7 +107,7 @@ export const AutoCompleteSearch = () => {
107
107
  /** allow the user to focus on the menu and navigate using the arrow keys */
108
108
  const handleArrowKey = () => {
109
109
  if (menuRef.current) {
110
- const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
110
+ const firstElement = menuRef.current.querySelector<HTMLButtonElement>('li > button:not(:disabled)');
111
111
  firstElement && firstElement.focus();
112
112
  }
113
113
  };
@@ -120,7 +120,7 @@ export const AutoCompleteSearch = () => {
120
120
  };
121
121
 
122
122
  /** enable keyboard only usage while focused on the text input */
123
- const handleTextInputKeyDown = event => {
123
+ const handleTextInputKeyDown = (event: React.KeyboardEvent) => {
124
124
  switch (event.key) {
125
125
  case 'Enter':
126
126
  handleEnter();
@@ -146,26 +146,26 @@ export const AutoCompleteSearch = () => {
146
146
  };
147
147
 
148
148
  /** add the text of the selected item as a new chip */
149
- const onSelect = (event, _itemId) => {
150
- const selectedText = event.target.innerText;
149
+ const onSelect = (event: React.MouseEvent<Element, MouseEvent>, _itemId: string | number) => {
150
+ const selectedText = (event.target as HTMLElement).innerText;
151
151
  addChip(selectedText);
152
152
  event.stopPropagation();
153
153
  focusTextInput();
154
154
  };
155
155
 
156
156
  /** close the menu when a click occurs outside of the menu or text input group */
157
- const handleClick = event => {
157
+ const handleClick = (event: MouseEvent) => {
158
158
  if (
159
159
  menuRef.current &&
160
- !menuRef.current.contains(event.target) &&
161
- !textInputGroupRef.current.contains(event.target)
160
+ !menuRef.current.contains(event.target as HTMLElement) &&
161
+ !textInputGroupRef.current.contains(event.target as HTMLElement)
162
162
  ) {
163
163
  setMenuIsOpen(false);
164
164
  }
165
165
  };
166
166
 
167
167
  /** enable keyboard only usage while focused on the menu */
168
- const handleMenuKeyDown = event => {
168
+ const handleMenuKeyDown = (event: React.KeyboardEvent) => {
169
169
  if (event.key === 'Escape') {
170
170
  setInputValue('');
171
171
  focusTextInput();
@@ -177,7 +177,7 @@ export const AutoCompleteSearch = () => {
177
177
  const showSearchIcon = !currentChips.length;
178
178
 
179
179
  /** only show the clear button when there is something that can be cleared */
180
- const showClearButton = inputValue || !!currentChips.length;
180
+ const showClearButton = !!inputValue || !!currentChips.length;
181
181
 
182
182
  const inputGroup = (
183
183
  <div ref={textInputGroupRef}>