@patternfly/react-core 4.177.0 → 4.180.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/esm/components/Card/Card.d.ts +5 -7
- package/dist/esm/components/Card/Card.d.ts.map +1 -1
- package/dist/esm/components/Card/Card.js +14 -2
- package/dist/esm/components/Card/Card.js.map +1 -1
- package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/esm/components/DragDrop/Droppable.js +5 -1
- package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
- 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/MenuToggle/MenuToggle.d.ts +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js +2 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
- package/dist/esm/components/Popover/Popover.js +2 -22
- package/dist/esm/components/Popover/Popover.js.map +1 -1
- package/dist/js/components/Card/Card.d.ts +5 -7
- package/dist/js/components/Card/Card.d.ts.map +1 -1
- package/dist/js/components/Card/Card.js +14 -2
- package/dist/js/components/Card/Card.js.map +1 -1
- package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/js/components/DragDrop/Droppable.js +5 -1
- package/dist/js/components/DragDrop/Droppable.js.map +1 -1
- 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/MenuToggle/MenuToggle.d.ts +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.js +2 -1
- package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/js/components/Popover/Popover.d.ts.map +1 -1
- package/dist/js/components/Popover/Popover.js +2 -22
- package/dist/js/components/Popover/Popover.js.map +1 -1
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Black.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-BlackItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Bold.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-BoldItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Light.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-LightItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Medium.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-MediumItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Regular.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplayVF-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplayVF-updated.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Bold.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-BoldItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Light.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-LightItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Medium.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-MediumItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Regular.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMonoVF-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMonoVF-updated.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Bold.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-BoldItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Light.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-LightItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Medium.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-MediumItalic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Regular.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatTextVF-updated-Italic.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatTextVF-updated.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatDisplayVF-updated-ItalicModified.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatDisplayVFModified-updated.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatTextVF-updated-ItalicModified.woff2 +0 -0
- package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatTextVFModified-updated.woff2 +0 -0
- package/dist/styles/base-no-reset.css +121 -0
- package/dist/styles/base.css +121 -15
- package/dist/umd/react-core.css +183 -12
- package/dist/umd/react-core.js +58 -31
- package/dist/umd/react-core.min.css +183 -12
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +6 -6
- package/src/components/Card/Card.tsx +23 -17
- package/src/components/Card/__tests__/Card.test.tsx +8 -14
- package/src/components/Card/__tests__/__snapshots__/Card.test.tsx.snap +2 -12
- package/src/components/Card/examples/Card.md +230 -264
- package/src/components/DragDrop/Droppable.tsx +5 -1
- package/src/components/DragDrop/examples/DragDrop.md +2 -0
- 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/MenuToggle/MenuToggle.tsx +5 -2
- package/src/components/MenuToggle/__tests__/MenuToggle.test.tsx +5 -0
- package/src/components/MenuToggle/__tests__/__snapshots__/MenuToggle.test.tsx.snap +59 -0
- package/src/components/MenuToggle/examples/MenuToggle.md +60 -67
- package/src/components/Popover/Popover.tsx +1 -19
- package/src/components/Popover/__tests__/Generated/__snapshots__/Popover.test.tsx.snap +0 -1
- package/src/components/Popover/__tests__/__snapshots__/Popover.test.tsx.snap +0 -4
- package/src/demos/Card/Card.md +47 -23
- package/src/demos/TextInputGroupDemo.md +8 -246
- package/src/demos/examples/TextInputGroup/AttributeValueFiltering.js +250 -0
- package/src/demos/examples/TextInputGroup/AutoCompleteSearch.js +230 -0
|
@@ -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
|
+
|
|
@@ -15,7 +15,7 @@ export interface MenuToggleProps
|
|
|
15
15
|
/** Flag indicating the toggle is disabled */
|
|
16
16
|
isDisabled?: boolean;
|
|
17
17
|
/** Variant styles of the menu toggle */
|
|
18
|
-
variant?: 'default' | 'plain' | 'primary';
|
|
18
|
+
variant?: 'default' | 'plain' | 'primary' | 'plainText';
|
|
19
19
|
/** Optional icon rendered inside the toggle, before the children content */
|
|
20
20
|
icon?: React.ReactNode;
|
|
21
21
|
/** Optional badge rendered inside the toggle, after the children content */
|
|
@@ -37,6 +37,8 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
37
37
|
const { children, className, icon, badge, isExpanded, isDisabled, variant, innerRef, ...props } = this.props;
|
|
38
38
|
|
|
39
39
|
const isPlain = variant === 'plain';
|
|
40
|
+
const isPlainText = variant === 'plainText';
|
|
41
|
+
|
|
40
42
|
const content = (
|
|
41
43
|
<React.Fragment>
|
|
42
44
|
{icon && <span className={css(styles.menuToggleIcon)}>{icon}</span>}
|
|
@@ -55,7 +57,8 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
55
57
|
styles.menuToggle,
|
|
56
58
|
isExpanded && styles.modifiers.expanded,
|
|
57
59
|
variant === 'primary' && styles.modifiers.primary,
|
|
58
|
-
isPlain && styles.modifiers.plain,
|
|
60
|
+
(isPlain || isPlainText) && styles.modifiers.plain,
|
|
61
|
+
isPlainText && styles.modifiers.text,
|
|
59
62
|
className
|
|
60
63
|
)}
|
|
61
64
|
type="button"
|
|
@@ -40,6 +40,11 @@ describe('menu toggle', () => {
|
|
|
40
40
|
expect(view).toMatchSnapshot();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
test('shows plain text', () => {
|
|
44
|
+
const view = mount(<MenuToggle variant="plainText">Toggle</MenuToggle>);
|
|
45
|
+
expect(view).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
|
|
43
48
|
test('shows icon', () => {
|
|
44
49
|
const view = mount(<MenuToggle icon={<CogIcon />}>Toggle</MenuToggle>);
|
|
45
50
|
expect(view).toMatchSnapshot();
|
|
@@ -517,3 +517,62 @@ exports[`menu toggle shows isPrimary 1`] = `
|
|
|
517
517
|
</MenuToggleBase>
|
|
518
518
|
</MenuToggle>
|
|
519
519
|
`;
|
|
520
|
+
|
|
521
|
+
exports[`menu toggle shows plain text 1`] = `
|
|
522
|
+
<MenuToggle
|
|
523
|
+
variant="plainText"
|
|
524
|
+
>
|
|
525
|
+
<MenuToggleBase
|
|
526
|
+
className=""
|
|
527
|
+
innerRef={null}
|
|
528
|
+
isDisabled={false}
|
|
529
|
+
isExpanded={false}
|
|
530
|
+
variant="plainText"
|
|
531
|
+
>
|
|
532
|
+
<button
|
|
533
|
+
aria-expanded={false}
|
|
534
|
+
className="pf-c-menu-toggle pf-m-plain pf-m-text"
|
|
535
|
+
type="button"
|
|
536
|
+
>
|
|
537
|
+
<span
|
|
538
|
+
className="pf-c-menu-toggle__text"
|
|
539
|
+
>
|
|
540
|
+
Toggle
|
|
541
|
+
</span>
|
|
542
|
+
<span
|
|
543
|
+
className="pf-c-menu-toggle__controls"
|
|
544
|
+
>
|
|
545
|
+
<span
|
|
546
|
+
className="pf-c-menu-toggle__toggle-icon"
|
|
547
|
+
>
|
|
548
|
+
<CaretDownIcon
|
|
549
|
+
aria-hidden={true}
|
|
550
|
+
color="currentColor"
|
|
551
|
+
noVerticalAlign={false}
|
|
552
|
+
size="sm"
|
|
553
|
+
>
|
|
554
|
+
<svg
|
|
555
|
+
aria-hidden={true}
|
|
556
|
+
aria-labelledby={null}
|
|
557
|
+
fill="currentColor"
|
|
558
|
+
height="1em"
|
|
559
|
+
role="img"
|
|
560
|
+
style={
|
|
561
|
+
Object {
|
|
562
|
+
"verticalAlign": "-0.125em",
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
viewBox="0 0 320 512"
|
|
566
|
+
width="1em"
|
|
567
|
+
>
|
|
568
|
+
<path
|
|
569
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
570
|
+
/>
|
|
571
|
+
</svg>
|
|
572
|
+
</CaretDownIcon>
|
|
573
|
+
</span>
|
|
574
|
+
</span>
|
|
575
|
+
</button>
|
|
576
|
+
</MenuToggleBase>
|
|
577
|
+
</MenuToggle>
|
|
578
|
+
`;
|