@patternfly/react-core 4.175.16 → 4.178.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 (78) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/esm/components/Dropdown/DropdownToggle.d.ts +3 -1
  3. package/dist/esm/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  4. package/dist/esm/components/Dropdown/DropdownToggle.js +4 -4
  5. package/dist/esm/components/Dropdown/DropdownToggle.js.map +1 -1
  6. package/dist/esm/components/Dropdown/Toggle.d.ts +3 -1
  7. package/dist/esm/components/Dropdown/Toggle.d.ts.map +1 -1
  8. package/dist/esm/components/Dropdown/Toggle.js +8 -3
  9. package/dist/esm/components/Dropdown/Toggle.js.map +1 -1
  10. package/dist/esm/components/MenuToggle/MenuToggle.d.ts +1 -1
  11. package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  12. package/dist/esm/components/MenuToggle/MenuToggle.js +2 -1
  13. package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
  14. package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
  15. package/dist/esm/components/Popover/Popover.js +2 -22
  16. package/dist/esm/components/Popover/Popover.js.map +1 -1
  17. package/dist/esm/components/Select/Select.d.ts +2 -0
  18. package/dist/esm/components/Select/Select.d.ts.map +1 -1
  19. package/dist/esm/components/Select/Select.js +7 -9
  20. package/dist/esm/components/Select/Select.js.map +1 -1
  21. package/dist/esm/components/Slider/Slider.d.ts.map +1 -1
  22. package/dist/esm/components/Slider/Slider.js +9 -6
  23. package/dist/esm/components/Slider/Slider.js.map +1 -1
  24. package/dist/js/components/Dropdown/DropdownToggle.d.ts +3 -1
  25. package/dist/js/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  26. package/dist/js/components/Dropdown/DropdownToggle.js +4 -4
  27. package/dist/js/components/Dropdown/DropdownToggle.js.map +1 -1
  28. package/dist/js/components/Dropdown/Toggle.d.ts +3 -1
  29. package/dist/js/components/Dropdown/Toggle.d.ts.map +1 -1
  30. package/dist/js/components/Dropdown/Toggle.js +8 -3
  31. package/dist/js/components/Dropdown/Toggle.js.map +1 -1
  32. package/dist/js/components/MenuToggle/MenuToggle.d.ts +1 -1
  33. package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  34. package/dist/js/components/MenuToggle/MenuToggle.js +2 -1
  35. package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
  36. package/dist/js/components/Popover/Popover.d.ts.map +1 -1
  37. package/dist/js/components/Popover/Popover.js +2 -22
  38. package/dist/js/components/Popover/Popover.js.map +1 -1
  39. package/dist/js/components/Select/Select.d.ts +2 -0
  40. package/dist/js/components/Select/Select.d.ts.map +1 -1
  41. package/dist/js/components/Select/Select.js +7 -9
  42. package/dist/js/components/Select/Select.js.map +1 -1
  43. package/dist/js/components/Slider/Slider.d.ts.map +1 -1
  44. package/dist/js/components/Slider/Slider.js +9 -6
  45. package/dist/js/components/Slider/Slider.js.map +1 -1
  46. package/dist/umd/react-core.css +191 -191
  47. package/dist/umd/react-core.js +32 -45
  48. package/dist/umd/react-core.min.css +69 -69
  49. package/dist/umd/react-core.min.js +2 -2
  50. package/package.json +5 -5
  51. package/src/components/Alert/examples/Alert.md +201 -382
  52. package/src/components/Alert/examples/AlertAsyncLiveRegion.tsx +61 -0
  53. package/src/components/Alert/examples/AlertDynamicLiveRegion.tsx +61 -0
  54. package/src/components/ApplicationLauncher/__tests__/__snapshots__/ApplicationLauncher.test.tsx.snap +6 -0
  55. package/src/components/Dropdown/DropdownToggle.tsx +6 -1
  56. package/src/components/Dropdown/Toggle.tsx +11 -1
  57. package/src/components/Dropdown/__tests__/DropdownToggle.test.tsx +51 -0
  58. package/src/components/Dropdown/__tests__/__snapshots__/Dropdown.test.tsx.snap +8 -0
  59. package/src/components/Dropdown/__tests__/__snapshots__/DropdownToggle.test.tsx.snap +346 -4
  60. package/src/components/Dropdown/__tests__/__snapshots__/Toggle.test.tsx.snap +1 -0
  61. package/src/components/Dropdown/examples/Dropdown.md +160 -91
  62. package/src/components/MenuToggle/MenuToggle.tsx +5 -2
  63. package/src/components/MenuToggle/__tests__/MenuToggle.test.tsx +5 -0
  64. package/src/components/MenuToggle/__tests__/__snapshots__/MenuToggle.test.tsx.snap +59 -0
  65. package/src/components/MenuToggle/examples/MenuToggle.md +60 -67
  66. package/src/components/OptionsMenu/__tests__/__snapshots__/OptionsMenu.test.tsx.snap +7 -0
  67. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +15 -0
  68. package/src/components/Popover/Popover.tsx +1 -19
  69. package/src/components/Popover/__tests__/Generated/__snapshots__/Popover.test.tsx.snap +0 -1
  70. package/src/components/Popover/__tests__/__snapshots__/Popover.test.tsx.snap +0 -4
  71. package/src/components/Select/Select.tsx +9 -1
  72. package/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +25 -0
  73. package/src/components/Select/examples/Select.md +75 -9
  74. package/src/components/Slider/Slider.tsx +9 -6
  75. package/src/components/Slider/examples/Slider.md +27 -0
  76. package/src/demos/CardDemos.md +65 -91
  77. package/src/demos/Tabs/NestedTabsDemo.js +151 -0
  78. package/src/demos/Tabs.md +4 -0
