@patternfly/react-core 4.192.7 → 4.192.8
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.
- package/CHANGELOG.md +11 -0
- package/dist/esm/components/Label/Label.d.ts.map +1 -1
- package/dist/esm/components/Label/Label.js +38 -25
- package/dist/esm/components/Label/Label.js.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.d.ts +4 -6
- package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.js +74 -42
- package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/js/components/Label/Label.d.ts.map +1 -1
- package/dist/js/components/Label/Label.js +38 -25
- package/dist/js/components/Label/Label.js.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.d.ts +4 -6
- package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.js +73 -41
- package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/umd/react-core.css +0 -104
- package/dist/umd/react-core.js +630 -607
- package/dist/umd/react-core.min.css +14 -118
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/Alert/examples/AlertAsyncLiveRegion.tsx +1 -1
- package/src/components/ApplicationLauncher/examples/ApplicationLauncher.md +11 -577
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherAlignRight.tsx +32 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherAlignTop.tsx +31 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherBasic.tsx +23 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherCustomIcon.tsx +32 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherDisabled.tsx +25 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherDocumentBody.tsx +31 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherFavoritesAndSearch.tsx +105 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherRouterLink.tsx +50 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherSectionsAndIcons.tsx +47 -0
- package/src/components/ApplicationLauncher/examples/ApplicationLauncherTooltip.tsx +35 -0
- package/src/components/Label/Label.tsx +58 -39
- package/src/components/Label/__tests__/Label.test.tsx +19 -1
- package/src/components/Label/__tests__/__snapshots__/Label.test.tsx.snap +109 -0
- package/src/components/Label/examples/Label.md +1 -41
- package/src/components/Label/examples/LabelEditable.tsx +57 -0
- package/src/components/TimePicker/TimePicker.tsx +112 -124
- package/src/components/TimePicker/examples/TimePicker.md +16 -10
|
@@ -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
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
!
|
|
109
|
+
editableInputRef &&
|
|
110
|
+
editableInputRef.current &&
|
|
111
|
+
!editableInputRef.current.contains(event.target as Node)
|
|
111
112
|
) {
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
<
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
+
});
|