@patternfly/react-core 4.179.1 → 4.181.1
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 +38 -0
- package/dist/esm/components/DualListSelector/DualListSelectorTree.d.ts +1 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTree.d.ts.map +1 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTree.js +2 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTree.js.map +1 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTreeItem.d.ts +3 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTreeItem.d.ts.map +1 -1
- package/dist/esm/components/DualListSelector/DualListSelectorTreeItem.js +24 -2
- package/dist/esm/components/DualListSelector/DualListSelectorTreeItem.js.map +1 -1
- package/dist/esm/components/Popover/Popover.d.ts +7 -1
- package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
- package/dist/esm/components/Popover/Popover.js +11 -4
- package/dist/esm/components/Popover/Popover.js.map +1 -1
- package/dist/esm/components/Popover/PopoverBody.d.ts +5 -3
- package/dist/esm/components/Popover/PopoverBody.d.ts.map +1 -1
- package/dist/esm/components/Popover/PopoverBody.js +2 -2
- package/dist/esm/components/Popover/PopoverBody.js.map +1 -1
- package/dist/esm/components/Popover/PopoverFooter.d.ts +2 -2
- package/dist/esm/components/Popover/PopoverFooter.d.ts.map +1 -1
- package/dist/esm/components/Popover/PopoverFooter.js.map +1 -1
- package/dist/esm/components/Popover/PopoverHeader.d.ts +15 -5
- package/dist/esm/components/Popover/PopoverHeader.d.ts.map +1 -1
- package/dist/esm/components/Popover/PopoverHeader.js +11 -3
- package/dist/esm/components/Popover/PopoverHeader.js.map +1 -1
- package/dist/esm/components/Popover/PopoverHeaderIcon.d.ts +9 -0
- package/dist/esm/components/Popover/PopoverHeaderIcon.d.ts.map +1 -0
- package/dist/esm/components/Popover/PopoverHeaderIcon.js +10 -0
- package/dist/esm/components/Popover/PopoverHeaderIcon.js.map +1 -0
- package/dist/esm/components/Popover/PopoverHeaderText.d.ts +9 -0
- package/dist/esm/components/Popover/PopoverHeaderText.d.ts.map +1 -0
- package/dist/esm/components/Popover/PopoverHeaderText.js +10 -0
- package/dist/esm/components/Popover/PopoverHeaderText.js.map +1 -0
- package/dist/js/components/DualListSelector/DualListSelectorTree.d.ts +1 -1
- package/dist/js/components/DualListSelector/DualListSelectorTree.d.ts.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelectorTree.js +2 -1
- package/dist/js/components/DualListSelector/DualListSelectorTree.js.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelectorTreeItem.d.ts +3 -1
- package/dist/js/components/DualListSelector/DualListSelectorTreeItem.d.ts.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelectorTreeItem.js +24 -3
- package/dist/js/components/DualListSelector/DualListSelectorTreeItem.js.map +1 -1
- package/dist/js/components/Popover/Popover.d.ts +7 -1
- package/dist/js/components/Popover/Popover.d.ts.map +1 -1
- package/dist/js/components/Popover/Popover.js +11 -4
- package/dist/js/components/Popover/Popover.js.map +1 -1
- package/dist/js/components/Popover/PopoverBody.d.ts +5 -3
- package/dist/js/components/Popover/PopoverBody.d.ts.map +1 -1
- package/dist/js/components/Popover/PopoverBody.js +2 -2
- package/dist/js/components/Popover/PopoverBody.js.map +1 -1
- package/dist/js/components/Popover/PopoverFooter.d.ts +2 -2
- package/dist/js/components/Popover/PopoverFooter.d.ts.map +1 -1
- package/dist/js/components/Popover/PopoverFooter.js.map +1 -1
- package/dist/js/components/Popover/PopoverHeader.d.ts +15 -5
- package/dist/js/components/Popover/PopoverHeader.d.ts.map +1 -1
- package/dist/js/components/Popover/PopoverHeader.js +11 -3
- package/dist/js/components/Popover/PopoverHeader.js.map +1 -1
- package/dist/js/components/Popover/PopoverHeaderIcon.d.ts +9 -0
- package/dist/js/components/Popover/PopoverHeaderIcon.d.ts.map +1 -0
- package/dist/js/components/Popover/PopoverHeaderIcon.js +14 -0
- package/dist/js/components/Popover/PopoverHeaderIcon.js.map +1 -0
- package/dist/js/components/Popover/PopoverHeaderText.d.ts +9 -0
- package/dist/js/components/Popover/PopoverHeaderText.d.ts.map +1 -0
- package/dist/js/components/Popover/PopoverHeaderText.js +14 -0
- package/dist/js/components/Popover/PopoverHeaderText.js.map +1 -0
- package/dist/umd/react-core.css +12 -12
- package/dist/umd/react-core.js +58 -11
- package/dist/umd/react-core.min.css +3587 -3587
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +6 -6
- package/src/components/DualListSelector/DualListSelectorTree.tsx +4 -2
- package/src/components/DualListSelector/DualListSelectorTreeItem.tsx +32 -1
- package/src/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap +3 -0
- package/src/components/DualListSelector/examples/ComposableTree.tsx +345 -0
- package/src/components/DualListSelector/examples/DualListSelector.md +5 -1
- package/src/components/Popover/Popover.tsx +27 -2
- package/src/components/Popover/PopoverBody.tsx +11 -8
- package/src/components/Popover/PopoverFooter.tsx +7 -7
- package/src/components/Popover/PopoverHeader.tsx +45 -17
- package/src/components/Popover/PopoverHeaderIcon.tsx +21 -0
- package/src/components/Popover/PopoverHeaderText.tsx +21 -0
- package/src/components/Popover/__tests__/Generated/__snapshots__/PopoverHeader.test.tsx.snap +9 -3
- package/src/components/Popover/__tests__/__snapshots__/Popover.test.tsx.snap +12 -0
- package/src/components/Popover/examples/Popover.md +83 -7
- package/src/components/Toolbar/examples/Toolbar.md +1 -1
- package/src/demos/BackToTop.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.181.1",
|
|
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.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.32.1",
|
|
38
|
+
"@patternfly/react-styles": "^4.31.1",
|
|
39
|
+
"@patternfly/react-tokens": "^4.33.1",
|
|
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.164.
|
|
46
|
+
"@patternfly/patternfly": "4.164.2",
|
|
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": "
|
|
63
|
+
"gitHead": "bc3dc77b8d33e06e58b2273bc85c2b87e6bda3b5"
|
|
64
64
|
}
|
|
@@ -37,7 +37,7 @@ export interface DualListSelectorTreeItemData {
|
|
|
37
37
|
|
|
38
38
|
export interface DualListSelectorTreeProps {
|
|
39
39
|
/** Data of the tree view */
|
|
40
|
-
data: DualListSelectorTreeItemData[];
|
|
40
|
+
data: DualListSelectorTreeItemData[] | (() => DualListSelectorTreeItemData[]);
|
|
41
41
|
/** ID of the tree view */
|
|
42
42
|
id?: string;
|
|
43
43
|
/** @hide Flag indicating if the list is nested */
|
|
@@ -64,7 +64,8 @@ export const DualListSelectorTree: React.FunctionComponent<DualListSelectorTreeP
|
|
|
64
64
|
isDisabled = false,
|
|
65
65
|
...props
|
|
66
66
|
}: DualListSelectorTreeProps) => {
|
|
67
|
-
const
|
|
67
|
+
const dataToRender = typeof data === 'function' ? data() : data;
|
|
68
|
+
const tree = dataToRender.map(item => (
|
|
68
69
|
<DualListSelectorTreeItem
|
|
69
70
|
key={item.id}
|
|
70
71
|
text={item.text}
|
|
@@ -77,6 +78,7 @@ export const DualListSelectorTree: React.FunctionComponent<DualListSelectorTreeP
|
|
|
77
78
|
badgeProps={item.badgeProps}
|
|
78
79
|
itemData={item}
|
|
79
80
|
isDisabled={isDisabled}
|
|
81
|
+
useMemo={true}
|
|
80
82
|
{...(item.children && {
|
|
81
83
|
children: (
|
|
82
84
|
<DualListSelectorTree
|
|
@@ -36,9 +36,11 @@ export interface DualListSelectorTreeItemProps extends React.HTMLProps<HTMLLIEle
|
|
|
36
36
|
itemData?: DualListSelectorTreeItemData;
|
|
37
37
|
/** Flag indicating whether the component is disabled. */
|
|
38
38
|
isDisabled?: boolean;
|
|
39
|
+
/** Flag indicating the DualListSelector tree should utilize memoization to help render large data sets. */
|
|
40
|
+
useMemo?: boolean;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
const DualListSelectorTreeItemBase: React.FunctionComponent<DualListSelectorTreeItemProps> = ({
|
|
42
44
|
onOptionCheck,
|
|
43
45
|
children,
|
|
44
46
|
className,
|
|
@@ -51,12 +53,18 @@ export const DualListSelectorTreeItem: React.FunctionComponent<DualListSelectorT
|
|
|
51
53
|
badgeProps,
|
|
52
54
|
itemData,
|
|
53
55
|
isDisabled = false,
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
|
+
useMemo,
|
|
54
58
|
...props
|
|
55
59
|
}: DualListSelectorTreeItemProps) => {
|
|
56
60
|
const ref = React.useRef(null);
|
|
57
61
|
const [isExpanded, setIsExpanded] = React.useState(defaultExpanded || false);
|
|
58
62
|
const { setFocusedOption } = React.useContext(DualListSelectorListContext);
|
|
59
63
|
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
setIsExpanded(defaultExpanded);
|
|
66
|
+
}, [defaultExpanded]);
|
|
67
|
+
|
|
60
68
|
return (
|
|
61
69
|
<li
|
|
62
70
|
className={css(
|
|
@@ -150,4 +158,27 @@ export const DualListSelectorTreeItem: React.FunctionComponent<DualListSelectorT
|
|
|
150
158
|
</li>
|
|
151
159
|
);
|
|
152
160
|
};
|
|
161
|
+
|
|
162
|
+
export const DualListSelectorTreeItem = React.memo(DualListSelectorTreeItemBase, (prevProps, nextProps) => {
|
|
163
|
+
if (!nextProps.useMemo) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
prevProps.className !== nextProps.className ||
|
|
169
|
+
prevProps.text !== nextProps.text ||
|
|
170
|
+
prevProps.id !== nextProps.id ||
|
|
171
|
+
prevProps.defaultExpanded !== nextProps.defaultExpanded ||
|
|
172
|
+
prevProps.checkProps !== nextProps.checkProps ||
|
|
173
|
+
prevProps.hasBadge !== nextProps.hasBadge ||
|
|
174
|
+
prevProps.badgeProps !== nextProps.badgeProps ||
|
|
175
|
+
prevProps.isChecked !== nextProps.isChecked ||
|
|
176
|
+
prevProps.itemData !== nextProps.itemData
|
|
177
|
+
) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return true;
|
|
182
|
+
});
|
|
183
|
+
|
|
153
184
|
DualListSelectorTreeItem.displayName = 'DualListSelectorTreeItem';
|
package/src/components/DualListSelector/__tests__/__snapshots__/DualListSelector.test.tsx.snap
CHANGED
|
@@ -4487,6 +4487,7 @@ exports[`DualListSelector with tree 1`] = `
|
|
|
4487
4487
|
key="O1"
|
|
4488
4488
|
onOptionCheck={[Function]}
|
|
4489
4489
|
text="Opt1"
|
|
4490
|
+
useMemo={true}
|
|
4490
4491
|
>
|
|
4491
4492
|
<li
|
|
4492
4493
|
aria-expanded="true"
|
|
@@ -4598,6 +4599,7 @@ exports[`DualListSelector with tree 1`] = `
|
|
|
4598
4599
|
key="O3"
|
|
4599
4600
|
onOptionCheck={[Function]}
|
|
4600
4601
|
text="Opt3"
|
|
4602
|
+
useMemo={true}
|
|
4601
4603
|
>
|
|
4602
4604
|
<li
|
|
4603
4605
|
aria-selected={false}
|
|
@@ -4658,6 +4660,7 @@ exports[`DualListSelector with tree 1`] = `
|
|
|
4658
4660
|
key="O2"
|
|
4659
4661
|
onOptionCheck={[Function]}
|
|
4660
4662
|
text="Opt2"
|
|
4663
|
+
useMemo={true}
|
|
4661
4664
|
>
|
|
4662
4665
|
<li
|
|
4663
4666
|
aria-selected={false}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
DualListSelector,
|
|
4
|
+
DualListSelectorPane,
|
|
5
|
+
DualListSelectorList,
|
|
6
|
+
DualListSelectorControlsWrapper,
|
|
7
|
+
DualListSelectorControl,
|
|
8
|
+
DualListSelectorTree,
|
|
9
|
+
DualListSelectorTreeItemData,
|
|
10
|
+
SearchInput
|
|
11
|
+
} from '@patternfly/react-core';
|
|
12
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
13
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
14
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
15
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
|
+
|
|
17
|
+
interface FoodNode {
|
|
18
|
+
id: string;
|
|
19
|
+
text: string;
|
|
20
|
+
children?: FoodNode[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ExampleProps {
|
|
24
|
+
data: FoodNode[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const ComposableDualListSelectorTree: React.FunctionComponent<ExampleProps> = ({ data }: ExampleProps) => {
|
|
28
|
+
const [checkedLeafIds, setCheckedLeafIds] = React.useState<string[]>([]);
|
|
29
|
+
const [chosenLeafIds, setChosenLeafIds] = React.useState<string[]>(['beans', 'beef', 'chicken', 'tofu']);
|
|
30
|
+
const [chosenFilter, setChosenFilter] = React.useState<string>('');
|
|
31
|
+
const [availableFilter, setAvailableFilter] = React.useState<string>('');
|
|
32
|
+
let hiddenChosen: string[] = [];
|
|
33
|
+
let hiddenAvailable: string[] = [];
|
|
34
|
+
|
|
35
|
+
// helper function to build memoized lists
|
|
36
|
+
const buildTextById = (node: FoodNode): { [key: string]: string } => {
|
|
37
|
+
let textById = {};
|
|
38
|
+
if (!node) {
|
|
39
|
+
return textById;
|
|
40
|
+
}
|
|
41
|
+
textById[node.id] = node.text;
|
|
42
|
+
if (node.children) {
|
|
43
|
+
node.children.forEach(child => {
|
|
44
|
+
textById = { ...textById, ...buildTextById(child) };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return textById;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// helper function to build memoized lists
|
|
51
|
+
const getDescendantLeafIds = (node: FoodNode): string[] => {
|
|
52
|
+
if (!node.children || !node.children.length) {
|
|
53
|
+
return [node.id];
|
|
54
|
+
} else {
|
|
55
|
+
let childrenIds = [];
|
|
56
|
+
node.children.forEach(child => {
|
|
57
|
+
childrenIds = [...childrenIds, ...getDescendantLeafIds(child)];
|
|
58
|
+
});
|
|
59
|
+
return childrenIds;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// helper function to build memoized lists
|
|
64
|
+
const getLeavesById = (node: FoodNode): { [key: string]: string[] } => {
|
|
65
|
+
let leavesById = {};
|
|
66
|
+
if (!node.children || !node.children.length) {
|
|
67
|
+
leavesById[node.id] = [node.id];
|
|
68
|
+
} else {
|
|
69
|
+
node.children.forEach(child => {
|
|
70
|
+
leavesById[node.id] = getDescendantLeafIds(node);
|
|
71
|
+
leavesById = { ...leavesById, ...getLeavesById(child) };
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return leavesById;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Builds a map of child leaf nodes by node id - memoized so that it only rebuilds the list if the data changes.
|
|
78
|
+
const { memoizedLeavesById, memoizedAllLeaves, memoizedNodeText } = React.useMemo(() => {
|
|
79
|
+
let leavesById = {};
|
|
80
|
+
let allLeaves = [];
|
|
81
|
+
let nodeTexts = {};
|
|
82
|
+
data.forEach(foodNode => {
|
|
83
|
+
nodeTexts = { ...nodeTexts, ...buildTextById(foodNode) };
|
|
84
|
+
leavesById = { ...leavesById, ...getLeavesById(foodNode) };
|
|
85
|
+
allLeaves = [...allLeaves, ...getDescendantLeafIds(foodNode)];
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
memoizedLeavesById: leavesById,
|
|
89
|
+
memoizedAllLeaves: allLeaves,
|
|
90
|
+
memoizedNodeText: nodeTexts
|
|
91
|
+
};
|
|
92
|
+
}, [data]);
|
|
93
|
+
|
|
94
|
+
const moveChecked = (toChosen: boolean) => {
|
|
95
|
+
setChosenLeafIds(
|
|
96
|
+
prevChosenIds =>
|
|
97
|
+
toChosen
|
|
98
|
+
? [...prevChosenIds, ...checkedLeafIds] // add checked ids to chosen list
|
|
99
|
+
: [...prevChosenIds.filter(x => !checkedLeafIds.includes(x))] // remove checked ids from chosen list
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// uncheck checked ids that just moved
|
|
103
|
+
setCheckedLeafIds(prevChecked =>
|
|
104
|
+
toChosen
|
|
105
|
+
? [...prevChecked.filter(x => chosenLeafIds.includes(x))]
|
|
106
|
+
: [...prevChecked.filter(x => !chosenLeafIds.includes(x))]
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const moveAll = (toChosen: boolean) => {
|
|
111
|
+
if (toChosen) {
|
|
112
|
+
setChosenLeafIds(memoizedAllLeaves);
|
|
113
|
+
} else {
|
|
114
|
+
setChosenLeafIds([]);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const areAllDescendantsSelected = (node: FoodNode, isChosen: boolean) =>
|
|
119
|
+
memoizedLeavesById[node.id].every(
|
|
120
|
+
id => checkedLeafIds.includes(id) && (isChosen ? chosenLeafIds.includes(id) : !chosenLeafIds.includes(id))
|
|
121
|
+
);
|
|
122
|
+
const areSomeDescendantsSelected = (node: FoodNode, isChosen: boolean) =>
|
|
123
|
+
memoizedLeavesById[node.id].some(
|
|
124
|
+
id => checkedLeafIds.includes(id) && (isChosen ? chosenLeafIds.includes(id) : !chosenLeafIds.includes(id))
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const isNodeChecked = (node: FoodNode, isChosen: boolean) => {
|
|
128
|
+
if (areAllDescendantsSelected(node, isChosen)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (areSomeDescendantsSelected(node, isChosen)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const onOptionCheck = (
|
|
138
|
+
event: React.MouseEvent | React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent,
|
|
139
|
+
isChecked: boolean,
|
|
140
|
+
node: DualListSelectorTreeItemData,
|
|
141
|
+
isChosen: boolean
|
|
142
|
+
) => {
|
|
143
|
+
const nodeIdsToCheck = memoizedLeavesById[node.id].filter(id =>
|
|
144
|
+
isChosen
|
|
145
|
+
? chosenLeafIds.includes(id) && !hiddenChosen.includes(id)
|
|
146
|
+
: !chosenLeafIds.includes(id) && !hiddenAvailable.includes(id)
|
|
147
|
+
);
|
|
148
|
+
if (isChosen) {
|
|
149
|
+
hiddenChosen = [];
|
|
150
|
+
} else {
|
|
151
|
+
hiddenAvailable = [];
|
|
152
|
+
}
|
|
153
|
+
setCheckedLeafIds(prevChecked => {
|
|
154
|
+
const otherCheckedNodeNames = prevChecked.filter(id => !nodeIdsToCheck.includes(id));
|
|
155
|
+
return !isChecked ? otherCheckedNodeNames : [...otherCheckedNodeNames, ...nodeIdsToCheck];
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// builds a search input - used in each dual list selector pane
|
|
160
|
+
const buildSearchInput = (isChosen: boolean) => {
|
|
161
|
+
const onChange = value => (isChosen ? setChosenFilter(value) : setAvailableFilter(value));
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<SearchInput value={isChosen ? chosenFilter : availableFilter} onChange={onChange} onClear={() => onChange('')} />
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Builds the DualListSelectorTreeItems from the FoodNodes
|
|
169
|
+
const buildOptions = (
|
|
170
|
+
isChosen: boolean,
|
|
171
|
+
[node, ...remainingNodes]: FoodNode[],
|
|
172
|
+
hasParentMatch: boolean
|
|
173
|
+
): DualListSelectorTreeItemData[] => {
|
|
174
|
+
if (!node) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const isChecked = isNodeChecked(node, isChosen);
|
|
179
|
+
|
|
180
|
+
const filterValue = isChosen ? chosenFilter : availableFilter;
|
|
181
|
+
const descendentLeafIds = memoizedLeavesById[node.id];
|
|
182
|
+
const descendentsOnThisPane = isChosen
|
|
183
|
+
? descendentLeafIds.filter(id => chosenLeafIds.includes(id))
|
|
184
|
+
: descendentLeafIds.filter(id => !chosenLeafIds.includes(id));
|
|
185
|
+
|
|
186
|
+
const hasMatchingChildren =
|
|
187
|
+
filterValue && descendentsOnThisPane.some(id => memoizedNodeText[id].includes(filterValue));
|
|
188
|
+
const isFilterMatch = filterValue && node.text.includes(filterValue) && descendentsOnThisPane.length > 0;
|
|
189
|
+
|
|
190
|
+
// A node is displayed if either of the following is true:
|
|
191
|
+
// - There is no filter value and this node or its descendents belong on this pane
|
|
192
|
+
// - There is a filter value and this node or one of this node's descendents or ancestors match on this pane
|
|
193
|
+
const isDisplayed =
|
|
194
|
+
(!filterValue && descendentsOnThisPane.length > 0) ||
|
|
195
|
+
hasMatchingChildren ||
|
|
196
|
+
(hasParentMatch && descendentsOnThisPane.length > 0) ||
|
|
197
|
+
isFilterMatch;
|
|
198
|
+
|
|
199
|
+
if (!isDisplayed) {
|
|
200
|
+
if (isChosen) {
|
|
201
|
+
hiddenChosen.push(node.id);
|
|
202
|
+
} else {
|
|
203
|
+
hiddenAvailable.push(node.id);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return [
|
|
208
|
+
...(isDisplayed
|
|
209
|
+
? [
|
|
210
|
+
{
|
|
211
|
+
id: node.id,
|
|
212
|
+
text: node.text,
|
|
213
|
+
isChecked,
|
|
214
|
+
checkProps: { 'aria-label': `Select ${node.text}` },
|
|
215
|
+
hasBadge: node.children && node.children.length > 0,
|
|
216
|
+
badgeProps: { isRead: true },
|
|
217
|
+
defaultExpanded: isChosen ? !!chosenFilter : !!availableFilter,
|
|
218
|
+
children: node.children
|
|
219
|
+
? buildOptions(isChosen, node.children, isFilterMatch || hasParentMatch)
|
|
220
|
+
: undefined
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
: []),
|
|
224
|
+
...(!isDisplayed && node.children && node.children.length
|
|
225
|
+
? buildOptions(isChosen, node.children, hasParentMatch)
|
|
226
|
+
: []),
|
|
227
|
+
...(remainingNodes ? buildOptions(isChosen, remainingNodes, hasParentMatch) : [])
|
|
228
|
+
];
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const buildPane = (isChosen: boolean): React.ReactNode => {
|
|
232
|
+
const options: DualListSelectorTreeItemData[] = buildOptions(isChosen, data, false);
|
|
233
|
+
const numOptions = isChosen ? chosenLeafIds.length : memoizedAllLeaves.length - chosenLeafIds.length;
|
|
234
|
+
const numSelected = checkedLeafIds.filter(id =>
|
|
235
|
+
isChosen ? chosenLeafIds.includes(id) : !chosenLeafIds.includes(id)
|
|
236
|
+
).length;
|
|
237
|
+
const status = `${numSelected} of ${numOptions} options selected`;
|
|
238
|
+
return (
|
|
239
|
+
<DualListSelectorPane
|
|
240
|
+
title={isChosen ? 'Chosen' : 'Available'}
|
|
241
|
+
status={status}
|
|
242
|
+
searchInput={buildSearchInput(isChosen)}
|
|
243
|
+
isChosen={isChosen}
|
|
244
|
+
>
|
|
245
|
+
<DualListSelectorList>
|
|
246
|
+
<DualListSelectorTree
|
|
247
|
+
data={options}
|
|
248
|
+
onOptionCheck={(e, isChecked, itemData) => onOptionCheck(e, isChecked, itemData, isChosen)}
|
|
249
|
+
/>
|
|
250
|
+
</DualListSelectorList>
|
|
251
|
+
</DualListSelectorPane>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<DualListSelector isTree>
|
|
257
|
+
{buildPane(false)}
|
|
258
|
+
<DualListSelectorControlsWrapper aria-label="Selector controls">
|
|
259
|
+
<DualListSelectorControl
|
|
260
|
+
isDisabled={!checkedLeafIds.filter(x => !chosenLeafIds.includes(x)).length}
|
|
261
|
+
onClick={() => moveChecked(true)}
|
|
262
|
+
aria-label="Add selected"
|
|
263
|
+
>
|
|
264
|
+
<AngleRightIcon />
|
|
265
|
+
</DualListSelectorControl>
|
|
266
|
+
<DualListSelectorControl
|
|
267
|
+
isDisabled={chosenLeafIds.length === memoizedAllLeaves.length}
|
|
268
|
+
onClick={() => moveAll(true)}
|
|
269
|
+
aria-label="Add all"
|
|
270
|
+
>
|
|
271
|
+
<AngleDoubleRightIcon />
|
|
272
|
+
</DualListSelectorControl>
|
|
273
|
+
<DualListSelectorControl
|
|
274
|
+
isDisabled={chosenLeafIds.length === 0}
|
|
275
|
+
onClick={() => moveAll(false)}
|
|
276
|
+
aria-label="Remove all"
|
|
277
|
+
>
|
|
278
|
+
<AngleDoubleLeftIcon />
|
|
279
|
+
</DualListSelectorControl>
|
|
280
|
+
<DualListSelectorControl
|
|
281
|
+
onClick={() => moveChecked(false)}
|
|
282
|
+
isDisabled={!checkedLeafIds.filter(x => !!chosenLeafIds.includes(x)).length}
|
|
283
|
+
aria-label="Remove selected"
|
|
284
|
+
>
|
|
285
|
+
<AngleLeftIcon />
|
|
286
|
+
</DualListSelectorControl>
|
|
287
|
+
</DualListSelectorControlsWrapper>
|
|
288
|
+
{buildPane(true)}
|
|
289
|
+
</DualListSelector>
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export const ComposableDualListSelectorTreeExample: React.FunctionComponent = () => (
|
|
294
|
+
<ComposableDualListSelectorTree
|
|
295
|
+
data={[
|
|
296
|
+
{
|
|
297
|
+
id: 'fruits',
|
|
298
|
+
text: 'Fruits',
|
|
299
|
+
children: [
|
|
300
|
+
{ id: 'apple', text: 'Apple' },
|
|
301
|
+
{
|
|
302
|
+
id: 'berries',
|
|
303
|
+
text: 'Berries',
|
|
304
|
+
children: [
|
|
305
|
+
{ id: 'blueberry', text: 'Blueberry' },
|
|
306
|
+
{ id: 'strawberry', text: 'Strawberry' }
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
{ id: 'banana', text: 'Banana' }
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
{ id: 'bread', text: 'Bread' },
|
|
313
|
+
{
|
|
314
|
+
id: 'vegetables',
|
|
315
|
+
text: 'Vegetables',
|
|
316
|
+
children: [
|
|
317
|
+
{ id: 'broccoli', text: 'Broccoli' },
|
|
318
|
+
{ id: 'cauliflower', text: 'Cauliflower' }
|
|
319
|
+
]
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: 'proteins',
|
|
323
|
+
text: 'Proteins',
|
|
324
|
+
children: [
|
|
325
|
+
{ id: 'beans', text: 'Beans' },
|
|
326
|
+
{
|
|
327
|
+
id: 'meats',
|
|
328
|
+
text: 'Meats',
|
|
329
|
+
children: [
|
|
330
|
+
{
|
|
331
|
+
id: 'beef',
|
|
332
|
+
text: 'Beef'
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
id: 'chicken',
|
|
336
|
+
text: 'Chicken'
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
{ id: 'tofu', text: 'Tofu' }
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
]}
|
|
344
|
+
/>
|
|
345
|
+
);
|
|
@@ -8,7 +8,6 @@ propComponents: [
|
|
|
8
8
|
'DualListSelectorControl',
|
|
9
9
|
'DualListSelectorControlsWrapper',
|
|
10
10
|
'DualListSelectorTree',
|
|
11
|
-
'DualListSelectorListItem',
|
|
12
11
|
'DualListSelectorTreeItemData'
|
|
13
12
|
]
|
|
14
13
|
beta: true
|
|
@@ -822,3 +821,8 @@ const ComposableDualListSelector = () => {
|
|
|
822
821
|
);
|
|
823
822
|
}
|
|
824
823
|
```
|
|
824
|
+
|
|
825
|
+
### Composable dual list selector tree
|
|
826
|
+
```ts file="ComposableTree.tsx"
|
|
827
|
+
```
|
|
828
|
+
|
|
@@ -104,7 +104,7 @@ export interface PopoverProps {
|
|
|
104
104
|
*/
|
|
105
105
|
footerContent?: React.ReactNode | ((hide: () => void) => React.ReactNode);
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Simple header content to be placed within a title.
|
|
108
108
|
* If you want to close the popover after an action within the bodyContent, you can use the isVisible prop for manual control,
|
|
109
109
|
* or you can provide a function which will receive a callback as an argument to hide the popover
|
|
110
110
|
* i.e. headerContent={hide => <Button onClick={() => hide()}>Close</Button>}
|
|
@@ -112,6 +112,12 @@ export interface PopoverProps {
|
|
|
112
112
|
headerContent?: React.ReactNode | ((hide: () => void) => React.ReactNode);
|
|
113
113
|
/** Sets the heading level to use for the popover header. Default is h6. */
|
|
114
114
|
headerComponent?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
115
|
+
/** @beta Icon to be displayed in the popover header **/
|
|
116
|
+
headerIcon?: React.ReactNode;
|
|
117
|
+
/** @beta Severity variants for an alert popover. This modifies the color of the header to match the severity. */
|
|
118
|
+
alertSeverityVariant?: 'default' | 'info' | 'warning' | 'success' | 'danger';
|
|
119
|
+
/** @beta Text announced by screen reader when alert severity variant is set to indicate severity level */
|
|
120
|
+
alertSeverityScreenReaderText?: string;
|
|
115
121
|
/** Hides the popover when a click occurs outside (only works if isVisible is not controlled by the user) */
|
|
116
122
|
hideOnOutsideClick?: boolean;
|
|
117
123
|
/**
|
|
@@ -198,6 +204,14 @@ export interface PopoverProps {
|
|
|
198
204
|
tippyProps?: Partial<TippyProps>;
|
|
199
205
|
}
|
|
200
206
|
|
|
207
|
+
const alertStyle = {
|
|
208
|
+
default: styles.modifiers.default,
|
|
209
|
+
info: styles.modifiers.info,
|
|
210
|
+
success: styles.modifiers.success,
|
|
211
|
+
warning: styles.modifiers.warning,
|
|
212
|
+
danger: styles.modifiers.danger
|
|
213
|
+
};
|
|
214
|
+
|
|
201
215
|
export const Popover: React.FunctionComponent<PopoverProps> = ({
|
|
202
216
|
children,
|
|
203
217
|
position = 'top',
|
|
@@ -210,6 +224,9 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
|
|
|
210
224
|
bodyContent,
|
|
211
225
|
headerContent = null,
|
|
212
226
|
headerComponent = 'h6',
|
|
227
|
+
headerIcon = null,
|
|
228
|
+
alertSeverityVariant,
|
|
229
|
+
alertSeverityScreenReaderText,
|
|
213
230
|
footerContent = null,
|
|
214
231
|
appendTo = () => document.body,
|
|
215
232
|
hideOnOutsideClick = true,
|
|
@@ -253,6 +270,7 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
|
|
|
253
270
|
const transitionTimerRef = React.useRef(null);
|
|
254
271
|
const showTimerRef = React.useRef(null);
|
|
255
272
|
const hideTimerRef = React.useRef(null);
|
|
273
|
+
|
|
256
274
|
React.useEffect(() => {
|
|
257
275
|
onMount();
|
|
258
276
|
}, []);
|
|
@@ -383,6 +401,7 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
|
|
|
383
401
|
preventScrollOnDeactivate
|
|
384
402
|
className={css(
|
|
385
403
|
styles.popover,
|
|
404
|
+
alertSeverityVariant && alertStyle[alertSeverityVariant],
|
|
386
405
|
hasNoPadding && styles.modifiers.noPadding,
|
|
387
406
|
hasAutoWidth && styles.modifiers.widthAuto,
|
|
388
407
|
className
|
|
@@ -405,7 +424,13 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
|
|
|
405
424
|
<PopoverContent>
|
|
406
425
|
{showClose && <PopoverCloseButton onClose={closePopover} aria-label={closeBtnAriaLabel} />}
|
|
407
426
|
{headerContent && (
|
|
408
|
-
<PopoverHeader
|
|
427
|
+
<PopoverHeader
|
|
428
|
+
id={`popover-${uniqueId}-header`}
|
|
429
|
+
icon={headerIcon}
|
|
430
|
+
alertSeverityVariant={alertSeverityVariant}
|
|
431
|
+
alertSeverityScreenReaderText={alertSeverityScreenReaderText || `${alertSeverityVariant} alert:`}
|
|
432
|
+
titleHeadingLevel={headerComponent}
|
|
433
|
+
>
|
|
409
434
|
{typeof headerContent === 'function' ? headerContent(hide) : headerContent}
|
|
410
435
|
</PopoverHeader>
|
|
411
436
|
)}
|
|
@@ -2,20 +2,23 @@ import * as React from 'react';
|
|
|
2
2
|
import styles from '@patternfly/react-styles/css/components/Popover/popover';
|
|
3
3
|
import { css } from '@patternfly/react-styles';
|
|
4
4
|
|
|
5
|
+
export interface PopoverBodyProps extends React.HTMLProps<HTMLDivElement> {
|
|
6
|
+
/** Popover body id */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Popover body content */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** Classes to be applied to the popover body. */
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
export const PopoverBody: React.FunctionComponent<PopoverBodyProps> = ({
|
|
6
15
|
children,
|
|
7
16
|
id,
|
|
17
|
+
className,
|
|
8
18
|
...props
|
|
9
19
|
}: PopoverBodyProps) => (
|
|
10
|
-
<div className={css(styles.popoverBody)} id={id} {...props}>
|
|
20
|
+
<div className={css(styles.popoverBody, className)} id={id} {...props}>
|
|
11
21
|
{children}
|
|
12
22
|
</div>
|
|
13
23
|
);
|
|
14
24
|
PopoverBody.displayName = 'PopoverBody';
|
|
15
|
-
|
|
16
|
-
export interface PopoverBodyProps extends React.HTMLProps<HTMLDivElement> {
|
|
17
|
-
/** PopoverBody id */
|
|
18
|
-
id: string;
|
|
19
|
-
/** PopoverBody content */
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
}
|
|
@@ -2,6 +2,13 @@ import * as React from 'react';
|
|
|
2
2
|
import styles from '@patternfly/react-styles/css/components/Popover/popover';
|
|
3
3
|
import { css } from '@patternfly/react-styles';
|
|
4
4
|
|
|
5
|
+
export interface PopoverFooterProps extends React.HTMLProps<HTMLDivElement> {
|
|
6
|
+
/** Additional classes added to the Popover footer */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Footer node */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
export const PopoverFooter: React.FunctionComponent<PopoverFooterProps> = ({
|
|
6
13
|
children,
|
|
7
14
|
className = '',
|
|
@@ -12,10 +19,3 @@ export const PopoverFooter: React.FunctionComponent<PopoverFooterProps> = ({
|
|
|
12
19
|
</footer>
|
|
13
20
|
);
|
|
14
21
|
PopoverFooter.displayName = 'PopoverFooter';
|
|
15
|
-
|
|
16
|
-
export interface PopoverFooterProps extends React.HTMLProps<HTMLDivElement> {
|
|
17
|
-
/** Additional classes added to the Popover Footer */
|
|
18
|
-
className?: string;
|
|
19
|
-
/** Footer node */
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
}
|