@@ -16,412 +16,245 @@ import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon';
16
16
  ## Examples
17
17
 
18
18
  ### Types
19
- ```js
19
+ ```ts
20
20
  import React from 'react';
21
21
  import { Alert } from '@patternfly/react-core';
22
22
 
23
- class AlertTypes extends React.Component {
24
- render() {
25
- return (
26
- <React.Fragment>
27
- <Alert title="Default alert title" />
28
- <Alert variant="info" title="Info alert title" />
29
- <Alert variant="success" title="Success alert title" />
30
- <Alert variant="warning" title="Warning alert title" />
31
- <Alert variant="danger" title="Danger alert title" />
32
- </React.Fragment>
33
- );
34
- }
35
- }
23
+ <React.Fragment>
24
+ <Alert title="Default alert title" />
25
+ <Alert variant="info" title="Info alert title" />
26
+ <Alert variant="success" title="Success alert title" />
27
+ <Alert variant="warning" title="Warning alert title" />
28
+ <Alert variant="danger" title="Danger alert title" />
29
+ </React.Fragment>
36
30
  ```
37
31
 
38
32
  ### Variations
39
- ```js
33
+ ```ts
40
34
  import React from 'react';
41
35
  import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
42
36
 
43
- class AlertVariations extends React.Component {
44
- render() {
45
- return (
37
+ <React.Fragment>
38
+ <Alert
39
+ variant="success"
40
+ title="Success alert title"
41
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
42
+ actionLinks={
46
43
  <React.Fragment>
47
- <Alert
48
- variant="success"
49
- title="Success alert title"
50
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
51
- actionLinks={
52
- <React.Fragment>
53
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
54
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
55
- </React.Fragment>
56
- }
57
- >
58
- <p>Success alert description. This should tell the user more information about the alert.</p>
59
- </Alert>
60
- <Alert variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}>
61
- <p>
62
- Success alert description. This should tell the user more information about the alert.{' '}
63
- <a href="#">This is a link.</a>
64
- </p>
65
- </Alert>
66
- <Alert
67
- variant="success"
68
- title="Success alert title"
69
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
70
- actionLinks={
71
- <React.Fragment>
72
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
73
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
74
- </React.Fragment>
75
- }
76
- />
77
- <Alert variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />} />
78
- <Alert variant="success" title="h1 Success alert title" titleHeadingLevel="h1" />
79
- <Alert variant="success" title="h6 Success alert title" titleHeadingLevel="h6" />
44
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
45
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
80
46
  </React.Fragment>
81
- );
82
- }
83
- }
47
+ }
48
+ >
49
+ <p>Success alert description. This should tell the user more information about the alert.</p>
50
+ </Alert>
51
+ <Alert variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}>
52
+ <p>
53
+ Success alert description. This should tell the user more information about the alert.{' '}
54
+ <a href="#">This is a link.</a>
55
+ </p>
56
+ </Alert>
57
+ <Alert
58
+ variant="success"
59
+ title="Success alert title"
60
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
61
+ actionLinks={
62
+ <React.Fragment>
63
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
64
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
65
+ </React.Fragment>
66
+ }
67
+ />
68
+ <Alert variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />} />
69
+ <Alert variant="success" title="h1 Success alert title" titleHeadingLevel="h1" />
70
+ <Alert variant="success" title="h6 Success alert title" titleHeadingLevel="h6" />
71
+ </React.Fragment>
84
72
  ```
