@patternfly/react-core 4.253.0 → 4.254.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 (50) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts +1 -1
  3. package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
  4. package/dist/esm/components/ClipboardCopy/ClipboardCopy.js +13 -32
  5. package/dist/esm/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
  6. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.d.ts +2 -0
  7. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.d.ts.map +1 -1
  8. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.js +2 -2
  9. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.js.map +1 -1
  10. package/dist/esm/components/Menu/MenuItem.d.ts +3 -1
  11. package/dist/esm/components/Menu/MenuItem.d.ts.map +1 -1
  12. package/dist/esm/components/Menu/MenuItem.js +2 -2
  13. package/dist/esm/components/Menu/MenuItem.js.map +1 -1
  14. package/dist/esm/components/Slider/Slider.js +2 -2
  15. package/dist/esm/components/Slider/Slider.js.map +1 -1
  16. package/dist/esm/components/Tooltip/Tooltip.d.ts +2 -0
  17. package/dist/esm/components/Tooltip/Tooltip.d.ts.map +1 -1
  18. package/dist/esm/components/Tooltip/Tooltip.js +19 -2
  19. package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
  20. package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts +1 -1
  21. package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
  22. package/dist/js/components/ClipboardCopy/ClipboardCopy.js +13 -32
  23. package/dist/js/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
  24. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.d.ts +2 -0
  25. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.d.ts.map +1 -1
  26. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.js +2 -2
  27. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.js.map +1 -1
  28. package/dist/js/components/Menu/MenuItem.d.ts +3 -1
  29. package/dist/js/components/Menu/MenuItem.d.ts.map +1 -1
  30. package/dist/js/components/Menu/MenuItem.js +2 -2
  31. package/dist/js/components/Menu/MenuItem.js.map +1 -1
  32. package/dist/js/components/Slider/Slider.js +2 -2
  33. package/dist/js/components/Slider/Slider.js.map +1 -1
  34. package/dist/js/components/Tooltip/Tooltip.d.ts +2 -0
  35. package/dist/js/components/Tooltip/Tooltip.d.ts.map +1 -1
  36. package/dist/js/components/Tooltip/Tooltip.js +19 -2
  37. package/dist/js/components/Tooltip/Tooltip.js.map +1 -1
  38. package/dist/umd/react-core.min.css +669 -669
  39. package/dist/umd/react-core.min.js +2 -2
  40. package/package.json +2 -2
  41. package/src/components/ClipboardCopy/ClipboardCopy.tsx +16 -31
  42. package/src/components/ClipboardCopy/ClipboardCopyButton.tsx +4 -0
  43. package/src/components/CodeBlock/examples/CodeBlockBasic.tsx +3 -8
  44. package/src/components/CodeBlock/examples/CodeBlockExpandable.tsx +3 -8
  45. package/src/components/Menu/MenuItem.tsx +4 -0
  46. package/src/components/Menu/examples/Menu.md +5 -0
  47. package/src/components/Menu/examples/MenuDangerMenuItem.tsx +28 -0
  48. package/src/components/Slider/Slider.tsx +3 -3
  49. package/src/components/Slider/_tests_/__snapshots__/Slider.test.tsx.snap +11 -11
  50. package/src/components/Tooltip/Tooltip.tsx +24 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.253.0",
3
+ "version": "4.254.0",
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",
@@ -70,5 +70,5 @@
70
70
  "react": "^16.8 || ^17 || ^18",
71
71
  "react-dom": "^16.8 || ^17 || ^18"
72
72
  },
73
- "gitHead": "e19bfad93c0e242c2b1416daa3b347d7f3864f2c"
73
+ "gitHead": "af4d7f84ea9c7397c5ad51b033d9b2247c0ddba3"
74
74
  }
@@ -12,13 +12,7 @@ import { ClipboardCopyExpanded } from './ClipboardCopyExpanded';
12
12
  import { getOUIAProps, OUIAProps } from '../../helpers';
