@patternfly/react-core 4.187.2 → 4.189.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.187.2",
3
+ "version": "4.189.1",
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.38.2",
38
- "@patternfly/react-styles": "^4.37.2",
39
- "@patternfly/react-tokens": "^4.39.2",
37
+ "@patternfly/react-icons": "^4.40.1",
38
+ "@patternfly/react-styles": "^4.39.1",
39
+ "@patternfly/react-tokens": "^4.41.1",
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": "86b42dd534532822d79ec6be30648a68e1eab707"
63
+ "gitHead": "a634131168ee7e2c61e9a68080a1fd9b2b7bb46d"
64
64
  }
@@ -28,6 +28,8 @@ export interface DescriptionListProps extends Omit<React.HTMLProps<HTMLDListElem
28
28
  isCompact?: boolean;
29
29
  /** Sets a horizontal description list to have fluid styling. */
30
30
  isFluid?: boolean;
31
+ /** Sets the the default placement of description list groups to fill from top to bottom. */
32
+ isFillColumns?: boolean;
31
33
  /** Sets the number of columns on the description list */
32
34
  columnModifier?: {
33
35
  default?: '1Col' | '2Col' | '3Col';
@@ -74,6 +76,7 @@ export const DescriptionList: React.FunctionComponent<DescriptionListProps> = ({
74
76
  isInlineGrid,
75
77
  isCompact,
76
78
  isFluid,
79
+ isFillColumns,
77
80
  columnModifier,
78
81
  autoFitMinModifier,
79
82
  orientation,
@@ -91,6 +94,7 @@ export const DescriptionList: React.FunctionComponent<DescriptionListProps> = ({
91
94
  isInlineGrid && styles.modifiers.inlineGrid,
92
95
  isCompact && styles.modifiers.compact,
93
96
  isFluid && styles.modifiers.fluid,
97
+ isFillColumns && styles.modifiers.fillColumns,
94
98
  className
95
99
  )}
96
100
  style={
@@ -103,4 +107,5 @@ export const DescriptionList: React.FunctionComponent<DescriptionListProps> = ({
103
107
  {children}
104
108
  </dl>
105
109
  );
110
+
106
111
  DescriptionList.displayName = 'DescriptionList';
@@ -481,6 +481,52 @@ import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-i
481
481
  </DescriptionList>;
482
482
  ```
483
483
 
484
+ ### Column fill
485
+
486
+ ```js
487
+ import React from 'react';
488
+ import {
489
+ Button,
490
+ DescriptionList,
491
+ DescriptionListTerm,
492
+ DescriptionListText,
493
+ DescriptionListGroup,
494
+ DescriptionListDescription
495
+ } from '@patternfly/react-core';
496
+ import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon';
497
+
498
+ <DescriptionList isFillColumns columnModifier={{ default: '2Col', lg: '3Col' }}>
499
+ <DescriptionListGroup>
500
+ <DescriptionListTerm>Name</DescriptionListTerm>
501
+ <DescriptionListDescription>
502
+ This is a long description that should wrap to multiple lines in a multi-column layout.
503
+ </DescriptionListDescription>
504
+ </DescriptionListGroup>
505
+ <DescriptionListGroup>
506
+ <DescriptionListTerm>Namespace</DescriptionListTerm>
507
+ <DescriptionListDescription>
508
+ <a href="#">mary-test</a>
509
+ </DescriptionListDescription>
510
+ </DescriptionListGroup>
511
+ <DescriptionListGroup>
512
+ <DescriptionListTerm>Labels</DescriptionListTerm>
513
+ <DescriptionListDescription>example</DescriptionListDescription>
514
+ </DescriptionListGroup>
515
+ <DescriptionListGroup>
516
+ <DescriptionListTerm>Pod selector</DescriptionListTerm>
517
+ <DescriptionListDescription>
518
+ <Button variant="link" isInline icon={<PlusCircleIcon />}>
519
+ app=MyApp
520
+ </Button>
521
+ </DescriptionListDescription>
522
+ </DescriptionListGroup>
523
+ <DescriptionListGroup>
524
+ <DescriptionListTerm>Annotation</DescriptionListTerm>
525
+ <DescriptionListDescription>2 Annotations</DescriptionListDescription>
526
+ </DescriptionListGroup>
527
+ </DescriptionList>;
528
+ ```
529
+
484
530
  ## Responsive column definitions
485
531
 
486
532
  ### Default responsive columns
@@ -18,9 +18,12 @@ export enum TabsComponent {
18
18
  nav = 'nav'
19
19
  }
20
20
 
21
+ type TabElement = React.ReactElement<TabProps, React.JSXElementConstructor<TabProps>>;
22
+ type TabsChild = TabElement | boolean | null | undefined;
23
+
21
24
  export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivElement>, 'onSelect'>, OUIAProps {
22
- /** Content rendered inside the tabs component. Must be React.ReactElement<TabProps>[] */
23
- children: React.ReactNode;
25
+ /** Content rendered inside the tabs component. Only `Tab` components or expressions resulting in a falsy value are allowed here. */
26
+ children: TabsChild | TabsChild[];
24
27
  /** Additional classes added to the tabs */
25
28
  className?: string;
26
29
  /** Tabs background color variant */
@@ -163,8 +166,8 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
163
166
  // process any tab content sections outside of the component
164
167
  if (tabContentRef) {
165
168
  React.Children.toArray(this.props.children)
166
- .map(child => child as React.ReactElement<TabProps>)
167
- .filter(child => child.props && child.props.tabContentRef && child.props.tabContentRef.current)
169
+ .filter((child): child is TabElement => React.isValidElement(child))
170
+ .filter(({ props }) => props.tabContentRef && props.tabContentRef.current)
168
171
  .forEach(child => (child.props.tabContentRef.current.hidden = true));
169
172
  // most recently selected tabContent
170
173
  if (tabContentRef.current) {
@@ -308,8 +311,8 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
308
311
  uncontrolledActiveKey,
309
312
  uncontrolledIsExpandedLocal
310
313
  } = this.state;
311
- const filteredChildren = (React.Children.toArray(children) as React.ReactElement<TabProps>[])
312
- .filter(Boolean)
314
+ const filteredChildren = React.Children.toArray(children)
315
+ .filter((child): child is TabElement => React.isValidElement(child))
313
316
  .filter(child => !child.props.isHidden);
314
317
 
315
318
  const uniqueId = id || getUniqueId();
@@ -239,6 +239,70 @@ class ToolbarSpacers extends React.Component {
239
239
  }
240
240
  ```
241
241
 
242
+ ### Sticky
243
+
244
+ ```js
245
+ import React from 'react';
246
+ import {
247
+ Toolbar,
248
+ ToolbarItem,
249
+ ToolbarContent,
250
+ Button,
251
+ ButtonVariant,
252
+ InputGroup,
253
+ TextInput,
254
+ Checkbox
255
+ } from '@patternfly/react-core';
256
+ import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
257
+
258
+ const ToolbarItems = () => {
259
+ const [isSticky, setIsSticky] = React.useState(true);
260
+ const [showEvenOnly, setShowEvenOnly] = React.useState(true);
261
+ const array = [...Array(30).keys()];
262
+ const numbers = showEvenOnly ? array.filter(number => number % 2 === 0):array;
263
+
264
+ return (
265
+ <React.Fragment>
266
+ <div style={{ overflowY: 'scroll', height: '200px' }}>
267
+ <Toolbar id="toolbar-spacers" inset={{ default: 'insetNone' }} isSticky={isSticky}>
268
+ <ToolbarContent>
269
+ <ToolbarItem>
270
+ <InputGroup>
271
+ <TextInput name="textInput1" id="textInput1" type="search" aria-label="search input example" />
272
+ <Button variant={ButtonVariant.control} aria-label="search button for search input">
273
+ <SearchIcon />
274
+ </Button>
275
+ </InputGroup>
276
+ </ToolbarItem>
277
+ <ToolbarItem>
278
+ <Checkbox
279
+ label="Show only even number items"
280
+ isChecked={showEvenOnly}
281
+ onChange={setShowEvenOnly}
282
+ aria-label="checkbox for showing only even numbers"
283
+ id="showOnlyEvenCheckbox"
284
+ />
285
+ </ToolbarItem>
286
+ </ToolbarContent>
287
+ </Toolbar>
288
+ <ul>
289
+ {numbers.map(number => (
290
+ <li key={number}>{`item ${number}`}</li>
291
+ ))}
292
+ </ul>
293
+ </div>
294
+ <Checkbox
295
+ label="Is toolbar sticky"
296
+ isChecked={isSticky}
297
+ onChange={setIsSticky}
298
+ aria-label="checkbox for is sticky"
299
+ id="isStickyCheckbox"
300
+ />
301
+ </React.Fragment>
302
+ );
303
+ };
304
+ ```
305
+
242
306
  ### Groups
243
307
 
244
308
  Often, it makes sense to group sets of like items to create desired associations and to enable items to respond together to changes in viewport width. (Note: This example does not demonstrate the desired responsive behavior of the toolbar. That is handled in later examples.)
@@ -0,0 +1,175 @@
1
+ ---
2
+ id: Password generator
3
+ section: demos
4
+ ---
5
+
6
+ import RedoIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon';
7
+ import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';
8
+ import EyeSlashIcon from '@patternfly/react-icons/dist/esm/icons/eye-slash-icon';
9
+
10
+ ## Demos
11
+
12
+ ### Provide a generated password
13
+
14
+ ```ts
15
+ import React from 'react';
16
+ import {
17
+ InputGroup,
18
+ TextInput,
19
+ Button,
20
+ Popper,
21
+ Menu,
22
+ MenuContent,
23
+ MenuList,
24
+ MenuItem,
25
+ MenuItemAction
26
+ } from '@patternfly/react-core';
27
+ import RedoIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon';
28
+ import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';
29
+ import EyeSlashIcon from '@patternfly/react-icons/dist/esm/icons/eye-slash-icon';
30
+
31
+ const PasswordGenerator: React.FunctionComponent = () => {
32
+ const generatePassword = () => {
33
+ const length = 12;
34
+ const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@%()_-=+';
35
+ let retVal = '';
36
+ for (var i = 0, n = charset.length; i < length; ++i) {
37
+ retVal += charset.charAt(Math.floor(Math.random() * n));
38
+ }
39
+ return retVal;
40
+ };
41
+ const [password, setPassword] = React.useState<string>('');
42
+ const [generatedPassword, setGeneratedPassword] = React.useState<string>(generatePassword());
43
+ const [isAutocompleteOpen, setIsAutocompleteOpen] = React.useState<boolean>(false);
44
+ const [passwordHidden, setPasswordHidden] = React.useState<boolean>(true);
45
+ const searchInputRef = React.useRef(null);
46
+ const autocompleteRef = React.useRef(null);
47
+
48
+ React.useEffect(() => {
49
+ window.addEventListener('keydown', handleMenuKeys);
50
+ window.addEventListener('click', handleClickOutside);
51
+ return () => {
52
+ window.removeEventListener('keydown', handleMenuKeys);
53
+ window.removeEventListener('click', handleClickOutside);
54
+ };
55
+ }, [isAutocompleteOpen, searchInputRef.current]);
56
+
57
+ const onChange = (newValue: string) => {
58
+ if (searchInputRef && searchInputRef.current && searchInputRef.current.contains(document.activeElement)) {
59
+ setIsAutocompleteOpen(true);
60
+ } else {
61
+ setIsAutocompleteOpen(false);
62
+ }
63
+ setPassword(newValue);
64
+ };
65
+
66
+ // Whenever an autocomplete option is selected, set the search input value, close the menu, and put the browser
67
+ // focus back on the search input
68
+ const onSelect = (event: React.MouseEvent<HTMLButtonElement>) => {
69
+ event.stopPropagation();
70
+ setPassword(generatedPassword);
71
+ setIsAutocompleteOpen(false);
72
+ searchInputRef.current.focus();
73
+ };
74
+
75
+ const handleMenuKeys = (event: KeyboardEvent | React.KeyboardEvent<any>) => {
76
+ if (!(isAutocompleteOpen && searchInputRef.current && searchInputRef.current.contains(event.target))) {
77
+ return;
78
+ }
79
+ // the escape key closes the autocomplete menu and keeps the focus on the search input.
80
+ if (event.key === 'Escape') {
81
+ setIsAutocompleteOpen(false);
82
+ searchInputRef.current.focus();
83
+ // the up and down arrow keys move browser focus into the autocomplete menu
84
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
85
+ const firstElement = autocompleteRef.current.querySelector('li > button:not(:disabled)');
86
+ firstElement && firstElement.focus();
87
+ event.preventDefault(); // by default, the up and down arrow keys scroll the window
88
+ }
89
+ // If the autocomplete is open and the browser focus is in the autocomplete menu
90
+ // hitting tab will close the autocomplete and put browser focus back on the search input.
91
+ else if (autocompleteRef.current.contains(event.target) && event.key === 'Tab') {
92
+ event.preventDefault();
93
+ setIsAutocompleteOpen(false);
94
+ searchInputRef.current.focus();
95
+ }
96
+ };
97
+
98
+ // The autocomplete menu should close if the user clicks outside the menu.
99
+ const handleClickOutside = (event: MouseEvent | TouchEvent | KeyboardEvent | React.KeyboardEvent<any> | React.MouseEvent<HTMLButtonElement>) => {
100
+ if (
101
+ isAutocompleteOpen &&
102
+ autocompleteRef &&
103
+ autocompleteRef.current &&
104
+ !searchInputRef.current.contains(event.target)
105
+ ) {
106
+ setIsAutocompleteOpen(false);
107
+ }
108
+ if (
109
+ !isAutocompleteOpen &&
110
+ searchInputRef &&
111
+ searchInputRef.current &&
112
+ searchInputRef.current.contains(event.target)
113
+ ) {
114
+ setIsAutocompleteOpen(true);
115
+ }
116
+ };
117
+ const textInput = (
118
+ <div ref={searchInputRef} id="password-input">
119
+ <InputGroup>
120
+ <TextInput
121
+ onFocus={() => {
122
+ setIsAutocompleteOpen(true);
123
+ }}
124
+ isRequired
125
+ type={passwordHidden ? 'password' : 'text'}
126
+ aria-label="Password input"
127
+ value={password}
128
+ onChange={onChange}
129
+ />
130
+ <Button
131
+ variant="control"
132
+ onClick={() => setPasswordHidden(!passwordHidden)}
133
+ aria-label={passwordHidden ? 'Show password' : 'Hide password'}
134
+ >
135
+ {passwordHidden ? <EyeIcon /> : <EyeSlashIcon />}
136
+ </Button>
137
+ </InputGroup>
138
+ </div>
139
+ );
140
+ const autocomplete = (
141
+ <Menu ref={autocompleteRef} onSelect={onSelect}>
142
+ <MenuContent>
143
+ <MenuList>
144
+ <MenuItem
145
+ itemId={0}
146
+ actions={
147
+ <MenuItemAction
148
+ icon={<RedoIcon aria-hidden />}
149
+ onClick={e => {
150
+ setGeneratedPassword(generatePassword());
151
+ }}
152
+ actionId="redo"
153
+ aria-label="Generate a new suggested password"
154
+ />
155
+ }
156
+ >
157
+ Use suggested password: <b>{`${generatedPassword}`}</b>
158
+ </MenuItem>
159
+ </MenuList>
160
+ </MenuContent>
161
+ </Menu>
162
+ );
163
+
164
+ return (
165
+ <Popper
166
+ trigger={textInput}
167
+ popper={autocomplete}
168
+ isVisible={isAutocompleteOpen}
169
+ enableFlip={false}
170
+ // append the autocomplete menu to the search input in the DOM for the sake of the keyboard navigation experience
171
+ appendTo={() => document.querySelector('#password-input')}
172
+ />
173
+ );
174
+ };
175
+ ```