85
73
 
86
74
  ### Inline types
87
- ```js
75
+ ```ts
88
76
  import React from 'react';
89
77
  import { Alert } from '@patternfly/react-core';
90
78
 
91
- class InlineAlert extends React.Component {
92
- render() {
93
- return (
94
- <React.Fragment>
95
- <Alert variant="default" isInline title="Default inline alert title" />
96
- <Alert variant="info" isInline title="Info inline alert title" />
97
- <Alert variant="success" isInline title="Success inline alert title" />
98
- <Alert variant="warning" isInline title="Warning inline alert title" />
99
- <Alert variant="danger" isInline title="Danger inline alert title" />
100
- </React.Fragment>
101
- );
102
- }
103
- }
79
+ <React.Fragment>
80
+ <Alert variant="default" isInline title="Default inline alert title" />
81
+ <Alert variant="info" isInline title="Info inline alert title" />
82
+ <Alert variant="success" isInline title="Success inline alert title" />
83
+ <Alert variant="warning" isInline title="Warning inline alert title" />
84
+ <Alert variant="danger" isInline title="Danger inline alert title" />
85
+ </React.Fragment>
104
86
  ```
105
87
 
106
88
  ### Inline variations
107
- ```js
89
+ ```ts
108
90
  import React from 'react';
109
91
  import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
110
92
 
111
- class InlineAlertVariations extends React.Component {
112
- render() {
113
- return (
93
+ <React.Fragment>
94
+ <Alert
95
+ isInline
96
+ variant="success"
97
+ title="Success alert title"
98
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
99
+ actionLinks={
114
100
  <React.Fragment>
115
- <Alert
116
- isInline
117
- variant="success"
118
- title="Success alert title"
119
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
120
- actionLinks={
121
- <React.Fragment>
122
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
123
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
124
- </React.Fragment>
125
- }
126
- >
127
- <p>Success alert description. This should tell the user more information about the alert.</p>
128
- </Alert>
129
- <Alert isInline variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}>
130
- <p>
131
- Success alert description. This should tell the user more information about the alert.{' '}
132
- <a href="#">This is a link.</a>
133
- </p>
134
- </Alert>
135
- <Alert
136
- isInline
137
- variant="success"
138
- title="Success alert title"
139
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
140
- actionLinks={
141
- <React.Fragment>
142
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
143
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
144
- </React.Fragment>
145
- }
146
- />
147
- <Alert
148
- isInline
149
- variant="success"
150
- title="Success alert title"
151
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
152
- />
153
- <Alert isInline variant="success" title="Success alert title" />
101
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
102
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
154
103
  </React.Fragment>
155
- );
156
- }
157
- }
104
+ }
105
+ >
106
+ <p>Success alert description. This should tell the user more information about the alert.</p>
107
+ </Alert>
108
+ <Alert isInline variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}>
109
+ <p>
110
+ Success alert description. This should tell the user more information about the alert.{' '}
111
+ <a href="#">This is a link.</a>
112
+ </p>
113
+ </Alert>
114
+ <Alert
115
+ isInline
116
+ variant="success"
117
+ title="Success alert title"
118
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
119
+ actionLinks={
120
+ <React.Fragment>
121
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
122
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
123
+ </React.Fragment>
124
+ }
125
+ />
126
+ <Alert
127
+ isInline
128
+ variant="success"
129
+ title="Success alert title"
130
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
131
+ />
132
+ <Alert isInline variant="success" title="Success alert title" />
133
+ </React.Fragment>
158
134
  ```
