@patternfly/react-core 4.174.0 → 4.174.1

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 (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/esm/components/Pagination/Navigation.d.ts +2 -0
  3. package/dist/esm/components/Pagination/Navigation.d.ts.map +1 -1
  4. package/dist/esm/components/Pagination/Navigation.js +4 -4
  5. package/dist/esm/components/Pagination/Navigation.js.map +1 -1
  6. package/dist/esm/components/Pagination/OptionsToggle.js +3 -3
  7. package/dist/esm/components/Pagination/OptionsToggle.js.map +1 -1
  8. package/dist/esm/components/Pagination/Pagination.d.ts +1 -1
  9. package/dist/esm/components/Pagination/Pagination.d.ts.map +1 -1
  10. package/dist/esm/components/Pagination/Pagination.js +27 -18
  11. package/dist/esm/components/Pagination/Pagination.js.map +1 -1
  12. package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
  13. package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
  14. package/dist/esm/components/Pagination/PaginationOptionsMenu.js +3 -14
  15. package/dist/esm/components/Pagination/PaginationOptionsMenu.js.map +1 -1
  16. package/dist/js/components/Pagination/Navigation.d.ts +2 -0
  17. package/dist/js/components/Pagination/Navigation.d.ts.map +1 -1
  18. package/dist/js/components/Pagination/Navigation.js +4 -4
  19. package/dist/js/components/Pagination/Navigation.js.map +1 -1
  20. package/dist/js/components/Pagination/OptionsToggle.js +3 -3
  21. package/dist/js/components/Pagination/OptionsToggle.js.map +1 -1
  22. package/dist/js/components/Pagination/Pagination.d.ts +1 -1
  23. package/dist/js/components/Pagination/Pagination.d.ts.map +1 -1
  24. package/dist/js/components/Pagination/Pagination.js +30 -21
  25. package/dist/js/components/Pagination/Pagination.js.map +1 -1
  26. package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
  27. package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
  28. package/dist/js/components/Pagination/PaginationOptionsMenu.js +3 -14
  29. package/dist/js/components/Pagination/PaginationOptionsMenu.js.map +1 -1
  30. package/dist/umd/react-core.css +343 -87
  31. package/dist/umd/react-core.js +45 -46
  32. package/dist/umd/react-core.min.css +343 -87
  33. package/dist/umd/react-core.min.js +4 -4
  34. package/package.json +6 -6
  35. package/src/components/Pagination/Navigation.tsx +11 -4
  36. package/src/components/Pagination/OptionsToggle.tsx +3 -3
  37. package/src/components/Pagination/Pagination.tsx +40 -23
  38. package/src/components/Pagination/PaginationOptionsMenu.tsx +4 -15
  39. package/src/components/Pagination/__tests__/Generated/__snapshots__/Navigation.test.tsx.snap +0 -7
  40. package/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap +1 -1
  41. package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap +3 -8
  42. package/src/components/Pagination/__tests__/Pagination.test.tsx +24 -0
  43. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +187 -157
  44. package/src/components/Pagination/examples/Pagination.md +35 -0
  45. package/src/components/TextInputGroup/examples/TextInputGroup.md +4 -4
  46. package/src/demos/TextInputGroupDemo.md +278 -0
@@ -89,6 +89,41 @@ class PaginationBottom extends React.Component {
89
89
  }
90
90
  }
