@patternfly/react-core 4.208.9 → 4.208.12

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 (32) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/esm/helpers/index.d.ts +1 -0
  3. package/dist/esm/helpers/index.d.ts.map +1 -1
  4. package/dist/esm/helpers/index.js +1 -0
  5. package/dist/esm/helpers/index.js.map +1 -1
  6. package/dist/esm/helpers/useInterval.d.ts +6 -0
  7. package/dist/esm/helpers/useInterval.d.ts.map +1 -0
  8. package/dist/esm/helpers/useInterval.js +21 -0
  9. package/dist/esm/helpers/useInterval.js.map +1 -0
  10. package/dist/js/helpers/index.d.ts +1 -0
  11. package/dist/js/helpers/index.d.ts.map +1 -1
  12. package/dist/js/helpers/index.js +1 -0
  13. package/dist/js/helpers/index.js.map +1 -1
  14. package/dist/js/helpers/useInterval.d.ts +6 -0
  15. package/dist/js/helpers/useInterval.d.ts.map +1 -0
  16. package/dist/js/helpers/useInterval.js +26 -0
  17. package/dist/js/helpers/useInterval.js.map +1 -0
  18. package/dist/umd/react-core.css +17 -15
  19. package/dist/umd/react-core.js +22 -0
  20. package/dist/umd/react-core.min.css +92 -90
  21. package/dist/umd/react-core.min.js +1 -1
  22. package/package.json +6 -6
  23. package/src/components/AlertGroup/examples/AlertGroup.md +7 -361
  24. package/src/components/AlertGroup/examples/AlertGroupAsync.tsx +73 -0
  25. package/src/components/AlertGroup/examples/AlertGroupMultipleDynamic.tsx +59 -0
  26. package/src/components/AlertGroup/examples/AlertGroupSingularDynamic.tsx +70 -0
  27. package/src/components/AlertGroup/examples/AlertGroupSingularDynamicOverflow.tsx +89 -0
  28. package/src/components/AlertGroup/examples/AlertGroupStatic.tsx +11 -0
  29. package/src/components/AlertGroup/examples/AlertGroupToast.tsx +69 -0
  30. package/src/components/AlertGroup/examples/AlertGroupToastOverflowCapture.tsx +88 -0
  31. package/src/helpers/index.ts +1 -0
  32. package/src/helpers/useInterval.ts +25 -0
