@capillarytech/blaze-ui 0.1.6-alpha.37 → 0.1.6-alpha.38

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/.DS_Store ADDED
Binary file
@@ -11,6 +11,10 @@ import { InfoCircleOutlined, SearchOutlined, WarningFilled, DownOutlined } from
11
11
  import withStyles from '../utils/withStyles';
12
12
  import { SelectWrapper, HeaderWrapper, selectStyles } from './styles';
13
13
 
14
+ const StyledTreeSelect = styled(TreeSelect)`
15
+ ${selectStyles}
16
+ `;
17
+
14
18
  const CapUnifiedSelect = ({
15
19
  type,
16
20
  options = [],
@@ -35,13 +39,11 @@ const CapUnifiedSelect = ({
35
39
  onCancel,
36
40
  ...rest
37
41
  }) => {
38
- const StyledTreeSelect = styled(TreeSelect)`
39
- ${selectStyles}
40
- `;
41
42
 
42
43
  const [searchText, setSearchText] = useState('');
43
44
  const [tempValue, setTempValue] = useState(value);
44
45
  const [allSelected, setAllSelected] = useState(false);
46
+ const [dropdownOpen, setDropdownOpen] = useState(false);
45
47
 
46
48
  useEffect(() => {
47
49
  setTempValue(value);
@@ -100,9 +102,17 @@ const CapUnifiedSelect = ({
100
102
  const leafValues = flattenLeafValues(filteredTree);
101
103
 
102
104
  const handleSelectAll = () => {
105
+ console.log('Select All clicked');
103
106
  const availableValues = leafValues;
104
- setTempValue(allSelected ? [] : availableValues);
105
- setAllSelected(!allSelected);
107
+ if (allSelected) {
108
+ // If currently all selected, then unselect all
109
+ setTempValue([]);
110
+ setAllSelected(false);
111
+ } else {
112
+ // Otherwise select all available options
113
+ setTempValue(availableValues);
114
+ setAllSelected(true);
115
+ }
106
116
  };
107
117
 
108
118
  useEffect(() => {
@@ -112,20 +122,27 @@ const CapUnifiedSelect = ({
112
122
  }, [tempValue, leafValues, isMulti]);
113
123
 
114
124
  const handleConfirm = () => {
115
- if (onConfirm) onConfirm(tempValue);
116
- else onChange(tempValue);
117
- setSearchText('');
125
+ console.log('Confirm clicked');
126
+ if (onChange) onChange(tempValue);
127
+ setDropdownOpen(false);
118
128
  };
119
129
 
120
130
  const handleCancel = () => {
121
- if (onCancel) onCancel();
131
+ console.log('Cancel clicked');
122
132
  setTempValue(value);
123
- setSearchText('');
133
+ setDropdownOpen(false);
124
134
  };
125
135
 
126
136
  const handleTempChange = newValue => {
127
137
  setTempValue(newValue);
128
138
  };
139
+
140
+ const handleDropdownVisibilityChange = open => {
141
+ if (!open) {
142
+ setTempValue(value);
143
+ }
144
+ setDropdownOpen(open);
145
+ };
129
146
 
130
147
  const suffix = isMulti && Array.isArray(value) && value?.length > 1 ? (
131
148
  <>
@@ -164,7 +181,11 @@ const CapUnifiedSelect = ({
164
181
 
165
182
  const renderDropdown = () => {
166
183
  const currentItems = filteredTree;
167
- const selectedCount = Array.isArray(tempValue) ? tempValue.length : (tempValue ? 1 : 0);
184
+ const selectedCount = Array.isArray(tempValue)
185
+ ? isTree
186
+ ? tempValue.filter(val => leafValues.includes(val)).length
187
+ : tempValue.length
188
+ : (tempValue ? 1 : 0);
168
189
 
169
190
  const renderCustomDropdown = menu => {
170
191
  if (!customPopupRender) return menu;
@@ -180,7 +201,7 @@ const CapUnifiedSelect = ({
180
201
  value={searchText}
181
202
  onChange={e => setSearchText(e.target.value)}
182
203
  onKeyDown={e => e.stopPropagation()}
183
- />
204
+ />
184
205
  </div>
185
206
  )}
186
207
  {isMulti && showUpload && (
@@ -204,7 +225,7 @@ const CapUnifiedSelect = ({
204
225
  )}
205
226
  {isMulti && currentItems.length > 0 && (
206
227
  <div style={{ padding: '8px 12px', cursor: 'pointer', display: 'flex', alignItems: 'center', borderBottom: '1px solid #f0f0f0' }} onClick={e => { e.stopPropagation(); handleSelectAll(); }}>
207
- <input type="checkbox" checked={allSelected} readOnly style={{ cursor: 'pointer' }} onClick={e => e.stopPropagation()} />
228
+ <input type="checkbox" checked={allSelected} readOnly style={{ cursor: 'pointer' }} onClick={e => e.stopPropagation()} />
208
229
  <label style={{ marginLeft: 8, cursor: 'pointer' }}>Select all</label>
209
230
  </div>
210
231
  )}
@@ -247,6 +268,8 @@ const CapUnifiedSelect = ({
247
268
  virtual
248
269
  disabled={disabled}
249
270
  filterTreeNode={false}
271
+ open={dropdownOpen}
272
+ onOpenChange={handleDropdownVisibilityChange}
250
273
  {...treeSelectVirtualizationProps}
251
274
  popupRender={renderCustomDropdown}
252
275
  />
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.37",
4
+ "version": "0.1.6-alpha.38",
5
5
  "description": "Capillary UI component library with Ant Design v5",
6
6
  "main": "./index.js",
7
7
  "sideEffects": [