13
13
 
14
14
  export const clipboardCopyFunc = (event: React.ClipboardEvent<HTMLDivElement>, text?: React.ReactNode) => {
15
- const clipboard = event.currentTarget.parentElement;
16
- const el = document.createElement('textarea');
17
- el.value = text.toString();
18
- clipboard.appendChild(el);
19
- el.select();
20
- document.execCommand('copy');
21
- clipboard.removeChild(el);
15
+ navigator.clipboard.writeText(text.toString());
22
16
  };
23
17
 
24
18
  export enum ClipboardCopyVariant {
@@ -77,7 +71,7 @@ export interface ClipboardCopyProps extends Omit<React.HTMLProps<HTMLDivElement>
77
71
  exitDelay?: number;
78
72
  /** Delay in ms before the tooltip appears. */
79
73
  entryDelay?: number;
80
- /** Delay in ms before the tooltip message switch to hover tip. */
74
+ /** @deprecated Delay in ms before the tooltip message switch to hover tip. */
81
75
  switchDelay?: number;
82
76
  /** A function that is triggered on clicking the copy button. */
83
77
  onCopy?: (event: React.ClipboardEvent<HTMLDivElement>, text?: React.ReactNode) => void;
@@ -105,6 +99,14 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
105
99
  expanded: this.props.isExpanded,
106
100
  copied: false
107
101
  };
102
+
103
+ if (this.props.switchDelay !== undefined) {
104
+ // eslint-disable-next-line no-console
105
+ console.warn(
106
+ 'ClipboardCopy: switchDelay prop has been deprecated. ' +
107
+ 'The tooltip message will switch back to the hover tip as soon as the tooltip is hidden.'
108
+ );
109
+ }
108
110
  }
109
111
 
110
112
  static defaultProps: PickOptional<ClipboardCopyProps> = {
@@ -116,9 +118,8 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
116
118
  variant: 'inline',
117
119
  position: PopoverPosition.top,
118
120
  maxWidth: '150px',
119
- exitDelay: 1600,
121
+ exitDelay: 1500,
120
122
  entryDelay: 300,
121
- switchDelay: 2000,
122
123
  onCopy: clipboardCopyFunc,
123
124
  onChange: (): any => undefined,
124
125
  textAriaLabel: 'Copyable input',
@@ -157,6 +158,7 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
157
158
  /* eslint-disable @typescript-eslint/no-unused-vars */
158
159
  isExpanded,
159
160
  onChange, // Don't pass to <div>
161
+ switchDelay,
160
162
  /* eslint-enable @typescript-eslint/no-unused-vars */
161
163
  isReadOnly,
162
164
  isCode,
@@ -164,7 +166,6 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
164
166
  exitDelay,
165
167
  maxWidth,
166
168
  entryDelay,
167
- switchDelay,
168
169
  onCopy,
169
170
  hoverTip,
170
171
  clickTip,
@@ -219,18 +220,10 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
219
220
  textId={`text-input-${id}`}
220
221
  aria-label={hoverTip}
221
222
  onClick={(event: any) => {
222
- if (this.timer) {
223
- window.clearTimeout(this.timer);
224
- this.setState({ copied: false });
225
- }
226
223
  onCopy(event, this.state.text);
227
- this.setState({ copied: true }, () => {
228
- this.timer = window.setTimeout(() => {
229
- this.setState({ copied: false });
230
- this.timer = null;
231
- }, switchDelay);
232
- });
224
+ this.setState({ copied: true });
233
225
  }}
226
+ onTooltipHidden={() => this.setState({ copied: false })}
234
227
  >
235
228
  {this.state.copied ? clickTip : hoverTip}
236
229
  </ClipboardCopyButton>
@@ -272,18 +265,10 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
272
265
  textId={`text-input-${id}`}
273
266
  aria-label={hoverTip}
274
267
  onClick={(event: any) => {
275
- if (this.timer) {
276
- window.clearTimeout(this.timer);
277
- this.setState({ copied: false });
278
- }
279
268
  onCopy(event, this.state.text);
280
- this.setState({ copied: true }, () => {
281
- this.timer = window.setTimeout(() => {
282
- this.setState({ copied: false });
283
- this.timer = null;
284
- }, switchDelay);
285
- });
269
+ this.setState({ copied: true });
286
270
  }}
271
+ onTooltipHidden={() => this.setState({ copied: false })}
287
272
  >
288
273
  {this.state.copied ? clickTip : hoverTip}
289
274
  </ClipboardCopyButton>
@@ -43,6 +43,8 @@ export interface ClipboardCopyButtonProps
43
43
  'aria-label'?: string;
44
44
  /** Variant of the copy button */
45
45
  variant?: 'control' | 'plain';
46
+ /** Callback when tooltip's hide transition has finished executing */
47
+ onTooltipHidden?: () => void;
46
48
  }
