@capillarytech/blaze-ui 0.1.6-alpha.45 → 0.1.6-alpha.47

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.
@@ -36,6 +36,7 @@ const CapUnifiedSelect = ({
36
36
  searchBasedOn = 'label',
37
37
  onConfirm,
38
38
  onCancel,
39
+ size = 'm',
39
40
  noResultCustomText = 'No results found',
40
41
  noResultCustomIcon = 'warning',
41
42
  ...rest
@@ -51,19 +52,19 @@ const CapUnifiedSelect = ({
51
52
  setTempValue(value);
52
53
  }, [value]);
53
54
 
54
- const treeSelectVirtualizationProps = {
55
- listHeight: 256,
55
+ const treeSelectVirtualizationProps = useMemo(() => ({
56
+ listHeight: 256,
56
57
  listItemHeight: 32,
57
- };
58
+ }), []);
58
59
 
59
- const NoResult = memo(({ noResultCustomText, className }) => (
60
+ const NoResult = memo(({ noResultCustomText, className, showUpload, options }) => (
60
61
  <CapRow
61
62
  className={classnames(className, "cap-unified-select-no-result")}
62
63
  align="middle"
63
64
  gap={8}
64
65
  >
65
66
  <CapIcon type={noResultCustomIcon} size="m" />
66
- <CapLabel className="cap-unified-select-no-result-text">{showUpload && options.length === 0 ? noResultCustomText : 'No results found'}</CapLabel>
67
+ <CapLabel className="cap-unified-select-no-result-text">{showUpload && options?.length === 0 ? noResultCustomText : 'No results found'}</CapLabel>
67
68
  </CapRow>
68
69
  ));
69
70
 
@@ -71,14 +72,15 @@ const CapUnifiedSelect = ({
71
72
  if (!search) return data;
72
73
 
73
74
  const filterNode = node => {
75
+ if (!node) return false;
74
76
  if (searchBasedOn === 'value') {
75
- const valueText = String(node.value || '').toLowerCase();
77
+ const valueText = String(node?.value || '').toLowerCase();
76
78
  return valueText.includes(search.toLowerCase());
77
79
  } else if (searchBasedOn === 'key') {
78
- const keyText = String(node.key || '').toLowerCase();
80
+ const keyText = String(node?.key || '').toLowerCase();
79
81
  return keyText.includes(search.toLowerCase());
80
82
  } else {
81
- const labelText = node.label?.toLowerCase() || '';
83
+ const labelText = node?.label?.toLowerCase() || '';
82
84
  return labelText.includes(search.toLowerCase());
83
85
  }
84
86
  };
@@ -96,13 +98,13 @@ const CapUnifiedSelect = ({
96
98
  }, [searchBasedOn]);
97
99
 
98
100
  const flattenLeafValues = useCallback(nodes =>
99
- nodes?.flatMap(node => node.children ? flattenLeafValues(node.children) : [node.value]) || [], []);
101
+ nodes?.flatMap(node => node?.children ? flattenLeafValues(node.children) : [node?.value]) || [], []);
100
102
 
101
103
  const isMulti = useMemo(() => type === 'multiSelect' || type === 'multiTreeSelect', [type]);
102
104
  const isTree = useMemo(() => type === 'treeSelect' || type === 'multiTreeSelect', [type]);
103
105
 
104
106
  const dataSource = useMemo(() => {
105
- return isTree ? options : options.map(opt => ({ title: opt.label, value: opt.value, key: opt.key || opt.value }));
107
+ return isTree ? options : options?.map(opt => ({ title: opt?.label, value: opt?.value, key: opt?.key || opt?.value }));
106
108
  }, [isTree, options]);
107
109
 
108
110
  const filteredTree = useMemo(() => getFilteredTreeData(dataSource, searchText), [dataSource, searchText]);
@@ -140,12 +142,12 @@ const CapUnifiedSelect = ({
140
142
  setTempValue(newValue);
141
143
  }, []);
142
144
 
143
- const handleDropdownVisibilityChange = open => {
144
- if (!open) {
145
+ const handleDropdownVisibilityChange = useCallback(open => {
146
+ if (open === false) {
145
147
  setTempValue(value);
146
148
  }
147
149
  setDropdownOpen(open);
148
- };
150
+ }, [value]);
149
151
 
150
152
  const suffix = useMemo(() => {
151
153
  const displayValue = dropdownOpen ? tempValue : value;
@@ -162,12 +164,12 @@ const CapUnifiedSelect = ({
162
164
  if (isMulti) {
163
165
  if (Array.isArray(tempValue) && tempValue?.length > 0) {
164
166
  const firstSelectedValue = tempValue[0];
165
- const firstSelectedOption = options.find(opt => opt.value === firstSelectedValue);
167
+ const firstSelectedOption = options?.find(opt => opt?.value === firstSelectedValue);
166
168
  return firstSelectedOption?.label || null;
167
169
  }
168
170
  else if (Array.isArray(value) && value?.length > 0) {
169
171
  const firstSelectedValue = value[0];
170
- const firstSelectedOption = options.find(opt => opt.value === firstSelectedValue);
172
+ const firstSelectedOption = options?.find(opt => opt?.value === firstSelectedValue);
171
173
  return firstSelectedOption?.label || null;
172
174
  }
173
175
  }
@@ -195,15 +197,15 @@ const CapUnifiedSelect = ({
195
197
  );
196
198
  }, [headerLabel, tooltip, bylineText, disabled]);
197
199
 
198
- const renderDropdown = () => {
200
+ const renderDropdown = useCallback(() => {
199
201
  const currentItems = filteredTree;
200
202
  const selectedCount = Array.isArray(tempValue)
201
203
  ? isTree
202
- ? tempValue.filter(val => leafValues.includes(val)).length
203
- : tempValue.length
204
+ ? tempValue?.filter(val => leafValues?.includes(val))?.length || 0
205
+ : tempValue?.length || 0
204
206
  : (tempValue ? 1 : 0);
205
207
 
206
- const renderCustomDropdown = menu => {
208
+ const renderCustomDropdown = useCallback(menu => {
207
209
  if (!customPopupRender) return menu;
208
210
 
209
211
  return (
@@ -237,7 +239,7 @@ const CapUnifiedSelect = ({
237
239
  </CapRow>
238
240
  )}
239
241
 
240
- {currentItems.length === 0 ? <NoResult noResultCustomText={noResultCustomText} className={classnames(className, "cap-unified-select-no-result")}/> : menu}
242
+ {currentItems.length === 0 ? <NoResult noResultCustomText={noResultCustomText} className={classnames(className, "cap-unified-select-no-result")} showUpload={showUpload} options={options}/> : menu}
241
243
 
242
244
  {currentItems.length > 0 && isMulti && (
243
245
  <div className="cap-unified-select-confirm-container">
@@ -267,7 +269,7 @@ const CapUnifiedSelect = ({
267
269
  )}
268
270
  </div>
269
271
  );
270
- };
272
+ }, [customPopupRender, popupClassName, type, showSearch, searchText, isMulti, showUpload, currentItems?.length, allSelected, className, noResultCustomText, onUpload, handleSelectAll, handleConfirm, handleCancel]);
271
273
 
272
274
  return (
273
275
  <>
@@ -301,7 +303,7 @@ const CapUnifiedSelect = ({
301
303
  {isError && <CapLabel className={classnames("cap-unified-select-status")} style={{ color: 'red' }}>{errorMessage}</CapLabel>}
302
304
  </>
303
305
  );
304
- };
306
+ }, [filteredTree, tempValue, value, prefix, suffix, className, style, isError, errorMessage, allowClear, isMulti, dropdownOpen, customPopupRender, handleTempChange, onChange, disabled, handleDropdownVisibilityChange, treeSelectVirtualizationProps]);
305
307
 
306
308
  return (
307
309
  <SelectWrapper className={classnames(className, 'cap-unified-select-container')}>
@@ -348,8 +350,12 @@ CapUnifiedSelect.defaultProps = {
348
350
  disabled: false,
349
351
  showUpload: false,
350
352
  isError: false,
351
- noResultText: 'No results found',
352
- onUpload: () => {}
353
+ noResultCustomText: 'No results found',
354
+ noResultCustomIcon: 'warning',
355
+ onUpload: () => {},
356
+ onChange: () => {},
357
+ onConfirm: () => {},
358
+ onCancel: () => {}
353
359
  };
354
360
 
355
361
  export default withStyles(CapUnifiedSelect, selectStyles);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/blaze-ui",
3
3
  "author": "Capillary Technologies",
4
- "version": "0.1.6-alpha.45",
4
+ "version": "0.1.6-alpha.47",
5
5
  "description": "Capillary UI component library with Ant Design v5",
6
6
  "main": "./index.js",
7
7
  "sideEffects": [