159
135
 
160
136
  ### Inline plain types
161
- ```js
137
+ ```ts
162
138
  import React from 'react';
163
139
  import { Alert } from '@patternfly/react-core';
164
140
 
165
- class InlinePlainAlert extends React.Component {
166
- render() {
167
- return (
168
- <React.Fragment>
169
- <Alert variant="default" isInline isPlain title="Default inline alert title" />
170
- <Alert variant="info" isInline isPlain title="Info inline alert title" />
171
- <Alert variant="success" isInline isPlain title="Success inline alert title" />
172
- <Alert variant="warning" isInline isPlain title="Warning inline alert title" />
173
- <Alert variant="danger" isInline isPlain title="Danger inline alert title" />
174
- </React.Fragment>
175
- );
176
- }
177
- }
141
+ <React.Fragment>
142
+ <Alert variant="default" isInline isPlain title="Default inline alert title" />
143
+ <Alert variant="info" isInline isPlain title="Info inline alert title" />
144
+ <Alert variant="success" isInline isPlain title="Success inline alert title" />
145
+ <Alert variant="warning" isInline isPlain title="Warning inline alert title" />
146
+ <Alert variant="danger" isInline isPlain title="Danger inline alert title" />
147
+ </React.Fragment>
178
148
  ```
179
149
 
180
150
  ### Inline plain variations
181
151
 
182
152
  It is not recommended to use an inline plain alert with actionClose nor actionLinks.
183
153
 
184
- ```js
154
+ ```ts
185
155
  import React from 'react';
186
156
  import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
187
157
 
188
- class InlinePlainAlertVariations extends React.Component {
189
- render() {
190
- return (
191
- <Alert
192
- isInline
193
- isPlain
194
- variant="success"
195
- title="Success alert title"
196
- >
197
- <p>Success alert description. This should tell the user more information about the alert.</p>
198
- </Alert>
199
- );
200
- }
201
- }
158
+ <Alert
159
+ isInline
160
+ isPlain
161
+ variant="success"
162
+ title="Success alert title"
163
+ >
164
+ <p>Success alert description. This should tell the user more information about the alert.</p>
165
+ </Alert>
202
166
  ```
203
167
 
204
168
  ### Expandable
205
169
 
206
170
  It is not recommended to use an expandable alert within a toast Alert group. In such a case, the Alert could timeout before users would have time to interact and view the entire Alert.
207
171
 
208
- ```js
172
+ ```ts
209
173
  import React from 'react';
210
174
  import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
211
175
 