47
49
 
48
50
  export const ClipboardCopyButton: React.FunctionComponent<ClipboardCopyButtonProps> = ({
@@ -56,6 +58,7 @@ export const ClipboardCopyButton: React.FunctionComponent<ClipboardCopyButtonPro
56
58
  textId,
57
59
  children,
58
60
  variant = 'control',
61
+ onTooltipHidden = () => {},
59
62
  ...props
60
63
  }: ClipboardCopyButtonProps) => (
61
64
  <Tooltip
@@ -67,6 +70,7 @@ export const ClipboardCopyButton: React.FunctionComponent<ClipboardCopyButtonPro
67
70
  aria-live="polite"
68
71
  aria="none"
69
72
  content={<div>{children}</div>}
73
+ onTooltipHidden={onTooltipHidden}
70
74
  >
71
75
  <Button
72
76
  type="button"
@@ -6,13 +6,7 @@ export const BasicCodeBlock: React.FunctionComponent = () => {
6
6
  const [copied, setCopied] = React.useState(false);
7
7
 
8
8
  const clipboardCopyFunc = (event, text) => {
9
- const clipboard = event.currentTarget.parentElement;
10
- const el = document.createElement('textarea');
11
- el.value = text.toString();
12
- clipboard.appendChild(el);
13
- el.select();
14
- document.execCommand('copy');
15
- clipboard.removeChild(el);
9
+ navigator.clipboard.writeText(text.toString());
16
10
  };
17
11
 
18
12
  const onClick = (event, text) => {
@@ -36,9 +30,10 @@ url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`;
36
30
  textId="code-content"
37
31
  aria-label="Copy to clipboard"
38
32
  onClick={e => onClick(e, code)}
39
- exitDelay={600}
33
+ exitDelay={copied ? 1500 : 600}
40
34
  maxWidth="110px"
41
35
  variant="plain"
36
+ onTooltipHidden={() => setCopied(false)}
42
37
  >
43
38
  {copied ? 'Successfully copied to clipboard!' : 'Copy to clipboard'}
44
39
  </ClipboardCopyButton>
@@ -19,13 +19,7 @@ export const ExpandableCodeBlock: React.FunctionComponent = () => {
19
19
  };
20
20
 
21
21
  const clipboardCopyFunc = (event, text) => {
22
- const clipboard = event.currentTarget.parentElement;
23
- const el = document.createElement('textarea');
24
- el.value = text.toString();
25
- clipboard.appendChild(el);
26
- el.select();
27
- document.execCommand('copy');
28
- clipboard.removeChild(el);
22
+ navigator.clipboard.writeText(text.toString());
29
23
  };
30
24
 
31
25
  const onClick = (event, text) => {
@@ -57,9 +51,10 @@ url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`;
57
51
  textId="code-content"
58
52
  aria-label="Copy to clipboard"
59
53
  onClick={e => onClick(e, copyBlock)}
60
- exitDelay={600}
54
+ exitDelay={copied ? 1500 : 600}
61
55
  maxWidth="110px"
62
56
  variant="plain"
57
+ onTooltipHidden={() => setCopied(false)}
63
58
  >
64
59
  {copied ? 'Successfully copied to clipboard!' : 'Copy to clipboard'}
65
60
  </ClipboardCopyButton>
@@ -52,6 +52,8 @@ export interface MenuItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'onC
52
52
  isSelected?: boolean;
53
53
  /** Flag indicating the item is focused */
54
54
  isFocused?: boolean;
55
+ /** Flag indicating the item is in danger state */
56
+ isDanger?: boolean;
55
57
  /** @beta Flyout menu */
56
58
  flyoutMenu?: React.ReactElement;
57
59
  /** @beta Callback function when mouse leaves trigger */
@@ -91,6 +93,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
91
93
  isExternalLink = false,
92
94
  isSelected = null,
93
95
  isFocused,
96
+ isDanger = false,
94
97
  icon,
95
98
  actions,
96
99
  onShowFlyout,
@@ -295,6 +298,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
295
298
  isLoadButton && styles.modifiers.load,
296
299
  isLoading && styles.modifiers.loading,
297
300
  isFocused && styles.modifiers.focus,
301
+ isDanger && styles.modifiers.danger,
298
302
  className
299
303
  )}
300
304
  onMouseOver={onMouseOver}
@@ -23,6 +23,11 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico
23
23
  ```ts file="MenuBasic.tsx"
24
24
  ```
25
25
 
26
+ ### Danger menu item
27
+
28
+ ```ts file="MenuDangerMenuItem.tsx"
29
+ ```
30
+
26
31
  ### With icons
27
32
 
28
33
  ```ts file="MenuWithIcons.tsx"
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { Divider, Menu, MenuContent, MenuItem, MenuList } from '@patternfly/react-core';
3
+
4
+ export const MenuDangerMenuItem: React.FunctionComponent = () => {
5
+ const [activeItem, setActiveItem] = React.useState(0);
6
+
7
+ const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: number | string | undefined) => {
8
+ const item = itemId as number;
9
+ // eslint-disable-next-line no-console
10
+ console.log(`clicked ${itemId}`);
11
+ setActiveItem(item);
12
+ };
13
+
14
+ return (
15
+ <Menu activeItemId={activeItem} onSelect={onSelect}>
16
+ <MenuContent>
17
+ <MenuList>
18
+ <MenuItem itemId={0}>Action 1</MenuItem>
19
+ <MenuItem itemId={1}>Action 2</MenuItem>
20
+ <Divider component="li" />
21
+ <MenuItem itemId={2} isDanger>
22
+ Delete
23
+ </MenuItem>
24
+ </MenuList>
25
+ </MenuContent>
26
+ </Menu>
27
+ );
28
+ };
@@ -416,9 +416,6 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
416
416
  {buildSteps()}
417
417
  </div>
418
418
  )}
419
- {isInputVisible && inputPosition === 'aboveThumb' && (
420
- <div className={css(styles.sliderValue, styles.modifiers.floating)}>{displayInput()}</div>
421
- )}
422
419
  {hasTooltipOverThumb ? (
423
420
  <Tooltip entryDelay={0} content={findAriaTextValue()}>
424
421
  {thumbComponent}
@@ -426,6 +423,9 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
426
423
  ) : (
427
424
  thumbComponent
428
425
  )}
426
+ {isInputVisible && inputPosition === 'aboveThumb' && (
427
+ <div className={css(styles.sliderValue, styles.modifiers.floating)}>{displayInput()}</div>
428
+ )}
429
429
  </div>
430
430
  {isInputVisible && inputPosition === 'right' && <div className={css(styles.sliderValue)}>{displayInput()}</div>}
431
431
  {rightActions && <div className={css(styles.sliderActions)}>{rightActions}</div>}
@@ -475,6 +475,17 @@ exports[`slider renders slider with input above thumb 1`] = `
475
475
  </div>
476
476
  </div>
477
477
  </div>
478
+ <div
479
+ aria-disabled="false"
480
+ aria-label="Value"
481
+ aria-valuemax="100"
482
+ aria-valuemin="0"
483
+ aria-valuenow="50"
484
+ aria-valuetext="50"
485
+ class="pf-c-slider__thumb"
486
+ role="slider"
487
+ tabindex="0"
488
+ />
478
489
  <div
479
490
  class="pf-c-slider__value pf-m-floating"
480
491
  >
@@ -498,17 +509,6 @@ exports[`slider renders slider with input above thumb 1`] = `
498
509
  </span>
499
510
  </div>
500
511
  </div>
501
- <div
502
- aria-disabled="false"
503
- aria-label="Value"
504
- aria-valuemax="100"
505
- aria-valuemin="0"
506
- aria-valuenow="50"
507
- aria-valuetext="50"
508
- class="pf-c-slider__thumb"
509
- role="slider"
510
- tabindex="0"
511
- />
512
512
  </div>
513
513
  </div>
514
514
  </DocumentFragment>
@@ -95,6 +95,8 @@ export interface TooltipProps extends Omit<React.HTMLProps<HTMLDivElement>, 'con
95
95
  )[];
96
96
  /** Maximum width of the tooltip (default 18.75rem) */
97
97
  maxWidth?: string;
98
+ /** Callback when tooltip's hide transition has finished executing */
99
+ onTooltipHidden?: () => void;
98
100
  /**
99
101
  * Tooltip position. Note: With 'enableFlip' set to true,
100
102
  * it will change the position if there is not enough space for the starting position.
@@ -171,6 +173,7 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
171
173
  isAppLauncher,
172
174
  tippyProps,
173
175
  removeFindDomNode = false,
176
+ onTooltipHidden = () => {},
174
177
  ...rest
175
178
  }: TooltipProps) => {
176
179
  if (process.env.NODE_ENV !== 'production') {
@@ -194,6 +197,8 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
194
197
  const showTimerRef = React.useRef(null);
195
198
  const hideTimerRef = React.useRef(null);
196
199
 
200
+ const prevExitDelayRef = React.useRef<number>();
201
+
197
202
  const clearTimeouts = (timeoutRefs: React.RefObject<any>[]) => {
198
203
  timeoutRefs.forEach(ref => {
199
204
  if (ref.current) {
@@ -233,6 +238,21 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
233
238
  hide();
234
239
  }
235
240
  }, [isVisible]);
241
+
242
+ React.useEffect(() => {
243
+ if (prevExitDelayRef.current < exitDelay) {
244
+ clearTimeouts([transitionTimerRef, hideTimerRef]);
245
+ hideTimerRef.current = setTimeout(() => {
246
+ setOpacity(0);
247
+ transitionTimerRef.current = setTimeout(() => {
248
+ setVisible(false);
249
+ onTooltipHidden();
250
+ }, animationDuration);
251
+ }, exitDelay);
252
+ }
253
+ prevExitDelayRef.current = exitDelay;
254
+ }, [exitDelay]);
255
+
236
256
  const show = () => {
237
257
  clearTimeouts([transitionTimerRef, hideTimerRef]);
238
258
  showTimerRef.current = setTimeout(() => {
@@ -244,7 +264,10 @@ export const Tooltip: React.FunctionComponent<TooltipProps> = ({
244
264
  clearTimeouts([showTimerRef]);
245
265
  hideTimerRef.current = setTimeout(() => {
246
266
  setOpacity(0);
247
- transitionTimerRef.current = setTimeout(() => setVisible(false), animationDuration);
267
+ transitionTimerRef.current = setTimeout(() => {
268
+ setVisible(false);
269
+ onTooltipHidden();
270
+ }, animationDuration);
248
271
  }, exitDelay);
249
272
  };
250
273
  const positionModifiers = {