91
91
  ```
92
+ ### Indeterminate
93
+
94
+ By not passing `itemCount` and passing `toggleTemplate` you can customize the toggle with text.
95
+
96
+ ```js
97
+ import React from 'react';
98
+ import { Pagination } from '@patternfly/react-core';
99
+
100
+ PaginationIndeterminate = () => {
101
+ const [page, setPage] = React.useState(1);
102
+ const [perPage, setPerPage] = React.useState(20);
103
+
104
+ const onSetPage = (_event, pageNumber) => setPage(pageNumber);
105
+ const onPerPageSelect = (_event, perPage) => setPerPage(perPage);
106
+
107
+ return (
108
+ <Pagination
109
+ toggleTemplate={({ firstIndex, lastIndex }) => (
110
+ <React.Fragment>
111
+ <b>
112
+ {firstIndex} - {lastIndex}
113
+ </b>
114
+ of
115
+ <b>many</b>
116
+ </React.Fragment>
117
+ )}
118
+ widgetId="pagination-indeterminate"
119
+ perPage={perPage}
120
+ page={page}
121
+ onSetPage={onSetPage}
122
+ onPerPageSelect={onPerPageSelect}
123
+ />
124
+ );
125
+ }
126
+ ```
92
127
 
93
128
  ### Disabled
94
129
 
@@ -49,8 +49,8 @@ const TextInputGroupWithIcons = () => {
49
49
  const [inputValue, setInputValue] = React.useState('');
50
50
 
51
51
  /** callback for updating the inputValue state in this component so that the input can be controlled */
52
- const handleInputChange = event => {
53
- setInputValue(event.target.value);
52
+ const handleInputChange = (value, _event) => {
53
+ setInputValue(value);
54
54
  };
55
55
 
56
56
  /** show the input clearing button only when the input is not empty */
@@ -108,8 +108,8 @@ const TextInputGroupWithChips = () => {
108
108
  const showSearchIcon = !currentChips.length;
109
109
 
110
110
  /** callback for updating the inputValue state in this component so that the input can be controlled */
111
- const handleInputChange = event => {
112
- setInputValue(event.target.value);
111
+ const handleInputChange = (value, _event) => {
112
+ setInputValue(value);
113
113
  };
114
114
 
115
115
  /** callback for removing a chip from the chip selections */
@@ -0,0 +1,278 @@
1
+ ---
2
+ id: Text input group
3
+ section: components
4
+ beta: true
5
+ ---
6
+
7
+ import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
8
+ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
9
+
10
+ ## Demos
11
+
12
+ ### Attribute-value filtering
13
+
14
+ This demo showcases the selection of attribute-value pairs based on a predefined set of data.
15
+
16
+ Available attributes are shown in a menu when focus is placed on the text input. Once an attribute is selected the values for that attribute will be shown in the menu. When a value is selected for the attribute the pair will be converted into a chip and placed into the chip group. Typing in the text input will filter the entries shown in the menu.
17
+
18
+ Attributes and values can both be selected by:
19
+ - clicking the entry shown in the menu
20
+ - hitting the up or down arrows (while focused on the text input) to switch focus to the menu, navigating the menu using the arrow keys, and hitting `enter` on an entry
21
+ - hitting `enter` (while focused on the text input) to select the first entry shown in the menu at the time
22
+
23
+ Additionally, attributes can be selected by typing the full (case sensitive) name of an attribute, then typing `:`.
24
+
25
+ Attributes can be deselected (returning you to attribute selection mode) by hitting `escape`, or by hitting `backspace` when the only text in the text input is the attribute.
26
+
27
+ ```js
28
+ import React from 'react';
29
+ import {
30
+ TextInputGroup,
31
+ TextInputGroupMain,
32
+ TextInputGroupUtilities,
33
+ Button,
34
+ Menu,
35
+ MenuContent,
36
+ MenuList,
37
+ MenuItem,
38
+ Popper,
39
+ Chip,
40
+ ChipGroup,
41
+ Divider
42
+ } from '@patternfly/react-core';
43
+ import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
44
+ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
45
+
46
+ export const KeyValueFiltering = () => {
47
+ const [inputValue, setInputValue] = React.useState('');
48
+ const [selectedKey, setSelectedKey] = React.useState('');
49
+ const [menuIsOpen, setMenuIsOpen] = React.useState(false);
50
+ const [currentChips, setCurrentChips] = React.useState([]);
51
+
52
+ /** key and value data to be shown in the menu */
53
+ const data = {
54
+ Cluster: ['acmeqe-managed-1', 'local-cluster'],
55
+ Kind: ['Template', 'ReplicationController', 'ReplicaSet', 'Deployment'],
56
+ Label: ['release', 'environment', 'partition'],
57
+ Name: ['backup-1', 'backup-2', 'production-1', 'production-2', 'testing'],
58
+ Namespace: ['default', 'public'],
59
+ Status: ['running', 'idle', 'stopped']
60
+ };
61
+ const keyNames = ['Cluster', 'Kind', 'Label', 'Name', 'Namespace', 'Status'];
62
+ const [menuItemsText, setMenuItemsText] = React.useState(keyNames);
63
+ const [menuItems, setMenuItems] = React.useState([]);
64
+
65
+ /** refs used to detect when clicks occur inside vs outside of the textInputGroup and menu popper */
66
+ const menuRef = React.useRef();
67
+ const textInputGroupRef = React.useRef();
68
+
69
+ /** callback for updating the inputValue state in this component so that the input can be controlled */
70
+ const handleInputChange = (value, _event) => {
71
+ setInputValue(value);
72
+ };
73
+
74
+ /** callback for removing a chip from the chip selections */
75
+ const deleteChip = chipToDelete => {
76
+ const newChips = currentChips.filter(chip => !Object.is(chip, chipToDelete));
77
+ setCurrentChips(newChips);
78
+ };
79
+
80
+ /** reset state hooks associated with key selection */
81
+ const clearSelectedKey = () => {
82
+ setInputValue('');
83
+ setSelectedKey('');
84
+ setMenuItemsText(keyNames);
85
+ };
86
+
87
+ /** callback for clearing all selected chips, the text input, and any selected keys */
88
+ const clearChipsAndInput = () => {
89
+ setCurrentChips([]);
90
+ clearSelectedKey();
91
+ };
92
+
93
+ React.useEffect(() => {
94
+ /** in the menu only show items that include the text in the input */
95
+ const filteredMenuItems = menuItemsText
96
+ .filter(
97
+ item =>
98
+ !inputValue ||
99
+ item.toLowerCase().includes(
100
+ inputValue
101
+ .toString()
102
+ .slice(selectedKey.length && selectedKey.length + 2)
103
+ .toLowerCase()
104
+ )
105
+ )
106
+ .map((currentValue, index) => (
107
+ <MenuItem key={currentValue} itemId={index}>
108
+ {currentValue}
109
+ </MenuItem>
110
+ ));
111
+
112
+ /** in the menu show a disabled "no result" when all menu items are filtered out */
113
+ if (filteredMenuItems.length === 0) {
114
+ const noResultItem = (
115
+ <MenuItem isDisabled key="no result">
116
+ No results found
117
+ </MenuItem>
118
+ );
119
+ setMenuItems([noResultItem]);
120
+ return;
121
+ }
122
+
123
+ /** determine the menu heading text based on key selection; or lack thereof */
124
+ const headingItem = (
125
+ <MenuItem isDisabled key="heading">
126
+ {selectedKey.length ? `${selectedKey} values` : 'Attributes'}
127
+ </MenuItem>
128
+ );
129
+
130
+ const divider = <Divider key="divider" />;
131
+
132
+ setMenuItems([headingItem, divider, ...filteredMenuItems]);
133
+ }, [inputValue]);
134
+
135
+ /** add selected key/value pair as a chip in the chip group */
136
+ const selectValue = selectedValue => {
137
+ setCurrentChips([...currentChips, `${selectedKey}: ${selectedValue}`]);
138
+ clearSelectedKey();
139
+ };
140
+
141
+ /** update the input to show the selected key and the menu to show the values associated with that specific key */
142
+ const selectKey = selectedText => {
143
+ setInputValue(`${selectedText}: `);
144
+ setSelectedKey(selectedText);
145
+ setMenuItemsText(data[selectedText]);
146
+ };
147
+
148
+ const handleEnter = () => {
149
+ /** do nothing if the menu contains no real results */
150
+ if (menuItems.length === 1) {
151
+ return;
152
+ }
153
+
154
+ /** perform the appropriate action based on key selection state */
155
+ if (selectedKey.length) {
156
+ selectValue(menuItems[2].props.children);
157
+ } else {
158
+ selectKey(menuItems[2].props.children);
159
+ }
160
+ };
161
+
162
+ /** allow the user to backspace at the selected key name to drop the currently selected key */
163
+ const handleBackspace = () => {
164
+ if (selectedKey.length && inputValue === `${selectedKey}: `) {
165
+ clearSelectedKey();
166
+ }
167
+ };
168
+
169
+ /** allow the user to select a key by simply typing it and entering a colon, exact (case sensitive) matches only */
170
+ const handleColon = () => {
171
+ if (!selectedKey.length && keyNames.includes(inputValue)) {
172
+ selectKey(inputValue);
173
+ event.preventDefault();
174
+ }
175
+ };
176
+
177
+ /** allow the user to focus on the menu and navigate using the arrow keys */
178
+ const handleArrowKey = () => {
179
+ if (menuRef.current) {
180
+ const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
181
+ firstElement && firstElement.focus();
182
+ }
183
+ };
184
+
185
+ /** enable keyboard only usage */
186
+ const handleTextInputKeyDown = event => {
187
+ switch (event.key) {
188
+ case 'Enter':
189
+ handleEnter();
190
+ break;
191
+ case 'Escape':
192
+ clearSelectedKey();
193
+ break;
194
+ case 'Backspace':
195
+ handleBackspace();
196
+ break;
197
+ case ':':
198
+ handleColon();
199
+ break;
200
+ case 'ArrowUp':
201
+ case 'ArrowDown':
202
+ handleArrowKey();
203
+ break;
204
+ }
205
+ };
206
+
207
+ /** perform the proper key or value selection when a menu item is selected */
208
+ const onSelect = (event, _itemId) => {
209
+ const selectedText = event.target.innerText;
210
+
211
+ if (selectedKey.length) {
212
+ selectValue(selectedText);
213
+ } else {
214
+ selectKey(selectedText);
215
+ }
216
+ event.stopPropagation();
217
+ textInputGroupRef.current.querySelector('input').focus();
218
+ };
219
+
220
+ /** close the menu when a click occurs outside of the menu or text input group */
221
+ const handleClick = event => {
222
+ if (
223
+ menuRef.current &&
224
+ !menuRef.current.contains(event.target) &&
225
+ !textInputGroupRef.current.contains(event.target)
226
+ ) {
227
+ setMenuIsOpen(false);
228
+ }
229
+ };
230
+
231
+ /** only show the search icon when no chips are selected */
232
+ const showSearchIcon = !currentChips.length;
233
+
234
+ /** only show the clear button when there is something that can be cleared */
235
+ const showClearButton = inputValue || !!currentChips.length;
236
+
237
+ const inputGroup = (
238
+ <div ref={textInputGroupRef}>
239
+ <TextInputGroup>
240
+ <TextInputGroupMain
241
+ icon={showSearchIcon && <SearchIcon />}
242
+ value={inputValue}
243
+ onChange={handleInputChange}
244
+ onFocus={() => setMenuIsOpen(true)}
245
+ onKeyDown={handleTextInputKeyDown}
246
+ >
247
+ <ChipGroup>
248
+ {currentChips.map(currentChip => (
249
+ <Chip key={currentChip} onClick={() => deleteChip(currentChip)}>
250
+ {currentChip}
251
+ </Chip>
252
+ ))}
253
+ </ChipGroup>
254
+ </TextInputGroupMain>
255
+ <TextInputGroupUtilities>
256
+ {showClearButton && (
257
+ <Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
258
+ <TimesIcon />
259
+ </Button>
260
+ )}
261
+ </TextInputGroupUtilities>
262
+ </TextInputGroup>
263
+ </div>
264
+ );
265
+
266
+ const menu = (
267
+ <div ref={menuRef}>
268
+ <Menu onSelect={onSelect}>
269
+ <MenuContent>
270
+ <MenuList>{menuItems}</MenuList>
271
+ </MenuContent>
272
+ </Menu>
273
+ </div>
274
+ );
275
+
276
+ return <Popper trigger={inputGroup} popper={menu} isVisible={menuIsOpen} onDocumentClick={handleClick} />;
277
+ };
278
+ ```