@capillarytech/blaze-ui 0.1.6-alpha.67 → 0.1.6-alpha.7
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/CapHeading/CapHeading.js +71 -0
- package/CapHeading/index.js +1 -0
- package/CapHeading/styles.js +125 -0
- package/CapInfoNote/CapInfoNote.js +54 -0
- package/CapInfoNote/index.js +1 -0
- package/CapInfoNote/styles.js +63 -0
- package/CapInput/CapInput.js +2 -2
- package/CapInput/Number.js +1 -1
- package/CapInput/Search.js +1 -1
- package/CapInput/TextArea.js +1 -1
- package/CapInput/loadable.js +9 -0
- package/CapInput/styles.js +2 -2
- package/CapLabel/CapLabel.js +81 -58
- package/CapLabel/index.js +1 -3
- package/CapLabel/styles.js +212 -250
- package/CapRow/CapRow.js +10 -111
- package/CapRow/index.js +1 -3
- package/CapRow/styles.js +6 -47
- package/CapTable/CapTable.js +3 -0
- package/CapTable/loadable.js +4 -4
- package/CapTable/styles.js +26 -6
- package/CapTooltip/CapTooltip.js +25 -87
- package/CapTooltip/index.js +1 -3
- package/CapTooltip/styles.js +27 -19
- package/CapUnifiedSelect/CapUnifiedSelect.js +77 -495
- package/CapUnifiedSelect/index.js +4 -1
- package/CapUnifiedSelect/loadable.js +3 -0
- package/CapUnifiedSelect/styles.js +165 -376
- package/dist/235.index.js +2 -0
- package/dist/235.index.js.LICENSE.txt +29 -0
- package/dist/603.index.js +1 -0
- package/dist/CapInput/CapInput.js +66 -0
- package/dist/CapInput/Number.js +42 -0
- package/dist/CapInput/Search.js +35 -0
- package/dist/CapInput/TextArea.js +42 -0
- package/dist/CapInput/index.js +15 -0
- package/dist/CapInput/messages.js +32 -0
- package/dist/CapInput/styles.js +11 -0
- package/dist/CapTable/CapTable.js +151 -0
- package/dist/CapTable/index.js +9 -0
- package/dist/CapTable/loadable.js +23 -0
- package/dist/CapTable/styles.js +26 -0
- package/dist/LocaleHoc/index.js +40 -0
- package/dist/esm/CapHeading/CapHeading.js +41 -0
- package/dist/esm/CapHeading/index.js +1 -0
- package/dist/esm/CapHeading/styles.js +123 -0
- package/dist/esm/CapInfoNote/CapInfoNote.js +62 -0
- package/dist/esm/CapInfoNote/index.js +1 -0
- package/dist/esm/CapInfoNote/styles.js +6 -0
- package/dist/esm/CapInput/CapInput.js +57 -0
- package/dist/esm/CapInput/Number.js +35 -0
- package/dist/esm/CapInput/Search.js +28 -0
- package/dist/esm/CapInput/TextArea.js +35 -0
- package/dist/esm/CapInput/index.js +8 -0
- package/dist/esm/CapInput/loadable.js +9 -0
- package/dist/esm/CapInput/messages.js +25 -0
- package/dist/esm/CapInput/styles.js +3 -0
- package/dist/esm/CapLabel/CapLabel.js +50 -0
- package/dist/esm/CapLabel/index.js +1 -0
- package/dist/esm/CapLabel/styles.js +219 -0
- package/dist/esm/CapRow/CapRow.js +22 -0
- package/dist/esm/CapRow/index.js +1 -0
- package/dist/esm/CapRow/styles.js +5 -0
- package/dist/esm/CapTable/CapTable.js +143 -0
- package/dist/esm/CapTable/index.js +2 -0
- package/dist/esm/CapTable/loadable.js +12 -0
- package/dist/esm/CapTable/styles.js +17 -0
- package/dist/esm/CapTooltip/CapTooltip.js +34 -0
- package/dist/esm/CapTooltip/index.js +1 -0
- package/dist/esm/CapTooltip/styles.js +6 -0
- package/dist/esm/CapUnifiedSelect/CapUnifiedSelect.js +101 -0
- package/dist/esm/CapUnifiedSelect/index.js +3 -0
- package/dist/esm/CapUnifiedSelect/loadable.js +4 -0
- package/dist/esm/CapUnifiedSelect/messages.js +23 -0
- package/dist/esm/CapUnifiedSelect/styles.js +15 -0
- package/dist/esm/LocaleHoc/index.js +31 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/styled/index.js +5 -0
- package/dist/esm/styled/variables.js +88 -0
- package/dist/esm/translations/en.js +329 -0
- package/dist/index.js +39 -0
- package/dist/index.js.LICENSE.txt +7 -0
- package/dist/styled/index.js +22 -0
- package/dist/styled/variables.js +94 -0
- package/dist/translations/en.js +335 -0
- package/index.js +1 -12
- package/package.json +12 -6
- package/styled/variables.js +0 -2
- package/.DS_Store +0 -0
- package/CapIcon/CapIcon.js +0 -183
- package/CapIcon/index.js +0 -3
- package/CapIcon/styles.js +0 -76
- package/CapSkeleton/CapSkeleton.js +0 -17
- package/CapSkeleton/index.js +0 -1
- package/CapSpin/CapSpin.js +0 -23
- package/CapSpin/index.js +0 -1
- package/CapTestSelect/CapTestSelect.js +0 -47
- package/CapTestSelect/index.js +0 -1
- package/CapTooltipWithInfo/CapTooltipWithInfo.js +0 -74
- package/CapTooltipWithInfo/index.js +0 -3
- package/CapTooltipWithInfo/styles.js +0 -22
- package/assets/upload.svg +0 -3
- package/utils/index.js +0 -1
- package/utils/withMemo.js +0 -33
- package/utils/withStyles.js +0 -24
|
@@ -1,539 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
// CapUnifiedSelect component using Ant Design v5 Select and TreeSelect directly
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { CapLabel, CapTooltipWithInfo, CapRow, CapIcon, CapTooltip } from '../';
|
|
8
|
-
import withStyles from '../utils/withStyles';
|
|
9
|
-
import withMemo from '../utils/withMemo';
|
|
10
|
-
import { HeaderWrapper, selectStyles } from './styles';
|
|
4
|
+
import { Select, TreeSelect } from 'antd';
|
|
5
|
+
import { SelectWrapper, HeaderWrapper, StyledInfoIcon } from './styles';
|
|
6
|
+
import CapLabel from '../CapLabel';
|
|
7
|
+
import CapTooltip from '../CapTooltip';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
SELECT: 'select',
|
|
14
|
-
MULTI_SELECT: 'multiSelect',
|
|
15
|
-
TREE_SELECT: 'treeSelect',
|
|
16
|
-
MULTI_TREE_SELECT: 'multiTreeSelect'
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const StyledTreeSelect = styled(TreeSelect)`
|
|
20
|
-
${selectStyles}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
const NoResult = memo(({ noResultCustomText, className, showUpload, options, noResultCustomIcon }) => (
|
|
24
|
-
<CapRow
|
|
25
|
-
className={classnames(className, 'cap-unified-select-no-result')}
|
|
26
|
-
align="middle"
|
|
27
|
-
gap={8}
|
|
28
|
-
>
|
|
29
|
-
<CapIcon type={noResultCustomIcon} size="m" />
|
|
30
|
-
<CapLabel className="cap-unified-select-no-result-text">
|
|
31
|
-
{showUpload && options?.length === 0
|
|
32
|
-
? noResultCustomText
|
|
33
|
-
: 'No results found'}
|
|
34
|
-
</CapLabel>
|
|
35
|
-
</CapRow>
|
|
36
|
-
));
|
|
37
|
-
|
|
38
|
-
const SelectAllCheckbox = memo(({ currentItems, tempValue, setTempValue, processTreeData }) => {
|
|
39
|
-
const { leafValues = [] } = processTreeData ? processTreeData(currentItems) : {};
|
|
40
|
-
const totalAvailable = leafValues.length;
|
|
41
|
-
const leafSet = new Set(leafValues);
|
|
42
|
-
const selectedInScope = Array.isArray(tempValue)
|
|
43
|
-
? tempValue.filter((v) => leafSet.has(v)).length
|
|
44
|
-
: 0;
|
|
45
|
-
|
|
46
|
-
const allChecked = totalAvailable > 0 && selectedInScope === totalAvailable;
|
|
47
|
-
const indeterminate = selectedInScope > 0 && selectedInScope < totalAvailable;
|
|
48
|
-
|
|
49
|
-
const handleChange = (e) => {
|
|
50
|
-
if (e.target.checked) {
|
|
51
|
-
const merged = new Set(Array.isArray(tempValue) ? tempValue : []);
|
|
52
|
-
leafValues.forEach((v) => merged.add(v));
|
|
53
|
-
setTempValue(Array.from(merged));
|
|
54
|
-
} else {
|
|
55
|
-
const toRemove = new Set(leafValues);
|
|
56
|
-
const next = (Array.isArray(tempValue) ? tempValue : []).filter(
|
|
57
|
-
(v) => !toRemove.has(v)
|
|
58
|
-
);
|
|
59
|
-
setTempValue(next);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<CapRow className="cap-unified-select-select-all-container" align="middle">
|
|
65
|
-
<Checkbox
|
|
66
|
-
className="cap-unified-select-select-all-checkbox"
|
|
67
|
-
checked={allChecked}
|
|
68
|
-
indeterminate={indeterminate}
|
|
69
|
-
onChange={handleChange}
|
|
70
|
-
>
|
|
71
|
-
<CapLabel type="label14" className="cap-unified-select-select-all-label">Select all</CapLabel>
|
|
72
|
-
</Checkbox>
|
|
73
|
-
</CapRow>
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const buildTreeMaps = (nodes) => {
|
|
78
|
-
const result = {
|
|
79
|
-
leafValues: [],
|
|
80
|
-
parentChildMap: {},
|
|
81
|
-
nodeMap: {},
|
|
82
|
-
};
|
|
83
|
-
if (!nodes) return result;
|
|
84
|
-
|
|
85
|
-
const traverse = (items) => {
|
|
86
|
-
items?.forEach((item) => {
|
|
87
|
-
result.nodeMap[item.value] = item;
|
|
88
|
-
if (item?.children && item.children.length > 0) {
|
|
89
|
-
result.parentChildMap[item.value] = item.children.map(child => child?.value);
|
|
90
|
-
traverse(item.children);
|
|
91
|
-
} else {
|
|
92
|
-
result.leafValues.push(item.value);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
traverse(nodes);
|
|
97
|
-
return result;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const countSelectedLeaves = (treeMaps, selectedValues) => {
|
|
101
|
-
if (!Array.isArray(selectedValues) || !selectedValues?.length) return 0;
|
|
102
|
-
const expandedSet = new Set(selectedValues);
|
|
103
|
-
const processNode = (value) => {
|
|
104
|
-
const children = treeMaps?.parentChildMap?.[value];
|
|
105
|
-
if (!children) return;
|
|
106
|
-
children?.forEach(childValue => {
|
|
107
|
-
expandedSet.add(childValue);
|
|
108
|
-
processNode(childValue);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
selectedValues?.forEach(processNode);
|
|
112
|
-
return treeMaps?.leafValues?.reduce((count, leaf) => expandedSet.has(leaf) ? count + 1 : count, 0) || 0;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const filterTreeData = (data, search, searchBasedOn) => {
|
|
116
|
-
if (!data?.length || !search) return data;
|
|
117
|
-
const searchLower = search.toLowerCase();
|
|
118
|
-
const nodeMatchesSearch = (node) => {
|
|
119
|
-
const target = searchBasedOn === 'value'
|
|
120
|
-
? String(node?.value ?? '')
|
|
121
|
-
: searchBasedOn === 'key'
|
|
122
|
-
? String(node?.key ?? '')
|
|
123
|
-
: String(node?.label ?? node?.title ?? '');
|
|
124
|
-
return target.toLowerCase().includes(searchLower);
|
|
125
|
-
};
|
|
126
|
-
const loop = (items) =>
|
|
127
|
-
items.reduce((acc, item) => {
|
|
128
|
-
if (!item) return acc;
|
|
129
|
-
const children = item?.children?.length ? loop(item.children) : [];
|
|
130
|
-
if (nodeMatchesSearch(item) || children.length) {
|
|
131
|
-
acc.push({ ...item, children });
|
|
132
|
-
}
|
|
133
|
-
return acc;
|
|
134
|
-
}, []);
|
|
135
|
-
return loop(data);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const CapUnifiedSelect = ({
|
|
9
|
+
function CapUnifiedSelect({
|
|
139
10
|
type,
|
|
140
11
|
options = [],
|
|
12
|
+
treeData,
|
|
141
13
|
value,
|
|
142
14
|
onChange,
|
|
143
|
-
placeholder,
|
|
15
|
+
placeholder = 'Select an option',
|
|
144
16
|
className,
|
|
145
17
|
style,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
popoverClassName,
|
|
150
|
-
allowClear,
|
|
151
|
-
headerLabel,
|
|
152
|
-
onUpload,
|
|
18
|
+
allowClear = false,
|
|
19
|
+
showSearch = false,
|
|
20
|
+
label,
|
|
153
21
|
tooltip,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
readOnly,
|
|
160
|
-
searchBasedOn,
|
|
161
|
-
onConfirm,
|
|
162
|
-
clearText,
|
|
163
|
-
noResultCustomText,
|
|
164
|
-
noResultCustomIcon,
|
|
165
|
-
...rest
|
|
166
|
-
}) => {
|
|
167
|
-
const [searchText, setSearchText] = useState('');
|
|
168
|
-
const [tempValue, setTempValue] = useState(value);
|
|
169
|
-
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
170
|
-
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
const isEqual = Array.isArray(value) && Array.isArray(tempValue)
|
|
173
|
-
? value?.length === tempValue?.length && value.every((v) => tempValue.includes(v))
|
|
174
|
-
: value === tempValue;
|
|
175
|
-
if (!isEqual) setTempValue(value);
|
|
176
|
-
}, [value]);
|
|
177
|
-
|
|
178
|
-
const isMulti = useMemo(() => type === SELECT_TYPES.MULTI_SELECT || type === SELECT_TYPES.MULTI_TREE_SELECT, [type]);
|
|
179
|
-
const isTree = useMemo(() => type === SELECT_TYPES.TREE_SELECT || type === SELECT_TYPES.MULTI_TREE_SELECT, [type]);
|
|
180
|
-
|
|
181
|
-
const dataSource = useMemo(() => {
|
|
182
|
-
if (!options?.length) return [];
|
|
183
|
-
const enhanceOptions = (opts) =>
|
|
184
|
-
opts.map((opt) => {
|
|
185
|
-
const decoratedTitle = (
|
|
186
|
-
<CapRow className="cap-unified-select-option-with-suffix">
|
|
187
|
-
<CapLabel type="label14" className="cap-unified-select-option-label">{opt?.label}</CapLabel>
|
|
188
|
-
{opt?.optionSuffix && <div className="cap-unified-select-option-suffix">
|
|
189
|
-
{opt?.optionSuffix} {opt?.optionSuffixInfo && <CapTooltipWithInfo title={opt?.optionSuffixInfo} />}
|
|
190
|
-
</div>}
|
|
191
|
-
{opt?.optionTooltipInfo && <CapTooltipWithInfo title={opt?.optionTooltipInfo} />}
|
|
192
|
-
</CapRow>
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
...opt,
|
|
197
|
-
title: decoratedTitle,
|
|
198
|
-
label: opt?.label,
|
|
199
|
-
children: opt?.children ? enhanceOptions(opt.children) : [],
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
return isTree ? enhanceOptions(options) : options.map((opt) => ({
|
|
204
|
-
...opt,
|
|
205
|
-
title: (
|
|
206
|
-
<CapRow className="cap-unified-select-option-with-suffix">
|
|
207
|
-
<CapLabel type="label14" className="cap-unified-select-option-label">{opt?.label}</CapLabel>
|
|
208
|
-
{opt?.optionSuffix && <div className="cap-unified-select-option-suffix">
|
|
209
|
-
{opt?.optionSuffix} {opt?.optionSuffixInfo && <CapTooltipWithInfo title={opt?.optionSuffixInfo} />}
|
|
210
|
-
</div>}
|
|
211
|
-
{opt?.optionTooltipInfo && <CapTooltipWithInfo title={opt?.optionTooltipInfo} />}
|
|
212
|
-
</CapRow>
|
|
213
|
-
),
|
|
214
|
-
label: opt?.label,
|
|
215
|
-
}));
|
|
216
|
-
}, [isTree, options]);
|
|
217
|
-
|
|
218
|
-
const filteredTree = useMemo(
|
|
219
|
-
() => filterTreeData(dataSource, searchText, searchBasedOn),
|
|
220
|
-
[dataSource, searchText, searchBasedOn]
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
const treeMaps = useMemo(() => buildTreeMaps(options), [options]);
|
|
224
|
-
const selectedLeafCount = useMemo(() => countSelectedLeaves(treeMaps, tempValue), [treeMaps, tempValue]);
|
|
22
|
+
disabled = false,
|
|
23
|
+
}) {
|
|
24
|
+
const selectVirtualizationProps = {
|
|
25
|
+
listHeight: 256,
|
|
26
|
+
};
|
|
225
27
|
|
|
226
|
-
const
|
|
28
|
+
const treeSelectVirtualizationProps = {
|
|
29
|
+
listHeight: 256,
|
|
30
|
+
listItemHeight: 32,
|
|
31
|
+
};
|
|
227
32
|
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
const renderTooltipTitle = (values) => {
|
|
231
|
-
return (
|
|
232
|
-
<div className="cap-unified-select-more-tooltip-content">
|
|
233
|
-
{values.map((val, idx) => (
|
|
234
|
-
<div key={idx}>{val}</div>
|
|
235
|
-
))}
|
|
236
|
-
</div>
|
|
237
|
-
);
|
|
238
|
-
};
|
|
33
|
+
const renderHeader = () => {
|
|
34
|
+
if (!label && !tooltip) return null;
|
|
239
35
|
|
|
240
36
|
return (
|
|
241
|
-
|
|
242
|
-
{
|
|
243
|
-
<
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
placement="bottom"
|
|
247
|
-
overlayClassName="cap-unified-select-more-tooltip"
|
|
248
|
-
arrowPointAtCenter={true}
|
|
249
|
-
>
|
|
250
|
-
<span>+{count - 1} more</span>
|
|
251
|
-
</CapTooltip>
|
|
252
|
-
</span>
|
|
37
|
+
<HeaderWrapper className={disabled ? 'disabled' : ''}>
|
|
38
|
+
{label && (
|
|
39
|
+
<CapLabel type="label16" className={disabled ? 'disabled' : ''}>
|
|
40
|
+
{label}
|
|
41
|
+
</CapLabel>
|
|
253
42
|
)}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
/>
|
|
259
|
-
</>
|
|
260
|
-
);
|
|
261
|
-
}, [isMulti, displayValue, dropdownOpen]);
|
|
262
|
-
|
|
263
|
-
const prefix = useMemo(() => {
|
|
264
|
-
if (isMulti && Array.isArray(displayValue) && displayValue?.length > 0) {
|
|
265
|
-
const firstLeafValue = displayValue.find(val => treeMaps?.leafValues?.includes(val));
|
|
266
|
-
return treeMaps?.nodeMap?.[firstLeafValue]?.label || null;
|
|
267
|
-
}
|
|
268
|
-
return null;
|
|
269
|
-
}, [isMulti, displayValue, treeMaps]);
|
|
270
|
-
|
|
271
|
-
const handleConfirm = useCallback(() => {
|
|
272
|
-
onChange?.(tempValue);
|
|
273
|
-
setDropdownOpen(false);
|
|
274
|
-
setSearchText('');
|
|
275
|
-
onConfirm?.(tempValue);
|
|
276
|
-
}, [onChange, onConfirm, tempValue]);
|
|
277
|
-
|
|
278
|
-
const handleClearAll = useCallback(() => {
|
|
279
|
-
const cleared = isMulti ? [] : undefined;
|
|
280
|
-
setTempValue(cleared);
|
|
281
|
-
onChange?.(cleared);
|
|
282
|
-
setDropdownOpen(false);
|
|
283
|
-
}, [isMulti, onChange]);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const handleDropdownVisibilityChange = useCallback((open) => {
|
|
287
|
-
if (readOnly) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (!open && !customPopupRender) {
|
|
291
|
-
onChange?.(tempValue);
|
|
292
|
-
} else if (!open) {
|
|
293
|
-
setTempValue(value);
|
|
294
|
-
}
|
|
295
|
-
setDropdownOpen(open);
|
|
296
|
-
}, [customPopupRender, value, onChange, tempValue, readOnly]);
|
|
297
|
-
|
|
298
|
-
const renderHeader = useMemo(() => {
|
|
299
|
-
if (!headerLabel && !tooltip) return null;
|
|
300
|
-
return (
|
|
301
|
-
<>
|
|
302
|
-
<HeaderWrapper className={classnames(disabled && 'disabled', 'cap-unified-select-header')}>
|
|
303
|
-
{headerLabel && (
|
|
304
|
-
<CapLabel
|
|
305
|
-
type="label16"
|
|
306
|
-
className={classnames(disabled && 'disabled', 'cap-unified-select-header-label')}
|
|
307
|
-
>
|
|
308
|
-
{headerLabel}
|
|
309
|
-
</CapLabel>
|
|
310
|
-
)}
|
|
311
|
-
{tooltip && (
|
|
312
|
-
<CapTooltipWithInfo
|
|
313
|
-
title={tooltip}
|
|
314
|
-
className={classnames(disabled && 'disabled', 'cap-unified-select-header-tooltip')}
|
|
315
|
-
iconProps={{ disabled }}
|
|
316
|
-
/>
|
|
317
|
-
)}
|
|
318
|
-
</HeaderWrapper>
|
|
319
|
-
{bylineText && (
|
|
320
|
-
<div className="cap-unified-select-header-byline-text">
|
|
321
|
-
<CapLabel
|
|
322
|
-
className={classnames(disabled && 'disabled', 'cap-unified-select-header-byline-text')}
|
|
323
|
-
>
|
|
324
|
-
{bylineText}
|
|
325
|
-
</CapLabel>
|
|
326
|
-
</div>
|
|
43
|
+
{tooltip && (
|
|
44
|
+
<CapTooltip title={tooltip}>
|
|
45
|
+
<StyledInfoIcon className={disabled ? 'disabled' : ''} />
|
|
46
|
+
</CapTooltip>
|
|
327
47
|
)}
|
|
328
|
-
|
|
48
|
+
</HeaderWrapper>
|
|
329
49
|
);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const renderCustomDropdown = useCallback(
|
|
333
|
-
(menu) => {
|
|
334
|
-
if (!customPopupRender) return menu;
|
|
335
|
-
const currentItems = filteredTree;
|
|
50
|
+
};
|
|
336
51
|
|
|
52
|
+
const renderDropdown = () => {
|
|
53
|
+
if (type === 'treeSelect' || type === 'multiTreeSelect') {
|
|
337
54
|
return (
|
|
338
|
-
<
|
|
339
|
-
{
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
<CapRow className="cap-unified-select-upload-container" align="middle" onClick={onUpload}>
|
|
354
|
-
<CapIcon type="upload" size="s" style={{ color: styledVars.CAP_SECONDARY.base }} />
|
|
355
|
-
<CapLabel type="label14" className="cap-unified-select-upload-label">Upload</CapLabel>
|
|
356
|
-
</CapRow>
|
|
357
|
-
)}
|
|
358
|
-
|
|
359
|
-
{isMulti && currentItems.length > 0 && (
|
|
360
|
-
<SelectAllCheckbox
|
|
361
|
-
currentItems={currentItems}
|
|
362
|
-
tempValue={tempValue}
|
|
363
|
-
setTempValue={setTempValue}
|
|
364
|
-
processTreeData={buildTreeMaps}
|
|
365
|
-
/>
|
|
366
|
-
)}
|
|
367
|
-
|
|
368
|
-
{currentItems.length === 0 ? (
|
|
369
|
-
<NoResult
|
|
370
|
-
noResultCustomText={noResultCustomText}
|
|
371
|
-
className={className}
|
|
372
|
-
showUpload={showUpload}
|
|
373
|
-
options={options}
|
|
374
|
-
noResultCustomIcon={noResultCustomIcon}
|
|
375
|
-
/>
|
|
376
|
-
) : (
|
|
377
|
-
menu
|
|
378
|
-
)}
|
|
379
|
-
|
|
380
|
-
{currentItems.length > 0 && isMulti && (
|
|
381
|
-
<div className="cap-unified-select-confirm-container">
|
|
382
|
-
<div className="cap-unified-select-confirm-button-group">
|
|
383
|
-
<Button
|
|
384
|
-
type="primary"
|
|
385
|
-
size="small"
|
|
386
|
-
className="cap-unified-select-confirm-button"
|
|
387
|
-
onClick={handleConfirm}
|
|
388
|
-
>
|
|
389
|
-
Confirm
|
|
390
|
-
</Button>
|
|
391
|
-
<Button
|
|
392
|
-
type="text"
|
|
393
|
-
className="cap-unified-select-cancel-button"
|
|
394
|
-
size="small"
|
|
395
|
-
onClick={handleClearAll}
|
|
396
|
-
>
|
|
397
|
-
{clearText}
|
|
398
|
-
</Button>
|
|
399
|
-
<CapLabel className="cap-unified-select-selected-count">
|
|
400
|
-
{selectedLeafCount} selected
|
|
401
|
-
</CapLabel>
|
|
402
|
-
</div>
|
|
403
|
-
</div>
|
|
404
|
-
)}
|
|
405
|
-
|
|
406
|
-
{(type === SELECT_TYPES.SELECT || type === SELECT_TYPES.TREE_SELECT) && (
|
|
407
|
-
<CapRow className="cap-unified-select-tree-clear-container" onClick={handleClearAll}>
|
|
408
|
-
<CapLabel className="cap-unified-select-tree-clear-label">{clearText}</CapLabel>
|
|
409
|
-
</CapRow>
|
|
410
|
-
)}
|
|
411
|
-
</div>
|
|
55
|
+
<TreeSelect
|
|
56
|
+
treeData={treeData || options}
|
|
57
|
+
value={value}
|
|
58
|
+
onChange={onChange}
|
|
59
|
+
placeholder={placeholder}
|
|
60
|
+
className={className}
|
|
61
|
+
style={style}
|
|
62
|
+
allowClear={allowClear}
|
|
63
|
+
showSearch={showSearch}
|
|
64
|
+
multiple={type === 'multiTreeSelect' ? true : false}
|
|
65
|
+
virtual
|
|
66
|
+
treeDefaultExpandAll
|
|
67
|
+
disabled={disabled}
|
|
68
|
+
{...treeSelectVirtualizationProps}
|
|
69
|
+
/>
|
|
412
70
|
);
|
|
413
|
-
}
|
|
414
|
-
[
|
|
415
|
-
customPopupRender,
|
|
416
|
-
filteredTree,
|
|
417
|
-
searchText,
|
|
418
|
-
isMulti,
|
|
419
|
-
showUpload,
|
|
420
|
-
onUpload,
|
|
421
|
-
noResultCustomText,
|
|
422
|
-
noResultCustomIcon,
|
|
423
|
-
options,
|
|
424
|
-
type,
|
|
425
|
-
tempValue,
|
|
426
|
-
handleConfirm,
|
|
427
|
-
handleClearAll,
|
|
428
|
-
popoverClassName,
|
|
429
|
-
className,
|
|
430
|
-
selectedLeafCount,
|
|
431
|
-
]
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
const combinedClassName = useMemo(
|
|
435
|
-
() => classnames(
|
|
436
|
-
containerClassName,
|
|
437
|
-
'cap-unified-tree-select',
|
|
438
|
-
{ 'cap-unified-tree-select-readonly': readOnly },
|
|
439
|
-
className
|
|
440
|
-
),
|
|
441
|
-
[containerClassName, className, readOnly]
|
|
442
|
-
);
|
|
71
|
+
}
|
|
443
72
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
type={type}
|
|
449
|
-
treeData={filteredTree}
|
|
450
|
-
value={customPopupRender ? tempValue : value}
|
|
451
|
-
treeNodeLabelProp='label'
|
|
452
|
-
onChange={isMulti ? setTempValue : onChange}
|
|
73
|
+
return (
|
|
74
|
+
<Select
|
|
75
|
+
value={value}
|
|
76
|
+
onChange={onChange}
|
|
453
77
|
placeholder={placeholder}
|
|
454
|
-
|
|
455
|
-
maxTagCount={0}
|
|
456
|
-
maxTagPlaceholder={() => null}
|
|
457
|
-
prefix={prefix || undefined}
|
|
458
|
-
suffixIcon={suffix}
|
|
459
|
-
className={combinedClassName}
|
|
460
|
-
classNames={{
|
|
461
|
-
popup: { root: classnames('custom-popup-container', className) },
|
|
462
|
-
}}
|
|
78
|
+
className={className}
|
|
463
79
|
style={style}
|
|
464
|
-
status={isError ? 'error' : ''}
|
|
465
80
|
allowClear={allowClear}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
showCheckedStrategy={TreeSelect.SHOW_CHILD}
|
|
470
|
-
open={dropdownOpen}
|
|
471
|
-
onOpenChange={handleDropdownVisibilityChange}
|
|
81
|
+
showSearch={showSearch}
|
|
82
|
+
options={options}
|
|
83
|
+
mode={type === 'multiSelect' ? 'multiple' : undefined}
|
|
472
84
|
virtual
|
|
473
85
|
disabled={disabled}
|
|
474
|
-
|
|
475
|
-
listHeight={256}
|
|
476
|
-
listItemHeight={32}
|
|
477
|
-
popupRender={renderCustomDropdown}
|
|
478
|
-
{...rest}
|
|
86
|
+
{...selectVirtualizationProps}
|
|
479
87
|
/>
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<SelectWrapper>
|
|
93
|
+
{renderHeader()}
|
|
94
|
+
{renderDropdown()}
|
|
95
|
+
</SelectWrapper>
|
|
486
96
|
);
|
|
487
|
-
}
|
|
97
|
+
}
|
|
488
98
|
|
|
489
99
|
CapUnifiedSelect.propTypes = {
|
|
490
|
-
type: PropTypes.oneOf(
|
|
100
|
+
type: PropTypes.oneOf(['select', 'multiSelect', 'treeSelect', 'multiTreeSelect']),
|
|
491
101
|
options: PropTypes.array,
|
|
102
|
+
treeData: PropTypes.array,
|
|
492
103
|
value: PropTypes.any,
|
|
493
|
-
containerClassName: PropTypes.string,
|
|
494
104
|
onChange: PropTypes.func,
|
|
495
105
|
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
496
106
|
className: PropTypes.string,
|
|
497
107
|
style: PropTypes.object,
|
|
498
108
|
allowClear: PropTypes.bool,
|
|
499
|
-
|
|
109
|
+
showSearch: PropTypes.bool,
|
|
110
|
+
label: PropTypes.string,
|
|
500
111
|
tooltip: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
501
112
|
disabled: PropTypes.bool,
|
|
502
|
-
readOnly: PropTypes.bool,
|
|
503
|
-
bylineText: PropTypes.string,
|
|
504
|
-
customPopupRender: PropTypes.bool,
|
|
505
|
-
showSearch: PropTypes.bool,
|
|
506
|
-
searchBasedOn: PropTypes.oneOf(['label', 'value', 'key']),
|
|
507
|
-
onConfirm: PropTypes.func,
|
|
508
|
-
isError: PropTypes.bool,
|
|
509
|
-
errorMessage: PropTypes.string,
|
|
510
|
-
popoverClassName: PropTypes.string,
|
|
511
|
-
showUpload: PropTypes.bool,
|
|
512
|
-
onUpload: PropTypes.func,
|
|
513
|
-
clearText: PropTypes.string,
|
|
514
|
-
noResultCustomText: PropTypes.string,
|
|
515
|
-
noResultCustomIcon: PropTypes.string,
|
|
516
113
|
};
|
|
517
114
|
|
|
518
115
|
CapUnifiedSelect.defaultProps = {
|
|
519
|
-
type:
|
|
520
|
-
placeholder: 'Select an option',
|
|
521
|
-
searchBasedOn: 'label',
|
|
522
|
-
noResultCustomText: 'No results found',
|
|
523
|
-
noResultCustomIcon: 'warning',
|
|
524
|
-
clearText: 'Clear',
|
|
525
|
-
options: [],
|
|
116
|
+
type: 'select',
|
|
526
117
|
allowClear: false,
|
|
527
|
-
|
|
528
|
-
showSearch: true,
|
|
529
|
-
className: '',
|
|
530
|
-
disabled: false,
|
|
531
|
-
readOnly: false,
|
|
532
|
-
showUpload: false,
|
|
533
|
-
isError: false,
|
|
534
|
-
onUpload: () => {},
|
|
535
|
-
onChange: () => {},
|
|
536
|
-
onConfirm: () => {},
|
|
118
|
+
showSearch: false,
|
|
537
119
|
};
|
|
538
120
|
|
|
539
|
-
export default
|
|
121
|
+
export default CapUnifiedSelect;
|