@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
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem, DropdownPosition } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1a" href="#">
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
9
+ Application 2 (button with onClick)
10
+ </ApplicationLauncherItem>,
11
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
12
+ Unavailable application
13
+ </ApplicationLauncherItem>
14
+ ];
15
+
16
+ export const ApplicationLauncherAlignRight: React.FunctionComponent = () => {
17
+ const [isOpen, setIsOpen] = React.useState(false);
18
+
19
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
20
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
21
+
22
+ return (
23
+ <ApplicationLauncher
24
+ onSelect={onSelect}
25
+ onToggle={onToggle}
26
+ isOpen={isOpen}
27
+ items={appLauncherItems}
28
+ position={DropdownPosition.right}
29
+ style={{ marginLeft: 'calc(100% - 46px)' }}
30
+ />
31
+ );
32
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem, DropdownDirection } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1a" href="#">
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
9
+ Application 2 (button with onClick)
10
+ </ApplicationLauncherItem>,
11
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
12
+ Unavailable application
13
+ </ApplicationLauncherItem>
14
+ ];
15
+
16
+ export const ApplicationLauncherAlignTop: React.FunctionComponent = () => {
17
+ const [isOpen, setIsOpen] = React.useState(false);
18
+
19
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
20
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
21
+
22
+ return (
23
+ <ApplicationLauncher
24
+ onSelect={onSelect}
25
+ onToggle={onToggle}
26
+ isOpen={isOpen}
27
+ items={appLauncherItems}
28
+ direction={DropdownDirection.up}
29
+ />
30
+ );
31
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1a" href="#">
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
9
+ Application 2 (button with onClick)
10
+ </ApplicationLauncherItem>,
11
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
12
+ Unavailable application
13
+ </ApplicationLauncherItem>
14
+ ];
15
+
16
+ export const ApplicationLauncherBasic: React.FunctionComponent = () => {
17
+ const [isOpen, setIsOpen] = React.useState(false);
18
+
19
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
20
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
21
+
22
+ return <ApplicationLauncher onSelect={onSelect} onToggle={onToggle} isOpen={isOpen} items={appLauncherItems} />;
23
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
3
+ import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
4
+
5
+ const appLauncherItems: React.ReactElement[] = [
6
+ <ApplicationLauncherItem key="application_1a" href="#">
7
+ Application 1 (anchor link)
8
+ </ApplicationLauncherItem>,
9
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
10
+ Application 2 (button with onClick)
11
+ </ApplicationLauncherItem>,
12
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
13
+ Unavailable application
14
+ </ApplicationLauncherItem>
15
+ ];
16
+
17
+ export const ApplicationLauncherCustomIcon: React.FunctionComponent = () => {
18
+ const [isOpen, setIsOpen] = React.useState(false);
19
+
20
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
21
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
22
+
23
+ return (
24
+ <ApplicationLauncher
25
+ onSelect={onSelect}
26
+ onToggle={onToggle}
27
+ isOpen={isOpen}
28
+ items={appLauncherItems}
29
+ toggleIcon={<HelpIcon />}
30
+ />
31
+ );
32
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1a" href="#">
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
9
+ Application 2 (button with onClick)
10
+ </ApplicationLauncherItem>,
11
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
12
+ Unavailable application
13
+ </ApplicationLauncherItem>
14
+ ];
15
+
16
+ export const ApplicationLauncherDisabled: React.FunctionComponent = () => {
17
+ const [isOpen, setIsOpen] = React.useState(false);
18
+
19
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
20
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
21
+
22
+ return (
23
+ <ApplicationLauncher onSelect={onSelect} onToggle={onToggle} isOpen={isOpen} items={appLauncherItems} isDisabled />
24
+ );
25
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1a" href="#">
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
9
+ Application 2 (button with onClick)
10
+ </ApplicationLauncherItem>,
11
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
12
+ Unavailable application
13
+ </ApplicationLauncherItem>
14
+ ];
15
+
16
+ export const ApplicationLauncherDocumentBody: React.FunctionComponent = () => {
17
+ const [isOpen, setIsOpen] = React.useState(false);
18
+
19
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
20
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
21
+
22
+ return (
23
+ <ApplicationLauncher
24
+ menuAppendTo={() => document.body}
25
+ onSelect={onSelect}
26
+ onToggle={onToggle}
27
+ isOpen={isOpen}
28
+ items={appLauncherItems}
29
+ />
30
+ );
31
+ };
@@ -0,0 +1,105 @@
1
+ import React from 'react';
2
+ import {
3
+ ApplicationLauncher,
4
+ ApplicationLauncherItem,
5
+ ApplicationLauncherGroup,
6
+ ApplicationLauncherSeparator
7
+ } from '@patternfly/react-core';
8
+ import pfLogoSm from './pf-logo-small.svg';
9
+
10
+ const icon: JSX.Element = <img src={pfLogoSm} />;
11
+
12
+ const appLauncherItems: React.ReactElement[] = [
13
+ <ApplicationLauncherGroup key="group 1c">
14
+ <ApplicationLauncherItem key="group 1a" id="item-1" icon={icon}>
15
+ Item without group title
16
+ </ApplicationLauncherItem>
17
+ <ApplicationLauncherSeparator key="separator" />
18
+ </ApplicationLauncherGroup>,
19
+ <ApplicationLauncherGroup label="Group 2" key="group 2c">
20
+ <ApplicationLauncherItem key="group 2a" id="item-2" isExternal icon={icon} component="button">
21
+ Group 2 button
22
+ </ApplicationLauncherItem>
23
+ <ApplicationLauncherItem key="group 2b" id="item-3" isExternal href="#" icon={icon}>
24
+ Group 2 anchor link
25
+ </ApplicationLauncherItem>
26
+ <ApplicationLauncherSeparator key="separator" />
27
+ </ApplicationLauncherGroup>,
28
+ <ApplicationLauncherGroup label="Group 3" key="group 3c">
29
+ <ApplicationLauncherItem key="group 3a" id="item-4" isExternal icon={icon} component="button">
30
+ Group 3 button
31
+ </ApplicationLauncherItem>
32
+ <ApplicationLauncherItem key="group 3b" id="item-5" isExternal href="#" icon={icon}>
33
+ Group 3 anchor link
34
+ </ApplicationLauncherItem>
35
+ </ApplicationLauncherGroup>
36
+ ];
37
+
38
+ export const ApplicationLauncherFavoritesAndSearch: React.FunctionComponent = () => {
39
+ const [isOpen, setIsOpen] = React.useState(false);
40
+ const [favorites, setFavorites] = React.useState<string[]>([]);
41
+ const [filteredItems, setFilteredItems] = React.useState<React.ReactNode[]>(null);
42
+
43
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
44
+
45
+ const onFavorite = (itemId: string, isFavorite: boolean) => {
46
+ let updatedFavorites: string[] = [...favorites, itemId];
47
+
48
+ if (isFavorite) {
49
+ updatedFavorites = favorites.filter(id => id !== itemId);
50
+ }
51
+
52
+ setFavorites(updatedFavorites);
53
+ };
54
+
55
+ const onSearch = (textInput: string) => {
56
+ if (textInput === '') {
57
+ setFilteredItems(null);
58
+ } else {
59
+ const filteredGroups = appLauncherItems
60
+ .map((group: React.ReactElement) => {
61
+ const filteredGroup = React.cloneElement(group, {
62
+ children: group.props.children.filter((item: React.ReactElement) => {
63
+ if (item.type === ApplicationLauncherSeparator) {
64
+ return item;
65
+ }
66
+
67
+ return item.props.children.toLowerCase().includes(textInput.toLowerCase());
68
+ })
69
+ });
70
+
71
+ if (
72
+ filteredGroup.props.children.length > 0 &&
73
+ filteredGroup.props.children[0].type !== ApplicationLauncherSeparator
74
+ ) {
75
+ return filteredGroup;
76
+ }
77
+ })
78
+ .filter(newGroup => newGroup);
79
+
80
+ if (filteredGroups.length > 0) {
81
+ let lastGroup = filteredGroups.pop();
82
+
83
+ lastGroup = React.cloneElement(lastGroup, {
84
+ children: lastGroup.props.children.filter(item => item.type !== ApplicationLauncherSeparator)
85
+ });
86
+
87
+ filteredGroups.push(lastGroup);
88
+ }
89
+
90
+ setFilteredItems(filteredGroups);
91
+ }
92
+ };
93
+
94
+ return (
95
+ <ApplicationLauncher
96
+ onToggle={onToggle}
97
+ onFavorite={onFavorite}
98
+ onSearch={onSearch}
99
+ isOpen={isOpen}
100
+ items={filteredItems || appLauncherItems}
101
+ favorites={favorites}
102
+ isGrouped
103
+ />
104
+ );
105
+ };
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import { Link } from '@reach/router';
3
+ import { ApplicationLauncher, ApplicationLauncherItem, ApplicationLauncherContent } from '@patternfly/react-core';
4
+ import pfLogoSm from './pf-logo-small.svg';
5
+
6
+ const icon: JSX.Element = <img src={pfLogoSm} />;
7
+
8
+ const linkStyle: React.CSSProperties = {
9
+ color: 'var(--pf-c-app-launcher__menu-item--Color)',
10
+ textDecoration: 'none'
11
+ };
12
+
13
+ const appLauncherItems: React.ReactElement[] = [
14
+ <ApplicationLauncherItem
15
+ key="router1"
16
+ component={
17
+ <Link to="/" style={linkStyle}>
18
+ @reach/router Link
19
+ </Link>
20
+ }
21
+ />,
22
+ <ApplicationLauncherItem
23
+ key="router2"
24
+ isExternal
25
+ icon={icon}
26
+ component={
27
+ <Link to="/" style={linkStyle}>
28
+ <ApplicationLauncherContent>@reach/router Link with icon</ApplicationLauncherContent>
29
+ </Link>
30
+ }
31
+ />,
32
+ <ApplicationLauncherItem key="application_1a" href="#">
33
+ Application 1 (anchor link)
34
+ </ApplicationLauncherItem>,
35
+ <ApplicationLauncherItem key="application_2a" component="button" onClick={() => alert('Clicked item 2')}>
36
+ Application 2 (button with onClick)
37
+ </ApplicationLauncherItem>,
38
+ <ApplicationLauncherItem key="disabled_application_4a" isDisabled>
39
+ Unavailable application
40
+ </ApplicationLauncherItem>
41
+ ];
42
+
43
+ export const ApplicationLauncherRouterLink: React.FunctionComponent = () => {
44
+ const [isOpen, setIsOpen] = React.useState(false);
45
+
46
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
47
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
48
+
49
+ return <ApplicationLauncher onSelect={onSelect} onToggle={onToggle} isOpen={isOpen} items={appLauncherItems} />;
50
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import {
3
+ ApplicationLauncher,
4
+ ApplicationLauncherItem,
5
+ ApplicationLauncherGroup,
6
+ ApplicationLauncherSeparator
7
+ } from '@patternfly/react-core';
8
+ import pfLogoSm from './pf-logo-small.svg';
9
+
10
+ const icon = <img src={pfLogoSm} />;
11
+
12
+ const appLauncherItems: React.ReactElement[] = [
13
+ <ApplicationLauncherGroup key="group 1c">
14
+ <ApplicationLauncherItem key="group 1a" icon={icon}>
15
+ Item without group title
16
+ </ApplicationLauncherItem>
17
+ <ApplicationLauncherSeparator key="separator" />
18
+ </ApplicationLauncherGroup>,
19
+ <ApplicationLauncherGroup label="Group 2" key="group 2c">
20
+ <ApplicationLauncherItem key="group 2a" isExternal icon={icon} component="button">
21
+ Group 2 button
22
+ </ApplicationLauncherItem>
23
+ <ApplicationLauncherItem key="group 2b" isExternal href="#" icon={icon}>
24
+ Group 2 anchor link
25
+ </ApplicationLauncherItem>
26
+ <ApplicationLauncherSeparator key="separator" />
27
+ </ApplicationLauncherGroup>,
28
+ <ApplicationLauncherGroup label="Group 3" key="group 3c">
29
+ <ApplicationLauncherItem key="group 3a" isExternal icon={icon} component="button">
30
+ Group 3 button
31
+ </ApplicationLauncherItem>
32
+ <ApplicationLauncherItem key="group 3b" isExternal href="#" icon={icon}>
33
+ Group 3 anchor link
34
+ </ApplicationLauncherItem>
35
+ </ApplicationLauncherGroup>
36
+ ];
37
+
38
+ export const ApplicationLauncherSectionsAndIcons: React.FunctionComponent = () => {
39
+ const [isOpen, setIsOpen] = React.useState(false);
40
+
41
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
42
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
43
+
44
+ return (
45
+ <ApplicationLauncher onSelect={onSelect} onToggle={onToggle} isOpen={isOpen} items={appLauncherItems} isGrouped />
46
+ );
47
+ };
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
3
+
4
+ const appLauncherItems: React.ReactElement[] = [
5
+ <ApplicationLauncherItem key="application_1b" href="#" tooltip={<div>Launch Application 1</div>}>
6
+ Application 1 (anchor link)
7
+ </ApplicationLauncherItem>,
8
+ <ApplicationLauncherItem
9
+ key="application_2b"
10
+ component="button"
11
+ tooltip={<div>Launch Application 2</div>}
12
+ tooltipProps={{ position: 'right' }}
13
+ onClick={() => alert('Clicked item 2')}
14
+ >
15
+ Application 2 (onClick)
16
+ </ApplicationLauncherItem>,
17
+ <ApplicationLauncherItem
18
+ key="application_3b"
19
+ component="button"
20
+ tooltip={<div>Launch Application 3</div>}
21
+ tooltipProps={{ position: 'bottom' }}
22
+ onClick={() => alert('Clicked item 3')}
23
+ >
24
+ Application 3 (onClick)
25
+ </ApplicationLauncherItem>
26
+ ];
27
+
28
+ export const ApplicationLauncherTooltip: React.FunctionComponent = () => {
29
+ const [isOpen, setIsOpen] = React.useState(false);
30
+
31
+ const onToggle = (isOpen: boolean) => setIsOpen(isOpen);
32
+ const onSelect = (_event: any) => setIsOpen(prevIsOpen => !prevIsOpen);
33
+
34
+ return <ApplicationLauncher onSelect={onSelect} onToggle={onToggle} isOpen={isOpen} items={appLauncherItems} />;
35
+ };
@@ -2,7 +2,6 @@ import * as React from 'react';
2
2
  import { useState } from 'react';
3
3
  import styles from '@patternfly/react-styles/css/components/Label/label';
4
4
  import labelGrpStyles from '@patternfly/react-styles/css/components/LabelGroup/label-group';
5
- import inlineEditStyles from '@patternfly/react-styles/css/components/InlineEdit/inline-edit';
6
5
  import { Button } from '../Button';
7
6
  import { Tooltip } from '../Tooltip';
8
7
  import { css } from '@patternfly/react-styles';
@@ -91,7 +90,9 @@ export const Label: React.FunctionComponent<LabelProps> = ({
91
90
  ...props
92
91
  }: LabelProps) => {
93
92
  const [isEditableActive, setIsEditableActive] = useState(false);
94
- const editableDivRef = React.createRef<HTMLDivElement>();
93
+ const [currValue, setCurrValue] = useState(children);
94
+ const editableButtonRef = React.useRef<HTMLButtonElement>();
95
+ const editableInputRef = React.useRef<HTMLInputElement>();
95
96
 
96
97
  React.useEffect(() => {
97
98
  document.addEventListener('click', onDocClick);
@@ -105,34 +106,45 @@ export const Label: React.FunctionComponent<LabelProps> = ({
105
106
  const onDocClick = (event: MouseEvent) => {
106
107
  if (
107
108
  isEditableActive &&
108
- editableDivRef &&
109
- editableDivRef.current &&
110
- !editableDivRef.current.contains(event.target as Node)
109
+ editableInputRef &&
110
+ editableInputRef.current &&
111
+ !editableInputRef.current.contains(event.target as Node)
111
112
  ) {
112
- onEditComplete && onEditComplete(editableDivRef.current.textContent);
113
+ if (editableInputRef.current.value) {
114
+ onEditComplete && onEditComplete(editableInputRef.current.value);
115
+ }
113
116
  setIsEditableActive(false);
114
117
  }
115
118
  };
116
119
 
117
120
  const onKeyDown = (event: KeyboardEvent) => {
118
121
  const key = event.key;
119
-
120
- if (!editableDivRef || !editableDivRef.current || !editableDivRef.current.contains(event.target as Node)) {
122
+ if (
123
+ (!isEditableActive &&
124
+ (!editableButtonRef ||
125
+ !editableButtonRef.current ||
126
+ !editableButtonRef.current.contains(event.target as Node))) ||
127
+ (isEditableActive &&
128
+ (!editableInputRef || !editableInputRef.current || !editableInputRef.current.contains(event.target as Node)))
129
+ ) {
121
130
  return;
122
131
  }
123
-
124
132
  if (isEditableActive && (key === 'Enter' || key === 'Tab')) {
125
133
  event.preventDefault();
126
134
  event.stopImmediatePropagation();
127
- onEditComplete && onEditComplete(editableDivRef.current.textContent);
135
+ if (editableInputRef.current.value) {
136
+ onEditComplete && onEditComplete(editableInputRef.current.value);
137
+ }
128
138
  setIsEditableActive(false);
129
139
  }
130
140
  if (isEditableActive && key === 'Escape') {
131
141
  event.preventDefault();
132
142
  event.stopImmediatePropagation();
133
143
  // Reset div text to initial children prop - pre-edit
134
- editableDivRef.current.textContent = children as string;
135
- onEditCancel && onEditCancel(children as string);
144
+ if (editableInputRef.current.value) {
145
+ editableInputRef.current.value = children as string;
146
+ onEditCancel && onEditCancel(children as string);
147
+ }
136
148
  setIsEditableActive(false);
137
149
  }
138
150
  if (!isEditableActive && key === 'Enter') {
@@ -185,23 +197,29 @@ export const Label: React.FunctionComponent<LabelProps> = ({
185
197
  </React.Fragment>
186
198
  );
187
199
 
200
+ React.useEffect(() => {
201
+ if (isEditableActive && editableInputRef) {
202
+ editableInputRef.current && editableInputRef.current.focus();
203
+ }
204
+ }, [editableInputRef, isEditableActive]);
205
+
206
+ const updateVal = () => {
207
+ setCurrValue(editableInputRef.current.value);
208
+ };
209
+
188
210
  if (isEditable) {
189
211
  content = (
190
- <React.Fragment>
191
- <div className={css(inlineEditStyles.inlineEdit)}>
192
- <div
193
- tabIndex={0}
194
- ref={editableDivRef}
195
- className={css(inlineEditStyles.inlineEditEditableText)}
196
- role="textbox"
197
- {...(isEditableActive && { contentEditable: true })}
198
- suppressContentEditableWarning
199
- {...editableProps}
200
- >
201
- {children}
202
- </div>
203
- </div>
204
- </React.Fragment>
212
+ <button
213
+ ref={editableButtonRef}
214
+ className={css(styles.labelEditableText)}
215
+ onClick={e => {
216
+ setIsEditableActive(true);
217
+ e.stopPropagation();
218
+ }}
219
+ {...editableProps}
220
+ >
221
+ {children}
222
+ </button>
205
223
  );
206
224
  }
207
225
 
@@ -245,19 +263,20 @@ export const Label: React.FunctionComponent<LabelProps> = ({
245
263
  isEditableActive && styles.modifiers.editableActive,
246
264
  className
247
265
  )}
248
- {...(isEditable && {
249
- onClick: (evt: MouseEvent) => {
250
- const isEvtFromButton = (evt.target as HTMLElement).closest('button');
251
- if (isEvtFromButton !== null) {
252
- return;
253
- }
254
- setIsEditableActive(true);
255
- editableDivRef.current.focus();
256
- }
257
- })}
258
266
  >
259
- {labelComponentChild}
260
- {onClose && button}
267
+ {!isEditableActive && labelComponentChild}
268
+ {!isEditableActive && onClose && button}
269
+ {isEditableActive && (
270
+ <input
271
+ className={css(styles.labelEditableText)}
272
+ type="text"
273
+ id="editable-input"
274
+ ref={editableInputRef}
275
+ value={currValue}
276
+ onChange={updateVal}
277
+ {...editableProps}
278
+ />
279
+ )}
261
280
  </LabelComponent>
262
281
  );
263
282
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { shallow } from 'enzyme';
2
+ import { shallow, mount } from 'enzyme';
3
3
  import { Label } from '../Label';
4
4
 
5
5
  test('label', () => {
@@ -7,6 +7,8 @@ test('label', () => {
7
7
  expect(view).toMatchSnapshot();
8
8
  const outline = shallow(<Label variant="outline">Something</Label>);
9
9
  expect(outline).toMatchSnapshot();
10
+ const compact = shallow(<Label isCompact>Something</Label>);
11
+ expect(compact).toMatchSnapshot();
10
12
  });
11
13
 
12
14
  test('label with href', () => {
@@ -63,3 +65,19 @@ test('label with truncation', () => {
63
65
  const view = shallow(<Label isTruncated>Something very very very very very long that should be truncated</Label>);
64
66
  expect(view).toMatchSnapshot();
65
67
  });
68
+
69
+ test('editable label', () => {
70
+ const view = mount(
71
+ <Label onClose={jest.fn()}
72
+ onEditCancel={jest.fn()}
73
+ onEditComplete={jest.fn()}
74
+ isEditable>Something</Label>);
75
+ const button = view.find('button.pf-c-label__editable-text');
76
+ expect(button.length).toBe(1);
77
+ expect(view).toMatchSnapshot();
78
+
79
+ button.simulate('click');
80
+ const clickedButton = view.find('button.pf-c-label__editable-text');
81
+ expect(clickedButton.length).toBe(0);
82
+ expect(view).toMatchSnapshot();
83
+ });