212
- class ExpandableAlert extends React.Component {
213
- render() {
214
- return (
176
+ <React.Fragment>
177
+ <Alert
178
+ isExpandable
179
+ variant="success"
180
+ title="Success alert title"
181
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
182
+ actionLinks={
215
183
  <React.Fragment>
216
- <Alert
217
- isExpandable
218
- variant="success"
219
- title="Success alert title"
220
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
221
- actionLinks={
222
- <React.Fragment>
223
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
224
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
225
- </React.Fragment>
226
- }
227
- >
228
- <p>Success alert description. This should tell the user more information about the alert.</p>
229
- </Alert>
230
- <Alert
231
- isExpandable
232
- isInline
233
- variant="success"
234
- title="Success alert title"
235
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
236
- actionLinks={
237
- <React.Fragment>
238
- <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
239
- <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
240
- </React.Fragment>
241
- }
242
- >
243
- <p>Success alert description. This should tell the user more information about the alert.</p>
244
- </Alert>
184
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
185
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
245
186
  </React.Fragment>
246
- );
247
- }
248
- }
187
+ }
188
+ >
189
+ <p>Success alert description. This should tell the user more information about the alert.</p>
190
+ </Alert>
191
+ <Alert
192
+ isExpandable
193
+ isInline
194
+ variant="success"
195
+ title="Success alert title"
196
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
197
+ actionLinks={
198
+ <React.Fragment>
199
+ <AlertActionLink onClick={() => alert('Clicked on View details')}>View details</AlertActionLink>
200
+ <AlertActionLink onClick={() => alert('Clicked on Ignore')}>Ignore</AlertActionLink>
201
+ </React.Fragment>
202
+ }
203
+ >
204
+ <p>Success alert description. This should tell the user more information about the alert.</p>
205
+ </Alert>
206
+ </React.Fragment>
249
207
  ```
250
208
 
251
209
  ### Static live region alert
252
- ```js
210
+ ```ts
253
211
  import React from 'react';
254
212
  import { Alert, AlertActionCloseButton } from '@patternfly/react-core';
255
213
 
256
- class StaticLiveRegionAlert extends React.Component {
257
- render() {
258
- return (
259
- <React.Fragment>
260
- <Alert
261
- isLiveRegion
262
- variant="info"
263
- title="Default live region configuration"
264
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
265
- >
266
- This alert uses the recommended <code>isLiveRegion</code> prop to automatically set ARIA attributes and CSS classes.
267
- </Alert>
268
- <Alert
269
- aria-live="assertive"
270
- aria-relevant="additions text"
271
- aria-atomic="true"
272
- variant="info"
273
- title="Customized live region"
274
- actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
275
- >
276
- You can alternatively omit the <code>isLiveRegion</code> prop to specify ARIA attributes and CSS manually on
277
- the containing element.
278
- </Alert>
279
- </React.Fragment>
280
- );
281
- }
282
- }
214
+ <React.Fragment>
215
+ <Alert
216
+ isLiveRegion
217
+ variant="info"
218
+ title="Default live region configuration"
219
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
220
+ >
221
+ This alert uses the recommended <code>isLiveRegion</code> prop to automatically set ARIA attributes and CSS classes.
222
+ </Alert>
223
+ <Alert
224
+ aria-live="assertive"
225
+ aria-relevant="additions text"
226
+ aria-atomic="true"
227
+ variant="info"
228
+ title="Customized live region"
229
+ actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />}
230
+ >
231
+ You can alternatively omit the <code>isLiveRegion</code> prop to specify ARIA attributes and CSS manually on
232
+ the containing element.
233
+ </Alert>
234
+ </React.Fragment>
283
235
  ```
284
236
 
285
237
  ### Dynamic live region alert
286
238
  Alerts asynchronously appended into dynamic AlertGroups with isLiveRegion will be announced to assistive technology at the moment the change happens, following the strategy used for aria-atomic, which defaults to false. This means only changes of type "addition" will be announced.
