@patternfly/react-core 4.178.0 → 4.180.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/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/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/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 +449 -278
- package/dist/umd/react-core.js +54 -8
- 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/Toolbar/examples/Toolbar.md +1 -1
- 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
|
+
|
package/src/demos/Card/Card.md
CHANGED
|
@@ -86,8 +86,6 @@ class CardViewBasic extends React.Component {
|
|
|
86
86
|
constructor(props) {
|
|
87
87
|
super(props);
|
|
88
88
|
|
|
89
|
-
this.handleCheckboxClick = this.handleCheckboxClick.bind(this);
|
|
90
|
-
|
|
91
89
|
this.state = {
|
|
92
90
|
filters: {
|
|
93
91
|
products: []
|
|
@@ -199,6 +197,39 @@ class CardViewBasic extends React.Component {
|
|
|
199
197
|
});
|
|
200
198
|
}
|
|
201
199
|
};
|
|
200
|
+
|
|
201
|
+
this.onKeyDown = (event, productId) => {
|
|
202
|
+
console.log(productId);
|
|
203
|
+
if (event.target !== event.currentTarget) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
this.setState(prevState => {
|
|
209
|
+
return prevState.selectedItems.includes(productId*1) ?
|
|
210
|
+
{
|
|
211
|
+
selectedItems: [...prevState.selectedItems.filter(id => productId * 1 != id)],
|
|
212
|
+
areAllSelected: false
|
|
213
|
+
} : {
|
|
214
|
+
selectedItems: [...prevState.selectedItems, productId * 1],
|
|
215
|
+
areAllSelected: prevState.totalItemCount === prevState.selectedItems.length + 1
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
this.onClick = productId => {
|
|
222
|
+
this.setState(prevState => {
|
|
223
|
+
return prevState.selectedItems.includes(productId*1) ?
|
|
224
|
+
{
|
|
225
|
+
selectedItems: [...prevState.selectedItems.filter(id => productId * 1 != id)],
|
|
226
|
+
areAllSelected: false
|
|
227
|
+
} : {
|
|
228
|
+
selectedItems: [...prevState.selectedItems, productId * 1],
|
|
229
|
+
areAllSelected: prevState.totalItemCount === prevState.selectedItems.length + 1
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
};
|
|
202
233
|
}
|
|
203
234
|
|
|
204
235
|
selectedItems(e) {
|
|
@@ -294,24 +325,6 @@ class CardViewBasic extends React.Component {
|
|
|
294
325
|
return collection;
|
|
295
326
|
}
|
|
296
327
|
|
|
297
|
-
handleCheckboxClick(checked, e) {
|
|
298
|
-
const { value } = e.target;
|
|
299
|
-
const { totalItemCount } = this.state;
|
|
300
|
-
|
|
301
|
-
if (checked) {
|
|
302
|
-
const collection = this.getAllItems();
|
|
303
|
-
this.setState(prevState => ({
|
|
304
|
-
selectedItems: [...prevState.selectedItems, value * 1],
|
|
305
|
-
areAllSelected: totalItemCount === prevState.selectedItems.length + 1
|
|
306
|
-
}));
|
|
307
|
-
} else {
|
|
308
|
-
this.setState(prevState => ({
|
|
309
|
-
selectedItems: prevState.selectedItems.filter(item => item != value),
|
|
310
|
-
areAllSelected: false
|
|
311
|
-
}));
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
328
|
updateSelected() {
|
|
316
329
|
const { res, selectedItems } = this.state;
|
|
317
330
|
let rows = res.map(post => {
|
|
@@ -547,7 +560,11 @@ class CardViewBasic extends React.Component {
|
|
|
547
560
|
</PageSection>
|
|
548
561
|
<PageSection isFilled>
|
|
549
562
|
<Gallery hasGutter>
|
|
550
|
-
<Card
|
|
563
|
+
<Card
|
|
564
|
+
isSelectable
|
|
565
|
+
selectableVariant="raised"
|
|
566
|
+
isCompact
|
|
567
|
+
>
|
|
551
568
|
<Bullseye>
|
|
552
569
|
<EmptyState variant={EmptyStateVariant.xs}>
|
|
553
570
|
<EmptyStateIcon icon={PlusCircleIcon} />
|
|
@@ -561,7 +578,15 @@ class CardViewBasic extends React.Component {
|
|
|
561
578
|
</Bullseye>
|
|
562
579
|
</Card>
|
|
563
580
|
{filtered.map((product, key) => (
|
|
564
|
-
<Card
|
|
581
|
+
<Card
|
|
582
|
+
isSelectable
|
|
583
|
+
selectableVariant="raised"
|
|
584
|
+
isCompact
|
|
585
|
+
key={product.name}
|
|
586
|
+
onKeyDown={(e) => this.onKeyDown(e, product.id)}
|
|
587
|
+
onClick={() => this.onClick(product.id)}
|
|
588
|
+
isSelected={selectedItems.includes(product.id)}
|
|
589
|
+
>
|
|
565
590
|
<CardHeader>
|
|
566
591
|
<img src={icons[product.icon]} alt={`${product.name} icon`} style={{ maxWidth: '60px' }} />
|
|
567
592
|
<CardActions>
|
|
@@ -587,7 +612,6 @@ class CardViewBasic extends React.Component {
|
|
|
587
612
|
<Checkbox
|
|
588
613
|
checked={isChecked}
|
|
589
614
|
value={product.id}
|
|
590
|
-
onChange={this.handleCheckboxClick}
|
|
591
615
|
isChecked={selectedItems.includes(product.id)}
|
|
592
616
|
aria-label="card checkbox example"
|
|
593
617
|
id={`check-${product.id}`}
|