@patternfly/react-core 4.192.7 → 4.192.11

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 (100) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/esm/components/Label/Label.d.ts.map +1 -1
  3. package/dist/esm/components/Label/Label.js +38 -25
  4. package/dist/esm/components/Label/Label.js.map +1 -1
  5. package/dist/esm/components/Select/Select.d.ts +5 -1
  6. package/dist/esm/components/Select/Select.d.ts.map +1 -1
  7. package/dist/esm/components/Select/Select.js +171 -28
  8. package/dist/esm/components/Select/Select.js.map +1 -1
  9. package/dist/esm/components/Select/SelectMenu.d.ts.map +1 -1
  10. package/dist/esm/components/Select/SelectMenu.js +2 -1
  11. package/dist/esm/components/Select/SelectMenu.js.map +1 -1
  12. package/dist/esm/components/Select/SelectOption.d.ts.map +1 -1
  13. package/dist/esm/components/Select/SelectOption.js +6 -1
  14. package/dist/esm/components/Select/SelectOption.js.map +1 -1
  15. package/dist/esm/components/Select/SelectToggle.d.ts +3 -2
  16. package/dist/esm/components/Select/SelectToggle.d.ts.map +1 -1
  17. package/dist/esm/components/Select/SelectToggle.js +26 -16
  18. package/dist/esm/components/Select/SelectToggle.js.map +1 -1
  19. package/dist/esm/components/Select/selectConstants.d.ts +1 -0
  20. package/dist/esm/components/Select/selectConstants.d.ts.map +1 -1
  21. package/dist/esm/components/Select/selectConstants.js +1 -0
  22. package/dist/esm/components/Select/selectConstants.js.map +1 -1
  23. package/dist/esm/components/Tabs/Tabs.d.ts +2 -5
  24. package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
  25. package/dist/esm/components/Tabs/Tabs.js +3 -3
  26. package/dist/esm/components/Tabs/Tabs.js.map +1 -1
  27. package/dist/esm/components/TimePicker/TimePicker.d.ts +4 -6
  28. package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
  29. package/dist/esm/components/TimePicker/TimePicker.js +74 -42
  30. package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
  31. package/dist/esm/helpers/util.d.ts +6 -0
  32. package/dist/esm/helpers/util.d.ts.map +1 -1
  33. package/dist/esm/helpers/util.js +12 -0
  34. package/dist/esm/helpers/util.js.map +1 -1
  35. package/dist/js/components/Label/Label.d.ts.map +1 -1
  36. package/dist/js/components/Label/Label.js +38 -25
  37. package/dist/js/components/Label/Label.js.map +1 -1
  38. package/dist/js/components/Select/Select.d.ts +5 -1
  39. package/dist/js/components/Select/Select.d.ts.map +1 -1
  40. package/dist/js/components/Select/Select.js +170 -27
  41. package/dist/js/components/Select/Select.js.map +1 -1
  42. package/dist/js/components/Select/SelectMenu.d.ts.map +1 -1
  43. package/dist/js/components/Select/SelectMenu.js +2 -1
  44. package/dist/js/components/Select/SelectMenu.js.map +1 -1
  45. package/dist/js/components/Select/SelectOption.d.ts.map +1 -1
  46. package/dist/js/components/Select/SelectOption.js +6 -1
  47. package/dist/js/components/Select/SelectOption.js.map +1 -1
  48. package/dist/js/components/Select/SelectToggle.d.ts +3 -2
  49. package/dist/js/components/Select/SelectToggle.d.ts.map +1 -1
  50. package/dist/js/components/Select/SelectToggle.js +25 -15
  51. package/dist/js/components/Select/SelectToggle.js.map +1 -1
  52. package/dist/js/components/Select/selectConstants.d.ts +1 -0
  53. package/dist/js/components/Select/selectConstants.d.ts.map +1 -1
  54. package/dist/js/components/Select/selectConstants.js +2 -1
  55. package/dist/js/components/Select/selectConstants.js.map +1 -1
  56. package/dist/js/components/Tabs/Tabs.d.ts +2 -5
  57. package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
  58. package/dist/js/components/Tabs/Tabs.js +3 -3
  59. package/dist/js/components/Tabs/Tabs.js.map +1 -1
  60. package/dist/js/components/TimePicker/TimePicker.d.ts +4 -6
  61. package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
  62. package/dist/js/components/TimePicker/TimePicker.js +73 -41
  63. package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
  64. package/dist/js/helpers/util.d.ts +6 -0
  65. package/dist/js/helpers/util.d.ts.map +1 -1
  66. package/dist/js/helpers/util.js +14 -1
  67. package/dist/js/helpers/util.js.map +1 -1
  68. package/dist/umd/react-core.css +64 -110
  69. package/dist/umd/react-core.js +847 -653
  70. package/dist/umd/react-core.min.css +64 -110
  71. package/dist/umd/react-core.min.js +3 -3
  72. package/package.json +6 -6
  73. package/src/components/Alert/examples/AlertAsyncLiveRegion.tsx +1 -1
  74. package/src/components/ApplicationLauncher/examples/ApplicationLauncher.md +11 -577
  75. package/src/components/ApplicationLauncher/examples/ApplicationLauncherAlignRight.tsx +32 -0
  76. package/src/components/ApplicationLauncher/examples/ApplicationLauncherAlignTop.tsx +31 -0
  77. package/src/components/ApplicationLauncher/examples/ApplicationLauncherBasic.tsx +23 -0
  78. package/src/components/ApplicationLauncher/examples/ApplicationLauncherCustomIcon.tsx +32 -0
  79. package/src/components/ApplicationLauncher/examples/ApplicationLauncherDisabled.tsx +25 -0
  80. package/src/components/ApplicationLauncher/examples/ApplicationLauncherDocumentBody.tsx +31 -0
  81. package/src/components/ApplicationLauncher/examples/ApplicationLauncherFavoritesAndSearch.tsx +105 -0
  82. package/src/components/ApplicationLauncher/examples/ApplicationLauncherRouterLink.tsx +50 -0
  83. package/src/components/ApplicationLauncher/examples/ApplicationLauncherSectionsAndIcons.tsx +47 -0
  84. package/src/components/ApplicationLauncher/examples/ApplicationLauncherTooltip.tsx +35 -0
  85. package/src/components/Label/Label.tsx +58 -39
  86. package/src/components/Label/__tests__/Label.test.tsx +19 -1
  87. package/src/components/Label/__tests__/__snapshots__/Label.test.tsx.snap +109 -0
  88. package/src/components/Label/examples/Label.md +1 -41
  89. package/src/components/Label/examples/LabelEditable.tsx +57 -0
  90. package/src/components/Select/Select.tsx +166 -26
  91. package/src/components/Select/SelectMenu.tsx +2 -1
  92. package/src/components/Select/SelectOption.tsx +5 -1
  93. package/src/components/Select/SelectToggle.tsx +38 -17
  94. package/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +74 -24
  95. package/src/components/Select/examples/Select.md +5 -1
  96. package/src/components/Select/selectConstants.tsx +2 -0
  97. package/src/components/Tabs/Tabs.tsx +6 -9
  98. package/src/components/TimePicker/TimePicker.tsx +112 -124
  99. package/src/components/TimePicker/examples/TimePicker.md +16 -10
  100. package/src/helpers/util.ts +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.192.7",