@@ -0,0 +1,89 @@
1
+ import React from 'react';
2
+ import {
3
+ Alert,
4
+ AlertProps,
5
+ AlertGroup,
6
+ AlertActionCloseButton,
7
+ AlertVariant,
8
+ InputGroup
9
+ } from '@patternfly/react-core';
10
+
11
+ export const AlertGroupSingularDynamicOverflow: React.FunctionComponent = () => {
12
+ const [alerts, setAlerts] = React.useState<Partial<AlertProps>[]>([]);
13
+ const [overflowMessage, setOverflowMessage] = React.useState<string>('');
14
+
15
+ const maxDisplayed = 4;
16
+
17
+ const getOverflowMessage = (alertsNumber: number) => {
18
+ const overflow = alertsNumber - maxDisplayed;
19
+ if (overflow > 0) {
20
+ return `View ${overflow} more alerts`;
21
+ }
22
+ return '';
23
+ };
24
+
25
+ const addAlert = (title: string, variant: AlertProps['variant'], key: React.Key) => {
26
+ setAlerts(prevAlerts => [...prevAlerts, { title, variant, key }]);
27
+ setOverflowMessage(getOverflowMessage(alerts.length + 1));
28
+ };
29
+
30
+ const removeAlert = (key: React.Key) => {
31
+ const newAlerts = alerts.filter(alert => alert.key !== key);
32
+ setAlerts(newAlerts);
33
+ setOverflowMessage(getOverflowMessage(newAlerts.length));
34
+ };
35
+
36
+ const btnClasses = ['pf-c-button', 'pf-m-secondary'].join(' ');
37
+
38
+ const getUniqueId = () => new Date().getTime();
39
+
40
+ const addSuccessAlert = () => {
41
+ addAlert('Toast success alert', 'success', getUniqueId());
42
+ };
43
+
44
+ const addDangerAlert = () => {
45
+ addAlert('Toast danger alert', 'danger', getUniqueId());
46
+ };
47
+
48
+ const addInfoAlert = () => {
49
+ addAlert('Toast info alert', 'info', getUniqueId());
50
+ };
51
+
52
+ const onOverflowClick = () => {
53
+ // eslint-disable-next-line no-console
54
+ console.log('Overflow message clicked');
55
+ };
56
+
57
+ return (
58
+ <React.Fragment>
59
+ <InputGroup style={{ marginBottom: '16px' }}>
60
+ <button onClick={addSuccessAlert} type="button" className={btnClasses}>
61
+ Add single success alert
62
+ </button>
63
+ <button onClick={addDangerAlert} type="button" className={btnClasses}>
64
+ Add single danger alert
65
+ </button>
66
+ <button onClick={addInfoAlert} type="button" className={btnClasses}>
67
+ Add single info alert
68
+ </button>
69
+ </InputGroup>
70
+ <AlertGroup isLiveRegion onOverflowClick={onOverflowClick} overflowMessage={overflowMessage}>
71
+ {alerts.slice(0, maxDisplayed).map(({ key, variant, title }) => (
72
+ <Alert
73
+ isInline
74
+ variant={AlertVariant[variant]}
75
+ title={title}
76
+ actionClose={
77
+ <AlertActionCloseButton
78
+ title={title as string}
79
+ variantLabel={`${variant} alert`}
80
+ onClose={() => removeAlert(key)}
81
+ />
82
+ }
83
+ key={key}
84
+ />
85
+ ))}
86
+ </AlertGroup>
87
+ </React.Fragment>
88
+ );
89
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Alert, AlertGroup } from '@patternfly/react-core';
3
+
4
+ export const AlertGroupStatic: React.FunctionComponent = () => (
5
+ <React.Fragment>
6
+ <AlertGroup>
7
+ <Alert title="Success alert" variant="success" isInline />
8
+ <Alert title="Info alert" variant="info" isInline />
9
+ </AlertGroup>
10
+ </React.Fragment>
11
+ );
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import {
3
+ Alert,
4
+ AlertProps,
5
+ AlertGroup,
6
+ AlertActionCloseButton,
7
+ AlertVariant,
8
+ InputGroup
9
+ } from '@patternfly/react-core';
10
+
11
+ export const AlertGroupToast: React.FunctionComponent = () => {
12
+ const [alerts, setAlerts] = React.useState<Partial<AlertProps>[]>([]);
13
+
14
+ const addAlert = (title: string, variant: AlertProps['variant'], key: React.Key) => {
15
+ setAlerts(prevAlerts => [...prevAlerts, { title, variant, key }]);
16
+ };
17
+
18
+ const removeAlert = (key: React.Key) => {
19
+ setAlerts(prevAlerts => [...prevAlerts.filter(alert => alert.key !== key)]);
20
+ };
21
+
22
+ const btnClasses = ['pf-c-button', 'pf-m-secondary'].join(' ');
23
+
24
+ const getUniqueId = () => new Date().getTime();
25
+
26
+ const addSuccessAlert = () => {
27
+ addAlert('Toast success alert', 'success', getUniqueId());
28
+ };
29
+
30
+ const addDangerAlert = () => {
31
+ addAlert('Toast danger alert', 'danger', getUniqueId());
32
+ };
33
+
34
+ const addInfoAlert = () => {
35
+ addAlert('Toast info alert', 'info', getUniqueId());
36
+ };
37
+
38
+ return (
39
+ <React.Fragment>
40
+ <InputGroup style={{ marginBottom: '16px' }}>
41
+ <button onClick={addSuccessAlert} type="button" className={btnClasses}>
42
+ Add toast success alert
43
+ </button>
44
+ <button onClick={addDangerAlert} type="button" className={btnClasses}>
45
+ Add toast danger alert
46
+ </button>
47
+ <button onClick={addInfoAlert} type="button" className={btnClasses}>
48
+ Add toast info alert
49
+ </button>
50
+ </InputGroup>
51
+ <AlertGroup isToast isLiveRegion>
52
+ {alerts.map(({ key, variant, title }) => (
53
+ <Alert
54
+ variant={AlertVariant[variant]}
55
+ title={title}
56
+ actionClose={
57
+ <AlertActionCloseButton
58
+ title={title as string}
59
+ variantLabel={`${variant} alert`}
60
+ onClose={() => removeAlert(key)}
61
+ />
62
+ }
63
+ key={key}
64
+ />
65
+ ))}
66
+ </AlertGroup>
67
+ </React.Fragment>
68
+ );
69
+ };
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import {
3
+ Alert,
4
+ AlertProps,
5
+ AlertGroup,
6
+ AlertActionCloseButton,
7
+ AlertVariant,
8
+ InputGroup
9
+ } from '@patternfly/react-core';
10
+
11
+ export const AlertGroupToastOverflowCapture: React.FunctionComponent = () => {
12
+ const [alerts, setAlerts] = React.useState<Partial<AlertProps>[]>([]);
13
+ const [overflowMessage, setOverflowMessage] = React.useState<string>('');
14
+
15
+ const maxDisplayed = 4;
16
+
17
+ const getOverflowMessage = (alertsNumber: number) => {
18
+ const overflow = alertsNumber - maxDisplayed;
19
+ if (overflow > 0) {
20
+ return `View ${overflow} more alerts`;
21
+ }
22
+ return '';
23
+ };
24
+
25
+ const addAlert = (title: string, variant: AlertProps['variant'], key: React.Key) => {
26
+ setAlerts(prevAlerts => [...prevAlerts, { title, variant, key }]);
27
+ setOverflowMessage(getOverflowMessage(alerts.length + 1));
28
+ };
29
+
30
+ const removeAlert = (key: React.Key) => {
31
+ const newAlerts = alerts.filter(alert => alert.key !== key);
32
+ setAlerts(newAlerts);
33
+ setOverflowMessage(getOverflowMessage(newAlerts.length));
34
+ };
35
+
36
+ const btnClasses = ['pf-c-button', 'pf-m-secondary'].join(' ');
37
+
38
+ const getUniqueId = () => new Date().getTime();
39
+
40
+ const addSuccessAlert = () => {
41
+ addAlert('Toast success alert', 'success', getUniqueId());
42
+ };
43
+
44
+ const addDangerAlert = () => {
45
+ addAlert('Toast danger alert', 'danger', getUniqueId());
46
+ };
47
+
48
+ const addInfoAlert = () => {
49
+ addAlert('Toast info alert', 'info', getUniqueId());
50
+ };
51
+
52
+ const onOverflowClick = () => {
53
+ // eslint-disable-next-line no-console
54
+ console.log('Overflow message clicked');
55
+ };
56
+
57
+ return (
58
+ <React.Fragment>
59
+ <InputGroup style={{ marginBottom: '16px' }}>
60
+ <button onClick={addSuccessAlert} type="button" className={btnClasses}>
61
+ Add toast success alert
62
+ </button>
63
+ <button onClick={addDangerAlert} type="button" className={btnClasses}>
64
+ Add toast danger alert
65
+ </button>
66
+ <button onClick={addInfoAlert} type="button" className={btnClasses}>
67
+ Add toast info alert
68
+ </button>
69
+ </InputGroup>
70
+ <AlertGroup isToast isLiveRegion onOverflowClick={onOverflowClick} overflowMessage={overflowMessage}>
71
+ {alerts.slice(0, maxDisplayed).map(({ key, variant, title }) => (
72
+ <Alert
73
+ variant={AlertVariant[variant]}
74
+ title={title}
75
+ actionClose={
76
+ <AlertActionCloseButton
77
+ title={title as string}
78
+ variantLabel={`${variant} alert`}
79
+ onClose={() => removeAlert(key)}
80
+ />
81
+ }
82
+ key={key}
83
+ />
84
+ ))}
85
+ </AlertGroup>
86
+ </React.Fragment>
87
+ );
88
+ };
@@ -9,3 +9,4 @@ export * from './Popper/Popper';
9
9
  export * from './useIsomorphicLayout';
10
10
  export * from './KeyboardHandler';
11
11
  export * from './resizeObserver';
12
+ export * from './useInterval';
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+
3
+ /** This is a custom React hook in a format suggest by Dan Abramov in a blog post here:
4
+ * https://overreacted.io/making-setinterval-declarative-with-react-hooks/. It allows setInterval to be used
5
+ * declaratively in functional React components.
6
+ */
7
+
8
+ export function useInterval(callback: () => void, delay: number | null) {
9
+ const savedCallback = React.useRef(() => {});
10
+
11
+ React.useEffect(() => {
12
+ savedCallback.current = callback;
13
+ }, [callback]);
14
+
15
+ React.useEffect(() => {
16
+ function tick() {
17
+ savedCallback.current();
18
+ }
19
+
20
+ if (delay !== null) {
21
+ const id = setInterval(tick, delay);
22
+ return () => clearInterval(id);
23
+ }
24
+ }, [delay]);
25
+ }