287
- ```js
288
- import React from 'react';
289
- import { Alert, AlertGroup, InputGroup } from '@patternfly/react-core';
290
-
291
- class DynamicLiveRegionAlert extends React.Component {
292
- constructor() {
293
- super();
294
- this.state = {
295
- alerts: []
296
- };
297
- }
298
-
299
- render() {
300
- const addAlert = alertProps => {
301
- this.setState({ alerts: [...this.state.alerts, alertProps] });
302
- };
303
- const getUniqueId = () => new Date().getTime();
304
- const addSuccessAlert = () => {
305
- addAlert({
306
- title: 'Single success alert',
307
- variant: 'success',
308
- key: getUniqueId()
309
- });
310
- };
311
- const addInfoAlert = () => {
312
- addAlert({
313
- title: 'Single info alert',
314
- variant: 'info',
315
- key: getUniqueId()
316
- });
317
- };
318
- const addDangerAlert = () => {
319
- addAlert({
320
- title: 'Single danger alert',
321
- variant: 'danger',
322
- key: getUniqueId()
323
- });
324
- };
325
- const btnClasses = ['pf-c-button', 'pf-m-secondary'].join(' ');
326
- return (
327
- <React.Fragment>
328
- <InputGroup style={{ marginBottom: '16px' }}>
329
- <button onClick={addSuccessAlert} type="button" className={btnClasses}>
330
- Add single success alert
331
- </button>
332
- <button onClick={addInfoAlert} type="button" className={btnClasses}>
333
- Add single info alert
334
- </button>
335
- <button onClick={addDangerAlert} type="button" className={btnClasses}>
336
- Add single danger alert
337
- </button>
338
- </InputGroup>
339
- <AlertGroup isLiveRegion aria-live="polite" aria-relevant="additions text" aria-atomic="false">
340
- {this.state.alerts.map(({ title, variant, isLiveRegion, ariaLive, ariaRelevant, ariaAtomic, key }) => (
341
- <Alert
342
- variant={variant}
343
- title={title}
344
- key={key}
345
- />
346
- ))}
347
- </AlertGroup>
348
- </React.Fragment>
349
- );
350
- }
351
- }
239
+ ```ts file="AlertDynamicLiveRegion.tsx"
352
240
  ```
353
241
 
354
242
  ### Async live region alert
355
243
  This shows how an alert could be triggered by an asynchronous event in the application. Note that you can customize how the alert will be announced to assistive technology. See the alert accessibility tab for more information.
356
- ```js
357
- import React from 'react';
358
- import { Alert, AlertGroup, InputGroup } from '@patternfly/react-core';
359
-
360
- class AsyncLiveRegionAlert extends React.Component {
361
- constructor() {
362
- super();
363
- this.state = {
364
- alerts: [],
365
- timer: null
366
- };
367
- this.stopAsyncAlerts = () => {
368
- clearInterval(this.state.timer);
369
- };
370
- }
371
- componentWillUnmount() {
372
- this.stopAsyncAlerts();
373
- }
374
- render() {
375
- const addAlert = incomingAlerts => {
376
- this.setState({ alerts: [...this.state.alerts, incomingAlerts] });
377
- };
378
- const getUniqueId = () => new Date().getTime();
379
- const startAsyncAlerts = () => {
380
- let timerValue = setInterval(() => {
381
- addAlert({
382
- title: `Async alert number ${this.state.alerts.length + 1}`,
383
- variant: 'info',
384
- key: getUniqueId()
385
- });
386
- }, 4500);
387
- this.setState({ timer: timerValue });
388
- };
389
- const btnClasses = ['pf-c-button', 'pf-m-secondary'].join(' ');
390
- return (
391
- <React.Fragment>
392
- <InputGroup style={{ marginBottom: '16px' }}>
393
- <button onClick={startAsyncAlerts} type="button" className={btnClasses}>
394
- Start async info alerts
395
- </button>
396
- <button onClick={this.stopAsyncAlerts} type="button" className={btnClasses}>
397
- Stop async info alerts
398
- </button>
399
- </InputGroup>
400
- <AlertGroup isLiveRegion>
401
- {this.state.alerts.map(({ title, variant, key }) => (
402
- <Alert variant={variant} title={title} key={key} />
403
- ))}
404
- </AlertGroup>
405
- </React.Fragment>
406
- );
407
- }
408
- }
244
+ ```ts file="AlertAsyncLiveRegion.tsx"
409
245
  ```
410
246
 
411
247
  ### Alert timeout
412
- ```js
248
+ ```ts
413
249
  import React from 'react';
414
250
  import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-core';
415
251
 