3
+ "version": "4.192.11",
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,16 +34,16 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.43.7",
38
- "@patternfly/react-styles": "^4.42.7",
39
- "@patternfly/react-tokens": "^4.44.7",
37
+ "@patternfly/react-icons": "^4.43.11",
38
+ "@patternfly/react-styles": "^4.42.11",
39
+ "@patternfly/react-tokens": "^4.44.11",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
43
43
  "tslib": "^2.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@patternfly/patternfly": "4.171.0",
46
+ "@patternfly/patternfly": "4.171.1",
47
47
  "@rollup/plugin-commonjs": "^21.0.0",
48
48
  "@rollup/plugin-node-resolve": "^13.0.0",
49
49
  "@rollup/plugin-replace": "^3.0.0",
@@ -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": "cf4d17a0d89c743e5e12c6d455b8a668cc985bbd"
63
+ "gitHead": "02911bcfeae9b049ecf0cdd863053d4dd1aa4e1a"
64
64
  }
@@ -9,7 +9,7 @@ interface AlertInfo {
9
9
 
10
10
  export const AsyncLiveRegionAlert: React.FunctionComponent = () => {
11
11
  const [alerts, setAlerts] = React.useState<AlertInfo[]>([]);
12
- const [isActive, setIsActive] = React.useState<boolean>(false);
12
+ const [isActive, setIsActive] = React.useState(false);
13
13
  const getUniqueId: () => number = () => new Date().getTime();
14
14
 
15
15
  const addAlert = (alertInfo: AlertInfo) => {
@@ -8,7 +8,7 @@ ouia: true
8
8
 
9
9
  import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
10
10
  import { Link } from '@reach/router';
11
- import pfIcon from './pf-logo-small.svg';
11
+ import pfLogoSm from './pf-logo-small.svg';
12
12
 
13
13
  Note: Application launcher is built on Dropdown, for extended API go to [Dropdown](/documentation/react/components/dropdown) documentation.
14
14
  To add a tooltip, use the `tooltip` prop and optionally add more tooltip props by using `tooltipProps`. For more tooltip information go to [Tooltip](/documentation/react/components/tooltip).
@@ -17,616 +17,50 @@ To add a tooltip, use the `tooltip` prop and optionally add more tooltip props b
17
17
 
18
18
  ### Basic
19
19
 
20
- ```js
21
- import React from 'react';
22
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
23
-
24
- class SimpleApplicationLauncher extends React.Component {
25
- constructor(props) {
26
- super(props);
27
- this.state = {
28
- isOpen: false
29
- };
30
- this.onToggle = isOpen => {
31
- this.setState({
32
- isOpen
33
- });
34
- };
35
- this.onSelect = event => {
36
- this.setState({
37
- isOpen: !this.state.isOpen
38
- });
39
- };
40
- }
41
-
42
- render() {
43
- const { isOpen } = this.state;
44
- const appLauncherItems = [
45
- <ApplicationLauncherItem key="application_1a" href="#">
46
- Application 1 (anchor link)
47
- </ApplicationLauncherItem>,
48
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
49
- Application 2 (button with onClick)
50
- </ApplicationLauncherItem>,
51
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
52
- Unavailable application
53
- </ApplicationLauncherItem>
54
- ];
55
- return (
56
- <ApplicationLauncher onSelect={this.onSelect} onToggle={this.onToggle} isOpen={isOpen} items={appLauncherItems} />
57
- );
58
- }
59
- }
20
+ ```ts file="./ApplicationLauncherBasic.tsx"
60
21
  ```
61
22
 
62
23
  ### Router link
63
24
 
64
- ```js
65
- import React from 'react';
66
- import { Link } from '@reach/router';
67
- import { ApplicationLauncher, ApplicationLauncherItem, ApplicationLauncherContent, Text } from '@patternfly/react-core';
68
-
69
- class SimpleApplicationLauncher extends React.Component {
70
- constructor(props) {
71
- super(props);
72
- this.state = {
73
- isOpen: false
74
- };
75
- this.onToggle = isOpen => {
76
- this.setState({
77
- isOpen
78
- });
79
- };
80
- this.onSelect = event => {
81
- this.setState({
82
- isOpen: !this.state.isOpen
83
- });
84
- };
85
- }
86
-
87
- render() {
88
- const { isOpen } = this.state;
89
- const icon = <img src={pfIcon} />;
90
- const exampleStyle = {
91
- color: 'var(--pf-c-app-launcher__menu-item--Color)',
92
- textDecoration: 'none'
93
- };
94
- const appLauncherItems = [
95
- <ApplicationLauncherItem
96
- key="router1"
97
- component={
98
- <Link to="/" style={exampleStyle}>
99
- @reach/router Link
100
- </Link>
101
- }
102
- />,
103
- <ApplicationLauncherItem
104
- key="router2"
105
- isExternal
106
- icon={icon}
107
- component={
108
- <Link to="/" style={exampleStyle}>
109
- <ApplicationLauncherContent>@reach/router Link with icon</ApplicationLauncherContent>
110
- </Link>
111
- }
112
- />,
113
- <ApplicationLauncherItem key="application_1a" href="#">
114
- Application 1 (anchor link)
115
- </ApplicationLauncherItem>,
116
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
117
- Application 2 (button with onClick)
118
- </ApplicationLauncherItem>,
119
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
120
- Unavailable application
121
- </ApplicationLauncherItem>
122
- ];
123
- return (
124
- <ApplicationLauncher onSelect={this.onSelect} onToggle={this.onToggle} isOpen={isOpen} items={appLauncherItems} />
125
- );
126
- }
127
- }
25
+ ```ts file="./ApplicationLauncherRouterLink.tsx"
128
26
  ```
129
27
 
130
28
  ### Disabled
131
29
 
132
- ```js
133
- import React from 'react';
134
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
135
-
136
- class SimpleApplicationLauncher extends React.Component {
137
- constructor(props) {
138
- super(props);
139
- this.state = {
140
- isOpen: false
141
- };
142
- this.onToggle = isOpen => {
143
- this.setState({
144
- isOpen
145
- });
146
- };
147
- this.onSelect = event => {
148
- this.setState({
149
- isOpen: !this.state.isOpen
150
- });
151
- };
152
- }
153
-
154
- render() {
155
- const { isOpen } = this.state;
156
- const appLauncherItems = [
157
- <ApplicationLauncherItem key="application_1a" href="#">
158
- Application 1 (anchor link)
159
- </ApplicationLauncherItem>,
160
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
161
- Application 2 (button with onClick)
162
- </ApplicationLauncherItem>,
163
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
164
- Unavailable application
165
- </ApplicationLauncherItem>
166
- ];
167
- return (
168
- <ApplicationLauncher
169
- onSelect={this.onSelect}
170
- onToggle={this.onToggle}
171
- isOpen={isOpen}
172
- items={appLauncherItems}
173
- isDisabled
174
- />
175
- );
176
- }
177
- }
30
+ ```ts file="./ApplicationLauncherDisabled.tsx"
178
31
  ```
179
32
 
180
33
  ### Aligned right
181
34
 
182
- ```js
183
- import React from 'react';
184
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
185
- import { DropdownPosition } from '../Dropdown';
186
-
187
- class SimpleApplicationLauncher extends React.Component {
188
- constructor(props) {
189
- super(props);
190
- this.state = {
191
- isOpen: false
192
- };
193
- this.onToggle = isOpen => {
194
- this.setState({
195
- isOpen
196
- });
197
- };
198
- this.onSelect = event => {
199
- this.setState({
200
- isOpen: !this.state.isOpen
201
- });
202
- };
203
- }
204
-
205
- render() {
206
- const { isOpen } = this.state;
207
- const appLauncherItems = [
208
- <ApplicationLauncherItem key="application_1a" href="#">
209
- Application 1 (anchor link)
210
- </ApplicationLauncherItem>,
211
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
212
- Application 2 (button with onClick)
213
- </ApplicationLauncherItem>,
214
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
215
- Unavailable application
216
- </ApplicationLauncherItem>
217
- ];
218
- const style = { marginLeft: 'calc(100% - 46px)' };
219
- return (
220
- <ApplicationLauncher
221
- onSelect={this.onSelect}
222
- onToggle={this.onToggle}
223
- isOpen={isOpen}
224
- items={appLauncherItems}
225
- position={DropdownPosition.right}
226
- style={style}
227
- />
228
- );
229
- }
230
- }
35
+ ```ts file="./ApplicationLauncherAlignRight.tsx"
231
36
  ```
232
37
 
233
38
  ### Aligned top
234
39
 
235
- ```js
236
- import React from 'react';
237
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
238
- import { DropdownDirection } from '../Dropdown';
239
-
240
- class SimpleApplicationLauncher extends React.Component {
241
- constructor(props) {
242
- super(props);
243
- this.state = {
244
- isOpen: false
245
- };
246
- this.onToggle = isOpen => {
247
- this.setState({
248
- isOpen
249
- });
250
- };
251
- this.onSelect = event => {
252
- this.setState({
253
- isOpen: !this.state.isOpen
254
- });
255
- };
256
- }
257
-
258
- render() {
259
- const { isOpen } = this.state;
260
- const appLauncherItems = [
261
- <ApplicationLauncherItem key="application_1a" href="#">
262
- Application 1 (anchor link)
263
- </ApplicationLauncherItem>,
264
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
265
- Application 2 (button with onClick)
266
- </ApplicationLauncherItem>,
267
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
268
- Unavailable application
269
- </ApplicationLauncherItem>
270
- ];
271
- return (
272
- <ApplicationLauncher
273
- onSelect={this.onSelect}
274
- onToggle={this.onToggle}
275
- isOpen={isOpen}
276
- items={appLauncherItems}
277
- direction={DropdownDirection.up}
278
- />
279
- );
280
- }
281
- }
40
+ ```ts file="./ApplicationLauncherAlignTop.tsx"
282
41
  ```
283
42
 
284
43
  ### With tooltip
285
44
 
286
- ```js
287
- import React from 'react';
288
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
289
-
290
- class TooltipApplicationLauncher extends React.Component {
291
- constructor(props) {
292
- super(props);
293
- this.state = {
294
- isOpen: false
295
- };
296
- this.onToggle = isOpen => {
297
- this.setState({
298
- isOpen
299
- });
300
- };
301
- this.onSelect = event => {
302
- this.setState({
303
- isOpen: !this.state.isOpen
304
- });
305
- };
306
- }
307
-
308
- render() {
309
- const { isOpen } = this.state;
310
- const appLauncherItems = [
311
- <ApplicationLauncherItem key="application_1b" href="#" tooltip={<div>Launch Application 1</div>}>
312
- Application 1 (anchor link)
313
- </ApplicationLauncherItem>,
314
- <ApplicationLauncherItem
315
- key="application_2b"
316
- component="button"
317
- tooltip={<div>Launch Application 2</div>}
318
- tooltipProps={{ position: 'right' }}
319
- onClick={() => alert('Clicked item 2')}
320
- >
321
- Application 2 (onClick)
322
- </ApplicationLauncherItem>,
323
- <ApplicationLauncherItem
324
- key="application_3b"
325
- component="button"
326
- tooltip={<div>Launch Application 3</div>}
327
- tooltipProps={{ position: 'bottom' }}
328
- onClick={() => alert('Clicked item 3')}
329
- >
330
- Application 3 (onClick)
331
- </ApplicationLauncherItem>
332
- ];
333
- return (
334
- <ApplicationLauncher onSelect={this.onSelect} onToggle={this.onToggle} isOpen={isOpen} items={appLauncherItems} />
335
- );
336
- }
337
- }
45
+ ```ts file="./ApplicationLauncherTooltip.tsx"
338
46
  ```
339
47
 
340
48
  ### With sections and icons
341
49
 
342
- ```js
343
- import React from 'react';
344
- import {
345
- ApplicationLauncher,
346
- ApplicationLauncherItem,
347
- ApplicationLauncherGroup,
348
- ApplicationLauncherSeparator
349
- } from '@patternfly/react-core';
350
- import pfIcon from './examples/pf-logo-small.svg';
351
-
352
- class ApplicationLauncherSections extends React.Component {
353
- constructor(props) {
354
- super(props);
355
- this.state = {
356
- isOpen: false
357
- };
358
- this.onToggle = isOpen => {
359
- this.setState({
360
- isOpen
361
- });
362
- };
363
- this.onSelect = event => {
364
- this.setState({
365
- isOpen: !this.state.isOpen
366
- });
367
- };
368
- }
369
-
370
- render() {
371
- const { isOpen } = this.state;
372
- const icon = <img src={pfIcon} />;
373
- const appLauncherItems = [
374
- <ApplicationLauncherGroup key="group 1c">
375
- <ApplicationLauncherItem key="group 1a" icon={icon}>
376
- Item without group title
377
- </ApplicationLauncherItem>
378
- <ApplicationLauncherSeparator key="separator" />
379
- </ApplicationLauncherGroup>,
380
- <ApplicationLauncherGroup label="Group 2" key="group 2c">
381
- <ApplicationLauncherItem key="group 2a" isExternal icon={icon} component="button">
382
- Group 2 button
383
- </ApplicationLauncherItem>
384
- <ApplicationLauncherItem key="group 2b" isExternal href="#" icon={icon}>
385
- Group 2 anchor link
386
- </ApplicationLauncherItem>
387
- <ApplicationLauncherSeparator key="separator" />
388
- </ApplicationLauncherGroup>,
389
- <ApplicationLauncherGroup label="Group 3" key="group 3c">
390
- <ApplicationLauncherItem key="group 3a" isExternal icon={icon} component="button">
391
- Group 3 button
392
- </ApplicationLauncherItem>
393
- <ApplicationLauncherItem key="group 3b" isExternal href="#" icon={icon}>
394
- Group 3 anchor link
395
- </ApplicationLauncherItem>
396
- </ApplicationLauncherGroup>
397
- ];
398
- return (
399
- <ApplicationLauncher
400
- onSelect={this.onSelect}
401
- onToggle={this.onToggle}
402
- isOpen={isOpen}
403
- items={appLauncherItems}
404
- isGrouped
405
- />
406
- );
407
- }
408
- }
50
+ ```ts file="./ApplicationLauncherSectionsAndIcons.tsx"
409
51
  ```
410
52
 
411
53
  ### With favorites and search
412
54
 
413
- ```js
414
- import React from 'react';
415
- import {
416
- ApplicationLauncher,
417
- ApplicationLauncherItem,
418
- ApplicationLauncherGroup,
419
- ApplicationLauncherSeparator
420
- } from '@patternfly/react-core';
421
- import pfIcon from './examples/pf-logo-small.svg';
422
-
423
- class ApplicationLauncherFavorites extends React.Component {
424
- constructor(props) {
425
- super(props);
426
- this.state = {
427
- isOpen: false,
428
- favorites: [],
429
- filteredItems: null
430
- };
431
-
432
- const icon = <img src={pfIcon} />;
433
- this.appLauncherItems = [
434
- <ApplicationLauncherGroup key="group 1c">
435
- <ApplicationLauncherItem key="group 1a" id="item-1" icon={icon}>
436
- Item without group title
437
- </ApplicationLauncherItem>
438
- <ApplicationLauncherSeparator key="separator" />
439
- </ApplicationLauncherGroup>,
440
- <ApplicationLauncherGroup label="Group 2" key="group 2c">
441
- <ApplicationLauncherItem key="group 2a" id="item-2" isExternal icon={icon} component="button">
442
- Group 2 button
443
- </ApplicationLauncherItem>
444
- <ApplicationLauncherItem key="group 2b" id="item-3" isExternal href="#" icon={icon}>
445
- Group 2 anchor link
446
- </ApplicationLauncherItem>
447
- <ApplicationLauncherSeparator key="separator" />
448
- </ApplicationLauncherGroup>,
449
- <ApplicationLauncherGroup label="Group 3" key="group 3c">
450
- <ApplicationLauncherItem key="group 3a" id="item-4" isExternal icon={icon} component="button">
451
- Group 3 button
452
- </ApplicationLauncherItem>
453
- <ApplicationLauncherItem key="group 3b" id="item-5" isExternal href="#" icon={icon}>
454
- Group 3 anchor link
455
- </ApplicationLauncherItem>
456
- </ApplicationLauncherGroup>
457
- ];
458
-
459
- this.onToggle = isOpen => {
460
- this.setState({
461
- isOpen
462
- });
463
- };
464
- this.onSelect = event => {
465
- this.setState({
466
- isOpen: !this.state.isOpen
467
- });
468
- };
469
- this.onFavorite = (itemId, isFavorite) => {
470
- if (isFavorite) {
471
- this.setState({
472
- favorites: this.state.favorites.filter(id => id !== itemId)
473
- });
474
- } else
475
- this.setState({
476
- favorites: [...this.state.favorites, itemId]
477
- });
478
- };
479
- this.onSearch = textInput => {
480
- if (textInput === '') {
481
- this.setState({
482
- filteredItems: null
483
- });
484
- } else {
485
- let filteredGroups = this.appLauncherItems
486
- .map(group => {
487
- let filteredGroup = React.cloneElement(group, {
488
- children: group.props.children.filter(item => {
489
- if (item.type === ApplicationLauncherSeparator) return item;
490
- return item.props.children.toLowerCase().includes(textInput.toLowerCase());
491
- })
492
- });
493
- if (
494
- filteredGroup.props.children.length > 0 &&
495
- filteredGroup.props.children[0].type !== ApplicationLauncherSeparator
496
- )
497
- return filteredGroup;
498
- })
499
- .filter(newGroup => newGroup);
500
-
501
- if (filteredGroups.length > 0) {
502
- let lastGroup = filteredGroups.pop();
503
- lastGroup = React.cloneElement(lastGroup, {
504
- children: lastGroup.props.children.filter(item => item.type !== ApplicationLauncherSeparator)
505
- });
506
- filteredGroups.push(lastGroup);
507
- }
508
-
509
- this.setState({
510
- filteredItems: filteredGroups
511
- });
512
- }
513
- };
514
- }
515
-
516
- render() {
517
- const { isOpen, favorites, filteredItems } = this.state;
518
- return (
519
- <ApplicationLauncher
520
- onToggle={this.onToggle}
521
- onFavorite={this.onFavorite}
522
- onSearch={this.onSearch}
523
- isOpen={isOpen}
524
- items={filteredItems || this.appLauncherItems}
525
- favorites={favorites}
526
- isGrouped
527
- />
528
- );
529
- }
530
- }
55
+ ```ts file="./ApplicationLauncherFavoritesAndSearch.tsx"
531
56
  ```
532
57
 
533
58
  ### With custom icon
534
59
 
535
- ```js
536
- import React from 'react';
537
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
538
- import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
539
-
540
- class ApplicationLauncheIcon extends React.Component {
541
- constructor(props) {
542
- super(props);
543
- this.state = {
544
- isOpen: false
545
- };
546
- this.onToggle = isOpen => {
547
- this.setState({
548
- isOpen
549
- });
550
- };
551
- this.onSelect = event => {
552
- this.setState({
553
- isOpen: !this.state.isOpen
554
- });
555
- };
556
- }
557
-
558
- render() {
559
- const { isOpen } = this.state;
560
- const appLauncherItems = [
561
- <ApplicationLauncherItem key="application_1a" href="#">
562
- Application 1 (anchor link)
563
- </ApplicationLauncherItem>,
564
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
565
- Application 2 (button with onClick)
566
- </ApplicationLauncherItem>,
567
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
568
- Unavailable application
569
- </ApplicationLauncherItem>
570
- ];
571
- return (
572
- <ApplicationLauncher
573
- onSelect={this.onSelect}
574
- onToggle={this.onToggle}
575
- isOpen={isOpen}
576
- items={appLauncherItems}
577
- toggleIcon={<HelpIcon />}
578
- />
579
- );
580
- }
581
- }
60
+ ```ts file="./ApplicationLauncherCustomIcon.tsx"
582
61
  ```
583
62
 
584
63
  ### Basic with menu appended to document body
585
64
 
586
- ```js
587
- import React from 'react';
588
- import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
589
-
590
- class ApplicationLauncherDocumentBody extends React.Component {
591
- constructor(props) {
592
- super(props);
593
- this.state = {
594
- isOpen: false
595
- };
596
- this.onToggle = isOpen => {
597
- this.setState({
598
- isOpen
599
- });
600
- };
601
- this.onSelect = event => {
602
- this.setState({
603
- isOpen: !this.state.isOpen
604
- });
605
- };
606
- }
607
-
608
- render() {
609
- const { isOpen } = this.state;
610
- const appLauncherItems = [
611
- <ApplicationLauncherItem key="application_1a" href="#">
612
- Application 1 (anchor link)
613
- </ApplicationLauncherItem>,
614
- <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
615
- Application 2 (button with onClick)
616
- </ApplicationLauncherItem>,
617
- <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
618
- Unavailable application
619
- </ApplicationLauncherItem>
620
- ];
621
- return (
622
- <ApplicationLauncher
623
- menuAppendTo={() => document.body}
624
- onSelect={this.onSelect}
625
- onToggle={this.onToggle}
626
- isOpen={isOpen}
627
- items={appLauncherItems}
628
- />
629
- );
630
- }
631
- }
65
+ ```ts file="./ApplicationLauncherDocumentBody.tsx"
632
66
  ```