416
- class AlertTimeout extends React.Component {
417
- constructor() {
418
- super();
419
- this.state = {
420
- alerts: []
421
- };
422
- this.onClick = () => {
423
- const timeout = 8000;
424
- this.state.alerts.push(
252
+ const AlertTimeout: React.FunctionComponent = () => {
253
+ const [alerts, setAlerts] = React.useState<React.ReactNode[]>([]);
254
+ const onClick = () => {
255
+ const timeout = 8000;
256
+ setAlerts(prevAlerts => {
257
+ return [...prevAlerts,
425
258
  <Alert title="Default timeout Alert" timeout={timeout} actionLinks={
426
259
  <React.Fragment>
427
260
  <AlertActionLink>View details</AlertActionLink>
@@ -430,50 +263,42 @@ class AlertTimeout extends React.Component {
430
263
  }>
431
264
  This alert will dismiss after {`${timeout / 1000} seconds`}
432
265
  </Alert>
433
- );
434
- this.setState({ alerts: [...this.state.alerts] })
435
- };
266
+ ]
267
+ });
436
268
  }
437
269
 
438
- render() {
439
- return (
440
- <React.Fragment>
441
- <Button variant="secondary" onClick={this.onClick}>Add alert</Button>
442
- <Button variant="secondary" onClick={() => this.setState({ alerts: [] })}>Remove all alerts</Button>
443
- <AlertGroup isLiveRegion>
444
- {this.state.alerts}
445
- </AlertGroup>
446
- </React.Fragment>
447
- );
448
- }
449
- }
270
+ return (
271
+ <React.Fragment>
272
+ <Button variant="secondary" onClick={onClick}>Add alert</Button>
273
+ <Button variant="secondary" onClick={() => setAlerts([])}>Remove all alerts</Button>
274
+ <AlertGroup isLiveRegion>
275
+ {alerts}
276
+ </AlertGroup>
277
+ </React.Fragment>
278
+ );
279
+ };
450
280
  ```
451
281
 
452
282
  ### Truncate
453
- ```js
283
+ ```ts
454
284
  import React from 'react';
455
285
  import { Alert } from '@patternfly/react-core';
456
- class AlertTypes extends React.Component {
457
- render() {
458
- return (
459
- <React.Fragment>
460
- <Alert variant="info" truncateTitle={1} title={`
461
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
462
- `} />
463
- <Alert variant="warning" truncateTitle={2} title={`
464
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
465
- `} />
466
- <Alert variant="danger" truncateTitle={3} title={`
467
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
468
- `} />
469
- </React.Fragment>
470
- );
471
- }
472
- }
286
+
287
+ <React.Fragment>
288
+ <Alert variant="info" truncateTitle={1} title={`
289
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
290
+ `} />
291
+ <Alert variant="warning" truncateTitle={2} title={`
292
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
293
+ `} />
294
+ <Alert variant="danger" truncateTitle={3} title={`
295
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
296
+ `} />
297
+ </React.Fragment>
473
298
  ```
474
299
 
475
300
  ### Custom icons
476
- ```js
301
+ ```ts
477
302
  import React from 'react';
478
303
  import { Alert } from '@patternfly/react-core';
479
304
  import UsersIcon from '@patternfly/react-icons/dist/esm/icons/users-icon';
@@ -482,17 +307,11 @@ import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon';
482
307
  import ServerIcon from '@patternfly/react-icons/dist/esm/icons/server-icon';
483
308
  import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon';
484
309
 
485
- class AlertTypes extends React.Component {
486
- render() {
487
- return (
488
- <React.Fragment>
489
- <Alert customIcon={<UsersIcon />} title="Default alert title" />
490
- <Alert customIcon={<BoxIcon />} variant="info" title="Info alert title" />
491
- <Alert customIcon={<DatabaseIcon />} variant="success" title="Success alert title" />
492
- <Alert customIcon={<ServerIcon />} variant="warning" title="Warning alert title" />
493
- <Alert customIcon={<LaptopIcon />} variant="danger" title="Danger alert title" />
494
- </React.Fragment>
495
- );
496
- }
497
- }
310
+ <React.Fragment>
311
+ <Alert customIcon={<UsersIcon />} title="Default alert title" />
312
+ <Alert customIcon={<BoxIcon />} variant="info" title="Info alert title" />
313
+ <Alert customIcon={<DatabaseIcon />} variant="success" title="Success alert title" />
314
+ <Alert customIcon={<ServerIcon />} variant="warning" title="Warning alert title" />
315
+ <Alert customIcon={<LaptopIcon />} variant="danger" title="Danger alert title" />
316
+ </React.Fragment>
498
317
  ```