diginet-core-ui 1.3.78 → 1.3.79
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/components/accordion/details.js +2 -6
- package/components/accordion/group.js +2 -9
- package/components/accordion/index.js +2 -15
- package/components/accordion/summary.js +4 -27
- package/components/alert/index.js +98 -137
- package/components/alert/notify.js +97 -166
- package/components/avatar/index.js +4 -63
- package/components/badge/index.js +7 -34
- package/components/button/icon.js +120 -186
- package/components/button/index.js +136 -205
- package/components/button/more.js +0 -12
- package/components/button/ripple-effect.js +46 -44
- package/components/card/body.js +2 -7
- package/components/card/extra.js +2 -7
- package/components/card/footer.js +2 -7
- package/components/card/header.js +2 -7
- package/components/card/index.js +2 -22
- package/components/chart/Pie/Circle.js +0 -1
- package/components/chart/Pie/Sector.js +0 -17
- package/components/chart/Pie/Sectors.js +0 -10
- package/components/chart/Pie/index.js +4 -36
- package/components/chart/Pie-v2/Circle.js +0 -1
- package/components/chart/Pie-v2/Sector.js +0 -13
- package/components/chart/Pie-v2/Sectors.js +0 -20
- package/components/chart/Pie-v2/index.js +11 -38
- package/components/chart/bar/Axis.js +0 -12
- package/components/chart/bar/Bar.js +13 -35
- package/components/chart/bar/Grid.js +0 -18
- package/components/chart/bar/Labels.js +0 -18
- package/components/chart/bar/Points.js +0 -17
- package/components/chart/bar/index.js +6 -26
- package/components/chart/bar-v2/Axis.js +0 -12
- package/components/chart/bar-v2/Bar.js +15 -36
- package/components/chart/bar-v2/Grid.js +0 -18
- package/components/chart/bar-v2/Labels.js +0 -18
- package/components/chart/bar-v2/Points.js +0 -17
- package/components/chart/bar-v2/index.js +6 -26
- package/components/chart/line/Axis.js +4 -16
- package/components/chart/line/Grid.js +2 -19
- package/components/chart/line/Labels.js +0 -18
- package/components/chart/line/Path.js +23 -33
- package/components/chart/line/Point.js +6 -40
- package/components/chart/line/Title.js +0 -3
- package/components/chart/line/index.js +12 -35
- package/components/chart/line-v2/Axis.js +0 -13
- package/components/chart/line-v2/Grid.js +0 -18
- package/components/chart/line-v2/Labels.js +0 -18
- package/components/chart/line-v2/Path.js +23 -33
- package/components/chart/line-v2/Point.js +6 -35
- package/components/chart/line-v2/Title.js +0 -3
- package/components/chart/line-v2/index.js +12 -30
- package/components/check-text/index.js +0 -8
- package/components/check-text/interview-confirmation.js +0 -7
- package/components/check-text/interview-status.js +0 -7
- package/components/chip/attach.js +4 -17
- package/components/chip/index.js +6 -33
- package/components/collapse/index.js +0 -13
- package/components/divider/index.js +0 -8
- package/components/form-control/attachment/index.js +24 -202
- package/components/form-control/calendar/function.js +40 -94
- package/components/form-control/calendar/index.js +5 -30
- package/components/form-control/calendar/range.js +11 -28
- package/components/form-control/checkbox/index.js +4 -37
- package/components/form-control/control/index.js +3 -13
- package/components/form-control/date-picker/index-old.js +18 -0
- package/components/form-control/date-picker/index.js +23 -99
- package/components/form-control/date-range-picker/index.js +86 -221
- package/components/form-control/dropdown/index.js +72 -289
- package/components/form-control/dropdown-box/index.js +6 -35
- package/components/form-control/form/index.js +0 -2
- package/components/form-control/form-group/index.js +1 -6
- package/components/form-control/helper-text/index.js +2 -9
- package/components/form-control/input-base/index.js +218 -399
- package/components/form-control/label/index.js +2 -12
- package/components/form-control/money-input/index.js +43 -132
- package/components/form-control/number-input/index.js +15 -113
- package/components/form-control/number-input/index2.js +78 -119
- package/components/form-control/phone-input/index.js +16 -78
- package/components/form-control/radio/index.js +4 -23
- package/components/form-control/text-input/index.js +33 -256
- package/components/form-control/time-picker/index.js +14 -71
- package/components/form-control/time-picker/swiper.js +21 -73
- package/components/form-control/toggle/index.js +4 -19
- package/components/form-view/helper-text.js +2 -2
- package/components/form-view/index.js +0 -14
- package/components/form-view/input.js +2 -13
- package/components/form-view/label.js +0 -2
- package/components/grid/Col.js +2 -15
- package/components/grid/Container.js +2 -21
- package/components/grid/Row.js +2 -21
- package/components/grid/index.js +2 -43
- package/components/image/index.js +2 -22
- package/components/index.js +62 -31
- package/components/list/list-item-action.js +0 -9
- package/components/list/list-item-icon.js +0 -9
- package/components/list/list-item-text.js +0 -5
- package/components/list/list-item.js +0 -11
- package/components/list/list.js +0 -13
- package/components/list/sub-header.js +0 -4
- package/components/modal/body.js +2 -6
- package/components/modal/footer.js +2 -11
- package/components/modal/header.js +2 -12
- package/components/modal/index.js +2 -10
- package/components/modal/modal.js +11 -52
- package/components/others/extra/index.js +3 -10
- package/components/others/import/index.js +0 -7
- package/components/others/option-wrapper/index.js +4 -7
- package/components/others/scrollbar/index.js +0 -3
- package/components/paging/page-info.js +39 -101
- package/components/paging/page-selector.js +7 -35
- package/components/paging/page-selector2.js +35 -74
- package/components/paper/index.js +0 -11
- package/components/popover/body.js +2 -6
- package/components/popover/footer.js +2 -11
- package/components/popover/header.js +2 -7
- package/components/popover/index.js +39 -123
- package/components/popup/danger_popup.js +0 -19
- package/components/popup/index.js +2 -48
- package/components/popup/proposals_popup.js +10 -49
- package/components/popup/v2/index.js +0 -31
- package/components/progress/circular.js +19 -81
- package/components/progress/linear.js +4 -20
- package/components/rating/index.js +0 -24
- package/components/slider/slider-container.js +3 -40
- package/components/slider/slider-item.js +10 -25
- package/components/status/index.js +2 -16
- package/components/tab/tab-container.js +2 -16
- package/components/tab/tab-header.js +4 -24
- package/components/tab/tab-panel.js +4 -16
- package/components/tab/tab.js +4 -28
- package/components/tooltip/index.js +12 -97
- package/components/tooltip/portal.js +0 -2
- package/components/transfer/index.js +22 -67
- package/components/tree-view/index.js +62 -202
- package/components/typography/index.js +3 -31
- package/global/index.js +0 -8
- package/icons/basic.js +0 -48
- package/icons/effect.js +17 -29
- package/icons/general/clock/clock.js +0 -2
- package/icons/general/color-handler/background.js +0 -2
- package/icons/general/color-handler/text.js +0 -2
- package/icons/general/emoji/emoji.js +0 -2
- package/icons/general/font-properties/bold.js +0 -2
- package/icons/general/font-properties/font-family.js +0 -2
- package/icons/general/font-properties/font-size.js +0 -2
- package/icons/general/font-properties/italic.js +0 -2
- package/icons/general/font-properties/underline.js +0 -2
- package/icons/general/hyperlink/hyperlink.js +0 -2
- package/icons/general/indent/decrease.js +0 -2
- package/icons/general/indent/increase.js +0 -2
- package/icons/general/list/bullets.js +0 -2
- package/icons/general/list/numbering.js +0 -2
- package/icons/general/picture/picture.js +0 -2
- package/icons/general/steps/redo.js +0 -2
- package/icons/general/steps/undo.js +0 -2
- package/icons/general/text-align/center.js +0 -2
- package/icons/general/text-align/justify.js +0 -2
- package/icons/general/text-align/left.js +0 -2
- package/icons/general/text-align/right.js +0 -2
- package/icons/menu/dhr.js +2 -1
- package/icons/menu/index.js +2 -2
- package/icons/menu/v2/index.js +0 -10
- package/package.json +1 -1
- package/readme.md +11 -1
- package/styles/animation.js +15 -58
- package/styles/color-helper.js +24 -54
- package/styles/colors.js +17 -9
- package/styles/general.js +6 -2
- package/styles/typography.js +4 -4
- package/styles/utils.js +2 -2
- package/theme/createBreakpoints.js +7 -18
- package/theme/make-styles.js +2 -5
- package/theme/set-theme.js +3 -6
- package/theme/settings.js +3 -2
- package/theme/theme-provider.js +0 -1
- package/utils/array/array.js +14 -23
- package/utils/classNames.js +0 -5
- package/utils/console.js +0 -6
- package/utils/date.js +13 -82
- package/utils/error/error.js +1 -9
- package/utils/error/errors.js +1 -48
- package/utils/getFileType.js +0 -9
- package/utils/handleBreakpoints.js +0 -5
- package/utils/intersectionObserver.js +0 -5
- package/utils/iterator.js +0 -9
- package/utils/map-parent.js +3 -10
- package/utils/object/extend.js +0 -10
- package/utils/object/object.js +12 -11
- package/utils/parseHTML.js +0 -1
- package/utils/promisify.js +0 -5
- package/utils/randomString.js +0 -7
- package/utils/remove-unicode.js +0 -1
- package/utils/render-portal.js +1 -9
- package/utils/renderHTML.js +4 -6
- package/utils/renderIcon.js +4 -14
- package/utils/sb-template.js +6 -5
- package/utils/string/capitalize.js +0 -1
- package/utils/string/capitalizeSentenceCase.js +0 -2
- package/utils/string/string.js +0 -13
- package/utils/type.js +0 -21
- package/utils/updatePosition.js +4 -5
- package/utils/useDelayUnmount.js +0 -4
- package/utils/useElementSize.js +9 -3
- package/utils/useEventListener.js +12 -6
- package/utils/useInput.js +0 -6
- package/utils/useMediaQuery.js +8 -10
- package/utils/useOnClickOutside.js +0 -2
- package/utils/usePortal.js +3 -10
- package/utils/validate.js +6 -20
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { Fragment, memo, useState, useEffect, useMemo, useRef, useImperativeHandle, forwardRef } from 'react';
|
|
5
4
|
import ReactDOM from 'react-dom';
|
|
@@ -44,26 +43,22 @@ const {
|
|
|
44
43
|
zIndex: zIndexCORE
|
|
45
44
|
} = theme;
|
|
46
45
|
const timing = {},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
currentValue = {},
|
|
47
|
+
currentObjectDefault = {},
|
|
48
|
+
isSearch = {},
|
|
49
|
+
allValue = {};
|
|
51
50
|
const separatorPattern = /\{\w+\}/g;
|
|
52
51
|
const regexBetween = /[^{\}]+(?=})/g; // eslint-disable-line
|
|
53
|
-
|
|
54
52
|
const regexInclude = /{|}/g;
|
|
55
|
-
|
|
56
53
|
const checkHasValue = value => {
|
|
57
54
|
return Array.isArray(value) ? value.length > 0 : value === 0 || !!value;
|
|
58
55
|
};
|
|
59
|
-
|
|
60
56
|
const convertData = (dt, valueExpr) => {
|
|
61
57
|
let data = dt || [];
|
|
62
58
|
let valueTemp = Array.isArray(data) ? data : [data];
|
|
63
59
|
valueTemp = valueTemp.map(i => i[valueExpr] || i);
|
|
64
60
|
return valueTemp;
|
|
65
61
|
};
|
|
66
|
-
|
|
67
62
|
const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
68
63
|
viewType,
|
|
69
64
|
itemMode,
|
|
@@ -137,36 +132,26 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
137
132
|
const [openState, setOpenState] = useState(false);
|
|
138
133
|
const [showClear, setShowClear] = useState(false);
|
|
139
134
|
const [textValue, setTextValue] = useState('');
|
|
140
|
-
let valueTemp = valueProp || defaultValue || [];
|
|
135
|
+
let valueTemp = valueProp || defaultValue || [];
|
|
141
136
|
|
|
137
|
+
// only mode multi
|
|
142
138
|
if (multiple) {
|
|
143
139
|
valueTemp = convertData(valueTemp, valueExpr);
|
|
144
140
|
}
|
|
145
|
-
|
|
146
141
|
const [valueMulti, setValueMulti] = useState(valueTemp);
|
|
147
|
-
|
|
148
142
|
const _isMobile = isMobile.any();
|
|
149
|
-
|
|
150
143
|
const _InputCSS = InputCSS(multiple, typeof renderSelectedItem === 'function');
|
|
151
|
-
|
|
152
144
|
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, typeof renderSelectedItem === 'function', disabled);
|
|
153
|
-
|
|
154
145
|
const _IconCSS = IconCSS(viewType, loading, showClear);
|
|
155
|
-
|
|
156
146
|
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, disabled, placeholder, _DropdownInputCSS.name);
|
|
157
|
-
|
|
158
147
|
const _DropdownListCSS = DropdownListCSS(loading);
|
|
159
|
-
|
|
160
148
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
161
|
-
|
|
162
149
|
const _DropdownRootCSS = DropdownRootCSS(_DropdownFormCSS.name, _IconCSS.name, _DropdownInputCSS.name);
|
|
163
|
-
/* Start handler */
|
|
164
|
-
|
|
165
150
|
|
|
151
|
+
/* Start handler */
|
|
166
152
|
const triggerInput = e => {
|
|
167
153
|
const target = e.currentTarget;
|
|
168
154
|
target.style.pointerEvents = 'none';
|
|
169
|
-
|
|
170
155
|
if (!dropdownListRef.current) {
|
|
171
156
|
onClickInput();
|
|
172
157
|
} else {
|
|
@@ -174,32 +159,26 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
174
159
|
target: null
|
|
175
160
|
});
|
|
176
161
|
}
|
|
177
|
-
|
|
178
162
|
setTimeout(() => {
|
|
179
163
|
target.style.pointerEvents = null;
|
|
180
164
|
}, 200);
|
|
181
165
|
};
|
|
182
|
-
|
|
183
166
|
const triggerBlur = (blur = true) => {
|
|
184
167
|
if ((currentValue[unique] || currentValue[unique] === 0) && !multiple) {
|
|
185
168
|
setValueIntoInput(currentValue[unique]);
|
|
186
169
|
} else if (!multiple) {
|
|
187
170
|
setValueIntoInput('');
|
|
188
171
|
}
|
|
189
|
-
|
|
190
172
|
!!blur && inputRef.current.blur();
|
|
191
173
|
};
|
|
192
|
-
|
|
193
174
|
const onClickInput = e => {
|
|
194
175
|
if (disabled || readOnly || loading) return;
|
|
195
|
-
|
|
196
176
|
if (!dropdownListRef.current) {
|
|
197
177
|
if (!multiple || !Array.from(inputRef.current.querySelectorAll('.DGN-UI-Chip')).some(item => item.contains(e === null || e === void 0 ? void 0 : e.target))) {
|
|
198
178
|
if ((typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none') && !multiple) {
|
|
199
179
|
var _inputRef$current$chi;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
180
|
+
inputRef.current.innerHTML = inputRef.current.textContent.trim();
|
|
181
|
+
// if (!allowSearch) inputRef.current.contentEditable = true;
|
|
203
182
|
const caret = (_inputRef$current$chi = inputRef.current.childNodes) !== null && _inputRef$current$chi !== void 0 && _inputRef$current$chi.length ? 1 : 0;
|
|
204
183
|
const range = document.createRange();
|
|
205
184
|
range.setStart(inputRef.current, caret);
|
|
@@ -208,7 +187,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
208
187
|
sel.removeAllRanges();
|
|
209
188
|
sel.addRange(range);
|
|
210
189
|
}
|
|
211
|
-
|
|
212
190
|
setOpenState(true);
|
|
213
191
|
}
|
|
214
192
|
} else if (multiple || itemMode === 'treeview') {
|
|
@@ -219,23 +197,18 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
219
197
|
}
|
|
220
198
|
}
|
|
221
199
|
};
|
|
222
|
-
|
|
223
200
|
const onClickOutsideOfInput = event => {
|
|
224
201
|
var _inputRef$current, _iconRef$current, _dropdownListRef$curr, _dropdownListRef$curr2, _dropdownListRef$curr3;
|
|
225
|
-
|
|
226
202
|
if (inputRef.current && !((_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.contains(event === null || event === void 0 ? void 0 : event.target)) && iconRef.current && !((_iconRef$current = iconRef.current) !== null && _iconRef$current !== void 0 && _iconRef$current.contains(event === null || event === void 0 ? void 0 : event.target)) && dropdownListRef.current && !((_dropdownListRef$curr = dropdownListRef.current) !== null && _dropdownListRef$curr !== void 0 && (_dropdownListRef$curr2 = _dropdownListRef$curr.parentNode) !== null && _dropdownListRef$curr2 !== void 0 && (_dropdownListRef$curr3 = _dropdownListRef$curr2.parentNode) !== null && _dropdownListRef$curr3 !== void 0 && _dropdownListRef$curr3.contains(event === null || event === void 0 ? void 0 : event.target))) {
|
|
227
203
|
closeDropdown();
|
|
228
204
|
triggerBlur(false);
|
|
229
205
|
}
|
|
230
206
|
};
|
|
231
|
-
|
|
232
207
|
const showDropdown = () => {
|
|
233
208
|
var _displayExpr, _searchRef$current;
|
|
234
|
-
|
|
235
209
|
if (displayExpr && Array.isArray(displayExpr)) {
|
|
236
210
|
displayExpr = displayExpr.join(' - ');
|
|
237
211
|
}
|
|
238
|
-
|
|
239
212
|
const keyArr = (_displayExpr = displayExpr) === null || _displayExpr === void 0 ? void 0 : _displayExpr.match(separatorPattern);
|
|
240
213
|
const dropdown = children ? jsx("div", {
|
|
241
214
|
css: _DropdownListCSS,
|
|
@@ -250,11 +223,11 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
250
223
|
left,
|
|
251
224
|
height,
|
|
252
225
|
width
|
|
253
|
-
} = formRef.current.getBoundingClientRect();
|
|
226
|
+
} = formRef.current.getBoundingClientRect();
|
|
254
227
|
|
|
228
|
+
// Calculate to set position of Dropdown box
|
|
255
229
|
const dropdownHeight = Math.min(Math.max(1, (itemMode === 'normal' ? dropdown.props.children : mapParent(dataSource, treeViewID, treeViewParentID)).length || 1), 7) * 40 + (multiple ? 43 : 0);
|
|
256
230
|
let positionTop = top + height + 4;
|
|
257
|
-
|
|
258
231
|
if (top + height + 4 + dropdownHeight + (allowSearch ? 40 : 0) > innerHeight) {
|
|
259
232
|
if (top - dropdownHeight > 0) {
|
|
260
233
|
positionTop = top - dropdownHeight;
|
|
@@ -262,11 +235,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
262
235
|
positionTop = innerHeight - dropdownHeight;
|
|
263
236
|
}
|
|
264
237
|
}
|
|
265
|
-
|
|
266
238
|
const defaultSearch = lastSearchRef.current || (onInput ? (_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 ? void 0 : _searchRef$current.value : '');
|
|
267
|
-
|
|
268
239
|
const _DropdownCSS = DropdownCSS(positionTop, left, width, _isMobile, allowSearch);
|
|
269
|
-
|
|
270
240
|
const el = jsx("div", {
|
|
271
241
|
css: _DropdownCSS,
|
|
272
242
|
ref: dropdownRef,
|
|
@@ -296,35 +266,29 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
296
266
|
}, jsx(CircularProgress, {
|
|
297
267
|
size: 'xs'
|
|
298
268
|
})));
|
|
299
|
-
|
|
300
269
|
if (!((multiple || allowSearch) && itemMode === 'normal' && !children)) {
|
|
301
270
|
inputRef.current.addEventListener('keydown', pressESCHandler);
|
|
302
271
|
}
|
|
303
|
-
|
|
304
272
|
document.documentElement.style.overflow = 'hidden';
|
|
305
273
|
setTimeout(() => {
|
|
306
274
|
window.addEventListener('resize', customizeWidthDropdown);
|
|
307
275
|
document.addEventListener('wheel', onWheelHandler);
|
|
308
276
|
document.addEventListener('mousedown', onClickOutsideOfInput);
|
|
309
277
|
dropdownListRef.current && dropdownListRef.current.addEventListener('keydown', moveOnItem);
|
|
310
|
-
|
|
311
278
|
if (onLoadMore && dataSource.length < total) {
|
|
312
279
|
dropdownListRef.current && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
313
280
|
}
|
|
314
281
|
}, 10);
|
|
315
282
|
return el;
|
|
316
283
|
};
|
|
317
|
-
|
|
318
284
|
const moveOnItem = e => {
|
|
319
285
|
if (e.key === 'Escape' || e.key === 'Tab') {
|
|
320
286
|
closeDropdown();
|
|
321
287
|
triggerBlur();
|
|
322
288
|
}
|
|
323
|
-
|
|
324
289
|
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
325
290
|
let activeEl = document.activeElement;
|
|
326
291
|
activeEl = e.key === 'ArrowDown' ? activeEl.nextElementSibling : activeEl.previousElementSibling;
|
|
327
|
-
|
|
328
292
|
if (activeEl) {
|
|
329
293
|
activeEl.focus();
|
|
330
294
|
activeEl.scrollIntoView({
|
|
@@ -334,7 +298,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
334
298
|
}
|
|
335
299
|
}
|
|
336
300
|
};
|
|
337
|
-
|
|
338
301
|
const pressESCHandler = e => {
|
|
339
302
|
if (e.key === 'Escape' || e.key === 'Tab') {
|
|
340
303
|
closeDropdown();
|
|
@@ -344,21 +307,17 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
344
307
|
dropdownListRef.current.firstChild.focus();
|
|
345
308
|
}
|
|
346
309
|
};
|
|
347
|
-
|
|
348
310
|
const onWheelHandler = e => {
|
|
349
311
|
var _dropdownRef$current;
|
|
350
|
-
|
|
351
312
|
if (!dropdownRef.current) {
|
|
352
313
|
document.removeEventListener('wheel', onWheelHandler);
|
|
353
314
|
return;
|
|
354
315
|
}
|
|
355
|
-
|
|
356
316
|
if (!((_dropdownRef$current = dropdownRef.current) !== null && _dropdownRef$current !== void 0 && _dropdownRef$current.contains(e.target))) {
|
|
357
317
|
closeDropdown();
|
|
358
318
|
triggerBlur();
|
|
359
319
|
}
|
|
360
320
|
};
|
|
361
|
-
|
|
362
321
|
const closeDropdown = () => {
|
|
363
322
|
if (dropdownRef.current) {
|
|
364
323
|
// dropdownRef.current.style.pointerEvents = `none`;
|
|
@@ -374,80 +333,64 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
374
333
|
document.removeEventListener('mousedown', onClickOutsideOfInput);
|
|
375
334
|
window.removeEventListener('resize', customizeWidthDropdown);
|
|
376
335
|
document.removeEventListener('wheel', onWheelHandler);
|
|
377
|
-
|
|
378
336
|
if (onLoadMore && dropdownListRef.current) {
|
|
379
337
|
dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
380
338
|
dropdownListRef.current = null;
|
|
381
|
-
}
|
|
339
|
+
}
|
|
340
|
+
// if (!multiple) {
|
|
382
341
|
// inputRef.current.removeEventListener('keydown', pressESCHandler);
|
|
383
342
|
// inputRef.current.removeEventListener('input', onChangeInput);
|
|
384
343
|
// }
|
|
385
|
-
|
|
386
344
|
}
|
|
387
345
|
|
|
388
346
|
document.documentElement.style.overflow = 'auto';
|
|
389
347
|
if (searchRef.current) lastSearchRef.current = '';
|
|
390
348
|
onClosed === null || onClosed === void 0 ? void 0 : onClosed();
|
|
391
349
|
};
|
|
392
|
-
|
|
393
350
|
const renderDropdown = pattern => {
|
|
394
351
|
var _displayExpr2;
|
|
395
|
-
|
|
396
352
|
const keyArr = (_displayExpr2 = displayExpr) === null || _displayExpr2 === void 0 ? void 0 : _displayExpr2.match(separatorPattern);
|
|
397
353
|
const dropdown = mapDropdown(pattern, keyArr);
|
|
398
354
|
const el = document.createElement('div');
|
|
399
355
|
el.className = `DGN-Dropdown-Box`;
|
|
400
|
-
|
|
401
356
|
if (dropdownRef.current) {
|
|
402
357
|
var _dropdownRef$current$;
|
|
403
|
-
|
|
404
358
|
(_dropdownRef$current$ = dropdownRef.current.querySelector('.DGN-Dropdown-Box')) === null || _dropdownRef$current$ === void 0 ? void 0 : _dropdownRef$current$.remove();
|
|
405
359
|
ReactDOM.render(dropdown, dropdownRef.current.appendChild(el));
|
|
406
360
|
setTimeout(() => {
|
|
407
361
|
dropdownListRef.current && dropdownListRef.current.addEventListener('keydown', moveOnItem);
|
|
408
|
-
|
|
409
362
|
if (onLoadMore && dataSource.length < total) {
|
|
410
363
|
dropdownListRef.current && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
411
364
|
}
|
|
412
|
-
|
|
413
365
|
updatePositionDropdown();
|
|
414
366
|
}, 0);
|
|
415
367
|
}
|
|
416
368
|
};
|
|
417
|
-
|
|
418
369
|
const handleRenderBySearch = (data, searchValue) => {
|
|
419
370
|
let existExpr = [];
|
|
420
371
|
typeof data === 'object' ? existExpr = searchExpr.filter(value => Object.keys(data).includes(value)) : existExpr = [data];
|
|
421
372
|
return existExpr.every(key => {
|
|
422
373
|
// return searchByMode(data?.[key] || key.toString(), searchValue);
|
|
423
374
|
const _data = (data === null || data === void 0 ? void 0 : data[key]) || key.toString();
|
|
424
|
-
|
|
425
375
|
if (searchMode === 'contains') {
|
|
426
376
|
if (_data.indexOf(searchValue) !== -1) return false;
|
|
427
377
|
}
|
|
428
|
-
|
|
429
378
|
if (searchMode === 'startswith') {
|
|
430
379
|
if (_data.lastIndexOf(searchValue) === 0) return false;
|
|
431
380
|
}
|
|
432
|
-
|
|
433
381
|
if (searchMode === 'equals') {
|
|
434
382
|
if (_data == searchValue) return false;
|
|
435
383
|
}
|
|
436
|
-
|
|
437
384
|
return true;
|
|
438
385
|
});
|
|
439
386
|
};
|
|
440
|
-
|
|
441
387
|
const mapDropdown = (pattern, keyArr) => {
|
|
442
388
|
var _currentObjectDefault;
|
|
443
|
-
|
|
444
389
|
const items = [];
|
|
445
390
|
const dataSourceUsable = [...dataSource];
|
|
446
|
-
|
|
447
391
|
if (currentObjectDefault[unique] && (_currentObjectDefault = currentObjectDefault[unique]) !== null && _currentObjectDefault !== void 0 && _currentObjectDefault.length) {
|
|
448
392
|
const length = currentObjectDefault[unique].length;
|
|
449
393
|
let existItemQuantity = 0;
|
|
450
|
-
|
|
451
394
|
for (let index = length - 1; index >= 0; index--) {
|
|
452
395
|
if (!dataSourceUsable.some(data => data[valueExpr] === currentObjectDefault[unique][index][valueExpr])) {
|
|
453
396
|
dataSourceUsable.unshift(currentObjectDefault[unique][index]);
|
|
@@ -456,26 +399,20 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
456
399
|
if (++existItemQuantity > limit) {
|
|
457
400
|
continue;
|
|
458
401
|
}
|
|
459
|
-
|
|
460
402
|
currentObjectDefault[unique].splice(index, 1);
|
|
461
403
|
}
|
|
462
404
|
}
|
|
463
405
|
}
|
|
464
|
-
|
|
465
406
|
const length = dataSourceUsable.length;
|
|
466
|
-
|
|
467
407
|
for (let index = 0; index < length; index++) {
|
|
468
408
|
var _searchExpr;
|
|
469
|
-
|
|
470
409
|
const data = dataSourceUsable[index];
|
|
471
410
|
const itemHidden = typeof data === 'object' ? data['hidden'] : false;
|
|
472
411
|
if (itemHidden) continue;
|
|
473
412
|
let displayText = typeof data === 'object' ? keyArr ? renderData(data, keyArr) : data[displayExpr] || data[valueExpr] : data;
|
|
474
|
-
|
|
475
413
|
if (((_searchExpr = searchExpr) === null || _searchExpr === void 0 ? void 0 : _searchExpr.length) > 0 && pattern) {
|
|
476
414
|
if (handleRenderBySearch(data, pattern)) continue;
|
|
477
415
|
} else if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
|
|
478
|
-
|
|
479
416
|
if (renderItem && typeof renderItem === 'function') {
|
|
480
417
|
displayText = renderItem({
|
|
481
418
|
data,
|
|
@@ -491,11 +428,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
491
428
|
index
|
|
492
429
|
}) : data[subText] || subText));
|
|
493
430
|
}
|
|
494
|
-
|
|
495
431
|
const value = typeof data === 'object' ? data[valueExpr] : data;
|
|
496
432
|
let itemDisabled = typeof data === 'object' ? data['disabled'] : false;
|
|
497
433
|
const icon = getIconFromData(data);
|
|
498
|
-
|
|
499
434
|
if (multiple && selectBox) {
|
|
500
435
|
const checked = Array.isArray(valueMulti) ? valueMulti.includes(value) : valueMulti.includes(value);
|
|
501
436
|
const isMaximumSelection = maximumSelectionLength === (valueMulti === null || valueMulti === void 0 ? void 0 : valueMulti.length);
|
|
@@ -503,7 +438,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
503
438
|
items.push(jsx("div", {
|
|
504
439
|
key: index,
|
|
505
440
|
css: !itemDisabled ? _DropdownItemCSS : [DisabledCSS, _DropdownItemCSS],
|
|
506
|
-
className: 'DGN-UI-Dropdown-Item'
|
|
441
|
+
className: 'DGN-UI-Dropdown-Item'
|
|
442
|
+
// onClick={() => {
|
|
507
443
|
// if (itemDisabled) return;
|
|
508
444
|
// onChangeValueWithCheckbox(e) & onChangeValue(displayText, value, icon, data, index);
|
|
509
445
|
// onChangeValue(displayText, value, icon, data, index);
|
|
@@ -511,8 +447,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
511
447
|
,
|
|
512
448
|
onKeyPress: e => {
|
|
513
449
|
if (itemDisabled) return;
|
|
514
|
-
if (e.key === 'Enter') e.currentTarget.firstChild.click();
|
|
450
|
+
if (e.key === 'Enter') e.currentTarget.firstChild.click();
|
|
451
|
+
// if (e.key === 'Enter') onChangeValue(displayText, value, icon, data, index);
|
|
515
452
|
},
|
|
453
|
+
|
|
516
454
|
tabIndex: -1
|
|
517
455
|
}, jsx(Checkbox, {
|
|
518
456
|
forTreeView: true,
|
|
@@ -546,13 +484,13 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
546
484
|
}, icon && icon, jsx("div", {
|
|
547
485
|
css: DropdownTextCSS
|
|
548
486
|
}, displayText)));
|
|
549
|
-
}
|
|
487
|
+
}
|
|
488
|
+
// if (items?.length === limit) {
|
|
550
489
|
// timerRef.current = setTimeout(() => {
|
|
551
490
|
// loadMoreItemsDropdown(index + 1, pattern);
|
|
552
491
|
// }, 1000);
|
|
553
492
|
// break;
|
|
554
493
|
// }
|
|
555
|
-
|
|
556
494
|
}
|
|
557
495
|
|
|
558
496
|
return jsx("div", {
|
|
@@ -561,7 +499,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
561
499
|
className: 'DGN-Dropdown-List'
|
|
562
500
|
}, items !== null && items !== void 0 && items.length ? items : EmptyDataText);
|
|
563
501
|
};
|
|
564
|
-
|
|
565
502
|
const mapTreeView = () => {
|
|
566
503
|
// if (!treeView[unique]) {
|
|
567
504
|
return jsx("div", {
|
|
@@ -585,20 +522,18 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
585
522
|
value: typeof currentValue[unique] === 'string' ? [currentValue[unique]] : currentValue[unique],
|
|
586
523
|
onChange: (e, value) => onChangeValue('', multiple ? value : e.value),
|
|
587
524
|
renderItem: renderItem
|
|
588
|
-
}) : EmptyDataText);
|
|
525
|
+
}) : EmptyDataText);
|
|
526
|
+
// }
|
|
589
527
|
// return treeView[unique];
|
|
590
528
|
};
|
|
591
529
|
|
|
592
530
|
const loadMoreItemsDropdown = (i = 0, pattern) => {
|
|
593
531
|
var _currentObjectDefault2, _displayExpr3;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
532
|
+
const dataSourceUsable = [...dataSource];
|
|
533
|
+
// Nếu có load more thì đẩy đội tượng mặc định lên đầu
|
|
597
534
|
let notExistItem = 0;
|
|
598
|
-
|
|
599
535
|
if (onLoadMore && (_currentObjectDefault2 = currentObjectDefault[unique]) !== null && _currentObjectDefault2 !== void 0 && _currentObjectDefault2.length) {
|
|
600
536
|
const length = currentObjectDefault[unique].length;
|
|
601
|
-
|
|
602
537
|
for (let index = length - 1; index >= 0; index--) {
|
|
603
538
|
if (!dataSourceUsable.some(data => data[valueExpr] === currentObjectDefault[unique][index][valueExpr])) {
|
|
604
539
|
notExistItem++;
|
|
@@ -606,26 +541,22 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
606
541
|
}
|
|
607
542
|
}
|
|
608
543
|
}
|
|
609
|
-
|
|
610
544
|
const length = dataSourceUsable.length;
|
|
611
545
|
let num = 0;
|
|
612
|
-
|
|
613
546
|
if (displayExpr && Array.isArray(displayExpr)) {
|
|
614
547
|
displayExpr = displayExpr.join(' - ');
|
|
615
548
|
}
|
|
616
|
-
|
|
617
549
|
const keyArr = (_displayExpr3 = displayExpr) === null || _displayExpr3 === void 0 ? void 0 : _displayExpr3.match(separatorPattern);
|
|
618
|
-
|
|
619
550
|
for (i; i < length; i++) {
|
|
620
|
-
const data = {
|
|
621
|
-
|
|
622
|
-
|
|
551
|
+
const data = {
|
|
552
|
+
...dataSourceUsable[i]
|
|
553
|
+
};
|
|
554
|
+
// Nếu đối tượng đã được hiển thị ở trên rồi thì không hiển thị ra nữa
|
|
623
555
|
if (onLoadMore && i > notExistItem && currentObjectDefault[unique].some(valueObject => valueObject[valueExpr] === data[valueExpr])) continue;
|
|
624
556
|
let displayText = typeof data === 'object' ? keyArr ? renderData(data, keyArr) : data[displayExpr] || data[valueExpr] : data;
|
|
625
557
|
if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
|
|
626
558
|
const value = typeof data === 'object' ? data[valueExpr] : data;
|
|
627
559
|
const icon = getIconFromData(data);
|
|
628
|
-
|
|
629
560
|
if (renderItem && typeof renderItem === 'function') {
|
|
630
561
|
displayText = renderItem({
|
|
631
562
|
data,
|
|
@@ -641,7 +572,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
641
572
|
index: i
|
|
642
573
|
}) : data[subText] || subText));
|
|
643
574
|
}
|
|
644
|
-
|
|
645
575
|
const dropdownItem = document.createElement('div');
|
|
646
576
|
dropdownItem.className = `DGN-UI-Dropdown-Item css-${_DropdownItemCSS.name}`;
|
|
647
577
|
dropdownItem.tabIndex = -1;
|
|
@@ -650,7 +580,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
650
580
|
if (e.key === 'Enter') dropdownItem.firstChild.click();
|
|
651
581
|
});
|
|
652
582
|
let item = null;
|
|
653
|
-
|
|
654
583
|
if (multiple && selectBox) {
|
|
655
584
|
const checked = Array.isArray(currentValue[unique]) ? currentValue[unique].includes(value) : [currentValue[unique]].includes(value);
|
|
656
585
|
item = jsx(Checkbox, {
|
|
@@ -669,13 +598,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
669
598
|
css: DropdownTextCSS
|
|
670
599
|
}, displayText));
|
|
671
600
|
}
|
|
672
|
-
|
|
673
601
|
if (!dropdownListRef.current) {
|
|
674
602
|
return;
|
|
675
603
|
}
|
|
676
|
-
|
|
677
604
|
ReactDOM.render(item, dropdownListRef.current.appendChild(dropdownItem));
|
|
678
|
-
|
|
679
605
|
if (++num === 100) {
|
|
680
606
|
timerRef.current = setTimeout(() => {
|
|
681
607
|
loadMoreItemsDropdown(i + 1, pattern);
|
|
@@ -684,20 +610,16 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
684
610
|
}
|
|
685
611
|
}
|
|
686
612
|
};
|
|
687
|
-
|
|
688
613
|
const renderData = (data, keyArr) => {
|
|
689
614
|
const pattern = keyArr.join('|').replace(/([{}])/g, '\\$1');
|
|
690
615
|
const separatorArr = displayExpr.split(new RegExp(pattern));
|
|
691
616
|
let str = '';
|
|
692
617
|
let i = 0;
|
|
693
|
-
|
|
694
618
|
for (i; i < keyArr.length; i++) {
|
|
695
619
|
str += separatorArr[i] + (data[keyArr[i].replace(/\W/g, '')] !== undefined ? data[keyArr[i].replace(/\W/g, '')] : keyArr[i]);
|
|
696
620
|
}
|
|
697
|
-
|
|
698
621
|
return str + separatorArr[i];
|
|
699
622
|
};
|
|
700
|
-
|
|
701
623
|
const getIconFromData = (data, insideChip = false) => {
|
|
702
624
|
if (!iconExpr || iconExpr === 'none') return null;
|
|
703
625
|
let _src = iconDefault;
|
|
@@ -705,11 +627,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
705
627
|
let prefix = iconExpr.prefix || '';
|
|
706
628
|
const suffix = iconExpr.suffix || '';
|
|
707
629
|
const url = data[iconExpr.key];
|
|
708
|
-
|
|
709
630
|
if (prefix && /^http/i.test(prefix) && /^http/i.test(url)) {
|
|
710
631
|
prefix = '';
|
|
711
632
|
}
|
|
712
|
-
|
|
713
633
|
_src = prefix + url + suffix;
|
|
714
634
|
}
|
|
715
635
|
return jsx(Avatar, {
|
|
@@ -717,55 +637,45 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
717
637
|
src: _src,
|
|
718
638
|
width: insideChip ? 20 : 24,
|
|
719
639
|
height: insideChip ? 20 : 24,
|
|
720
|
-
style: {
|
|
640
|
+
style: {
|
|
641
|
+
...iconExpr.style,
|
|
721
642
|
marginRight: spacing([insideChip ? 0 : 2])
|
|
722
643
|
}
|
|
723
644
|
});
|
|
724
645
|
};
|
|
725
|
-
|
|
726
646
|
const customizeWidthDropdown = () => {
|
|
727
647
|
if (dropdownListRef.current && _isMobile) dropdownListRef.current.style.maxHeight = `${Math.min(280, window.innerHeight) - (allowSearch ? 40 : 0)}px`;
|
|
728
|
-
|
|
729
648
|
if (!ref.current) {
|
|
730
649
|
window.removeEventListener('resize', customizeWidthDropdown);
|
|
731
650
|
return;
|
|
732
651
|
}
|
|
733
|
-
|
|
734
652
|
const {
|
|
735
653
|
width
|
|
736
654
|
} = ref.current.getBoundingClientRect();
|
|
737
|
-
|
|
738
655
|
if (dropdownRef.current) {
|
|
739
656
|
dropdownRef.current.style.width = width + 'px';
|
|
740
657
|
}
|
|
741
|
-
|
|
742
658
|
updatePositionDropdown();
|
|
743
659
|
};
|
|
744
|
-
|
|
745
660
|
const updatePositionDropdown = () => {
|
|
746
661
|
if (!formRef.current || !dropdownRef.current) {
|
|
747
662
|
document.removeEventListener('wheel', onWheelHandler);
|
|
748
663
|
return;
|
|
749
664
|
}
|
|
750
|
-
|
|
751
665
|
_isMobile ? updatePosition(formRef.current, dropdownRef.current, null) : updatePosition(formRef.current, dropdownRef.current, closeDropdown);
|
|
752
666
|
};
|
|
753
|
-
|
|
754
667
|
const onLoadMoreHandler = e => {
|
|
755
668
|
if (loadMoreTimer.current) {
|
|
756
669
|
clearTimeout(loadMoreTimer.current);
|
|
757
670
|
}
|
|
758
|
-
|
|
759
671
|
loadMoreTimer.current = setTimeout(() => {
|
|
760
672
|
const {
|
|
761
673
|
scrollTop,
|
|
762
674
|
scrollHeight,
|
|
763
675
|
offsetHeight
|
|
764
676
|
} = e.target;
|
|
765
|
-
|
|
766
677
|
if (scrollHeight === Math.ceil(scrollTop) + offsetHeight && dropdownListRef.current) {
|
|
767
678
|
var _dropdownListRef$curr4, _currentObjectDefault3;
|
|
768
|
-
|
|
769
679
|
const length = ((_dropdownListRef$curr4 = dropdownListRef.current.children) === null || _dropdownListRef$curr4 === void 0 ? void 0 : _dropdownListRef$curr4.length) - (((_currentObjectDefault3 = currentObjectDefault[unique]) === null || _currentObjectDefault3 === void 0 ? void 0 : _currentObjectDefault3.length) || 0);
|
|
770
680
|
dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
771
681
|
!!onLoadMore && onLoadMore({
|
|
@@ -775,50 +685,44 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
775
685
|
}
|
|
776
686
|
});
|
|
777
687
|
};
|
|
778
|
-
|
|
779
688
|
const onPreventKeyDownHandler = e => {
|
|
780
689
|
e.preventDefault();
|
|
781
690
|
return false;
|
|
782
691
|
};
|
|
783
|
-
|
|
784
692
|
const onChangeInput = e => {
|
|
785
693
|
if (searchRef.current) lastSearchRef.current = searchRef.current.value;
|
|
786
694
|
const dataFilter = getData();
|
|
787
695
|
dataChoosen.current = [...dataFilter].filter(i => [...valueMulti].includes(i === null || i === void 0 ? void 0 : i[valueExpr]));
|
|
788
|
-
|
|
789
696
|
if (onInput) {
|
|
790
|
-
isSearch[unique] = true;
|
|
697
|
+
isSearch[unique] = true;
|
|
698
|
+
// const valueInput = e.target.value;
|
|
791
699
|
// const text = (valueInput || e.target.textContent).normalize();
|
|
792
|
-
|
|
793
700
|
if (timeout.current) {
|
|
794
701
|
if (timing[unique]) {
|
|
795
702
|
clearTimeout(timing[unique]);
|
|
796
703
|
}
|
|
797
|
-
|
|
798
704
|
timing[unique] = setTimeout(() => {
|
|
799
705
|
// e.target.value = text;
|
|
800
|
-
onInput(e);
|
|
706
|
+
onInput(e);
|
|
707
|
+
// e.target.value = valueInput;
|
|
801
708
|
}, timeout.current || searchDelayTime);
|
|
802
709
|
} else {
|
|
803
710
|
// e.target.value = text;
|
|
804
|
-
onInput(e);
|
|
711
|
+
onInput(e);
|
|
712
|
+
// e.target.value = valueInput;
|
|
805
713
|
}
|
|
806
714
|
|
|
807
715
|
return;
|
|
808
716
|
}
|
|
809
|
-
|
|
810
717
|
const value = e.target.value || e.target.textContent;
|
|
811
|
-
|
|
812
718
|
if (typeof renderSelectedItem === 'function' && e.target.childNodes && Array.from(e.target.childNodes).some(node => node.toString() !== '[object Text]')) {
|
|
813
719
|
const cursor = document.getSelection().anchorOffset;
|
|
814
720
|
e.target.innerHTML = value;
|
|
815
721
|
document.getSelection().collapse(e.target, cursor);
|
|
816
722
|
}
|
|
817
|
-
|
|
818
723
|
if (timing[unique]) clearTimeout(timing[unique]);
|
|
819
724
|
timing[unique] = setTimeout(() => {
|
|
820
725
|
var _searchExpr2;
|
|
821
|
-
|
|
822
726
|
// if (timerRef.current) {
|
|
823
727
|
// clearTimeout(timerRef.current);
|
|
824
728
|
// timerRef.current = null;
|
|
@@ -826,7 +730,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
826
730
|
renderDropdown(((_searchExpr2 = searchExpr) === null || _searchExpr2 === void 0 ? void 0 : _searchExpr2.length) > 0 ? value.normalize() : new RegExp(value.normalize(), 'gim'));
|
|
827
731
|
}, timeout.current || searchDelayTime);
|
|
828
732
|
};
|
|
829
|
-
|
|
830
733
|
const onChangeValue = (displayText, value, icon, data) => {
|
|
831
734
|
if (itemMode === 'treeview') {
|
|
832
735
|
if (valueProp === undefined) {
|
|
@@ -834,7 +737,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
834
737
|
setValueIntoInput(value);
|
|
835
738
|
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !loading);
|
|
836
739
|
}
|
|
837
|
-
|
|
838
740
|
!!onChange && onChange({
|
|
839
741
|
value
|
|
840
742
|
});
|
|
@@ -845,10 +747,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
845
747
|
if (!Array.isArray(currentValue[unique])) currentValue[unique] = [];
|
|
846
748
|
const newValueArr = [...currentValue[unique]];
|
|
847
749
|
const newValueArrState = [...valueMulti];
|
|
848
|
-
|
|
849
750
|
if (!currentValue[unique].some(v => JSON.stringify(v) === JSON.stringify(value))) {
|
|
850
751
|
newValueArr.push(value);
|
|
851
|
-
newValueArrState.push(value);
|
|
752
|
+
newValueArrState.push(value);
|
|
753
|
+
// if (valueProp === undefined) {
|
|
852
754
|
// let item = null;
|
|
853
755
|
// if (typeof renderSelectedItem === 'function') {
|
|
854
756
|
// item = renderSelextedItem({ data, index });
|
|
@@ -873,7 +775,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
873
775
|
} else {
|
|
874
776
|
const index = newValueArr.indexOf(value);
|
|
875
777
|
newValueArr.splice(index, 1);
|
|
876
|
-
newValueArrState.splice(index, 1);
|
|
778
|
+
newValueArrState.splice(index, 1);
|
|
779
|
+
// if (valueProp === undefined) {
|
|
877
780
|
// const nodes = inputRef.current.querySelectorAll('.dropdown-item');
|
|
878
781
|
// nodes[index]?.remove();
|
|
879
782
|
// }
|
|
@@ -889,14 +792,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
889
792
|
}, 0);
|
|
890
793
|
} else {
|
|
891
794
|
const isChanged = currentValue[unique] !== value;
|
|
892
|
-
|
|
893
795
|
if (isChanged) {
|
|
894
796
|
if (valueProp === undefined) {
|
|
895
797
|
allValue[unique].push(value);
|
|
896
798
|
setValueIntoInput(value);
|
|
897
799
|
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !loading);
|
|
898
800
|
}
|
|
899
|
-
|
|
900
801
|
!!onChange && onChange({
|
|
901
802
|
value,
|
|
902
803
|
data
|
|
@@ -906,7 +807,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
906
807
|
triggerBlur(false);
|
|
907
808
|
}
|
|
908
809
|
}
|
|
909
|
-
|
|
910
810
|
if (closeAfterSelect === true || closeAfterSelect === undefined && !multiple) {
|
|
911
811
|
closeDropdown();
|
|
912
812
|
} else {
|
|
@@ -914,22 +814,22 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
914
814
|
updatePositionDropdown();
|
|
915
815
|
}, 0);
|
|
916
816
|
}
|
|
917
|
-
};
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
// const onChangeValueWithCheckbox = e => {
|
|
918
820
|
// const firstChild = e.currentTarget.firstChild;
|
|
919
821
|
// if (!firstChild.contains(e.target)) {
|
|
920
822
|
// firstChild.click();
|
|
921
823
|
// }
|
|
922
824
|
// };
|
|
923
825
|
|
|
924
|
-
|
|
925
826
|
const onRemove = (e, value) => {
|
|
926
827
|
var _ref;
|
|
927
|
-
|
|
928
828
|
if (readOnly || disabled) return;
|
|
929
829
|
const index = currentValue[unique].findIndex(v => JSON.stringify(v) === JSON.stringify(value));
|
|
930
|
-
|
|
931
830
|
if (index !== -1) {
|
|
932
|
-
currentValue[unique].splice(index, 1);
|
|
831
|
+
currentValue[unique].splice(index, 1);
|
|
832
|
+
// setTimeout(() => {
|
|
933
833
|
// if (dropdownListRef.current && multiple && selectBox && !children) {
|
|
934
834
|
// const input = dropdownListRef.current.querySelector(`input[value="${value}"]`);
|
|
935
835
|
// if (input) {
|
|
@@ -942,9 +842,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
942
842
|
// }, 0);
|
|
943
843
|
// setValueMulti([...valueMulti]?.filter(i=>i!==value) || []);
|
|
944
844
|
// !!onChange && onChange({ value: currentValue[unique], removed: value });
|
|
945
|
-
}
|
|
946
|
-
|
|
845
|
+
}
|
|
947
846
|
|
|
847
|
+
// logic mới
|
|
948
848
|
const newValueArrState = ((_ref = [...valueMulti]) === null || _ref === void 0 ? void 0 : _ref.filter(i => i !== value)) || [];
|
|
949
849
|
setValueMulti(newValueArrState);
|
|
950
850
|
!!onChange && onChange({
|
|
@@ -952,26 +852,25 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
952
852
|
removed: value
|
|
953
853
|
});
|
|
954
854
|
};
|
|
955
|
-
|
|
956
855
|
const onClear = e => {
|
|
957
856
|
if (disabled || readOnly || loading || !clearAble) return;
|
|
958
857
|
currentValue[unique] = multiple ? [] : '';
|
|
959
|
-
|
|
960
|
-
|
|
858
|
+
if (inputRef.current.tagName.toLowerCase() === 'div') {
|
|
859
|
+
// inputRef.current.innerHTML = '';
|
|
961
860
|
// if (dropdownListRef.current) {
|
|
962
861
|
// dropdownListRef.current.querySelectorAll('input').forEach(input => (input.checked = false));
|
|
963
862
|
// }
|
|
964
863
|
} else {
|
|
965
864
|
inputRef.current.value = '';
|
|
966
865
|
setTextValue('');
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
|
|
866
|
+
}
|
|
867
|
+
// onChangeValue('', '');
|
|
970
868
|
setValueMulti([]);
|
|
971
869
|
setShowClear(false);
|
|
972
870
|
e && e.target && e.target.blur();
|
|
973
871
|
updatePositionDropdown();
|
|
974
|
-
onInput === null || onInput === void 0 ? void 0 : onInput({
|
|
872
|
+
onInput === null || onInput === void 0 ? void 0 : onInput({
|
|
873
|
+
...(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current),
|
|
975
874
|
target: {
|
|
976
875
|
value: inputRef === null || inputRef === void 0 ? void 0 : inputRef.current.value
|
|
977
876
|
}
|
|
@@ -980,12 +879,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
980
879
|
value: currentValue[unique]
|
|
981
880
|
});
|
|
982
881
|
};
|
|
983
|
-
|
|
984
882
|
const setPreviousValue = () => {
|
|
985
883
|
allValue[unique].pop();
|
|
986
884
|
setValueIntoInput(allValue[unique][allValue[unique].length - 1]);
|
|
987
885
|
};
|
|
988
|
-
|
|
989
886
|
const setValueIntoInput = source => {
|
|
990
887
|
if (!source && source !== 0) {
|
|
991
888
|
if (multiple) {
|
|
@@ -998,45 +895,34 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
998
895
|
inputRef.current.value = '';
|
|
999
896
|
setTextValue('');
|
|
1000
897
|
}
|
|
1001
|
-
|
|
1002
898
|
currentValue[unique] = '';
|
|
1003
899
|
}
|
|
1004
|
-
|
|
1005
900
|
return;
|
|
1006
901
|
}
|
|
1007
|
-
|
|
1008
902
|
const length = dataSource.length;
|
|
1009
903
|
const displayKey = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr;
|
|
1010
|
-
|
|
1011
904
|
if (displayKey && Array.isArray(displayKey)) {
|
|
1012
905
|
displayExpr = displayExpr.join(' - ');
|
|
1013
906
|
}
|
|
1014
|
-
|
|
1015
907
|
const keyArr = displayKey === null || displayKey === void 0 ? void 0 : displayKey.match(separatorPattern);
|
|
1016
|
-
|
|
1017
908
|
if (multiple) {
|
|
1018
909
|
let valueArr = source;
|
|
1019
|
-
|
|
1020
910
|
if (!Array.isArray(valueArr)) {
|
|
1021
911
|
valueArr = [valueArr];
|
|
1022
912
|
}
|
|
1023
|
-
|
|
1024
913
|
valueArr = [...new Set(valueArr)];
|
|
1025
|
-
currentValue[unique] = [];
|
|
1026
|
-
|
|
914
|
+
currentValue[unique] = [];
|
|
915
|
+
// inputRef.current.innerHTML = '';
|
|
1027
916
|
valueArr.forEach(v => {
|
|
1028
917
|
var _currentObjectDefault4;
|
|
1029
|
-
|
|
1030
918
|
for (let i = 0; i < length; i++) {
|
|
1031
919
|
if (typeof dataSource[i] === 'object' && dataSource[i][valueExpr] === v || dataSource[i] === v) {
|
|
1032
920
|
setMultipleValueHandler(dataSource[i], v, keyArr, i);
|
|
1033
921
|
return;
|
|
1034
922
|
}
|
|
1035
923
|
}
|
|
1036
|
-
|
|
1037
924
|
if ((_currentObjectDefault4 = currentObjectDefault[unique]) !== null && _currentObjectDefault4 !== void 0 && _currentObjectDefault4.length) {
|
|
1038
925
|
const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === v || valueObject === v);
|
|
1039
|
-
|
|
1040
926
|
if (itemOfValue) {
|
|
1041
927
|
setMultipleValueHandler(itemOfValue, v, keyArr);
|
|
1042
928
|
}
|
|
@@ -1044,31 +930,25 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1044
930
|
});
|
|
1045
931
|
} else {
|
|
1046
932
|
var _currentObjectDefault5;
|
|
1047
|
-
|
|
1048
933
|
currentValue[unique] = source;
|
|
1049
|
-
|
|
1050
934
|
for (let i = 0; i < length; i++) {
|
|
1051
935
|
if (dataSource[i][valueExpr] === source || dataSource[i] === source) {
|
|
1052
936
|
setSingleValueHandler(dataSource[i], keyArr);
|
|
1053
937
|
return;
|
|
1054
938
|
}
|
|
1055
939
|
}
|
|
1056
|
-
|
|
1057
940
|
if ((_currentObjectDefault5 = currentObjectDefault[unique]) !== null && _currentObjectDefault5 !== void 0 && _currentObjectDefault5.length) {
|
|
1058
941
|
const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === source || valueObject === source);
|
|
1059
|
-
|
|
1060
942
|
if (itemOfValue) {
|
|
1061
943
|
setSingleValueHandler(itemOfValue, keyArr);
|
|
1062
944
|
return;
|
|
1063
945
|
}
|
|
1064
946
|
}
|
|
1065
|
-
|
|
1066
947
|
if (!isSearch[unique]) {
|
|
1067
948
|
inputRef.current.value = source;
|
|
1068
949
|
}
|
|
1069
950
|
}
|
|
1070
951
|
};
|
|
1071
|
-
|
|
1072
952
|
const setMultipleValueHandler = (data, value) => {
|
|
1073
953
|
// let item = null;
|
|
1074
954
|
// if (typeof renderSelectedItem === 'function') {
|
|
@@ -1094,10 +974,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1094
974
|
// ReactDOM.render(item, inputRef.current.appendChild(el));
|
|
1095
975
|
currentValue[unique].push(value);
|
|
1096
976
|
};
|
|
1097
|
-
|
|
1098
977
|
const setSingleValueHandler = (data, keyArr) => {
|
|
1099
978
|
const text = keyArr ? renderData(data, keyArr) : typeof renderSelectedItem === 'string' ? data[renderSelectedItem] : data[displayExpr] || data[valueExpr] || data;
|
|
1100
|
-
|
|
1101
979
|
if (typeof renderSelectedItem === 'function') {
|
|
1102
980
|
inputRef.current.innerHTML = '';
|
|
1103
981
|
const item = renderSelectedItem({
|
|
@@ -1123,7 +1001,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1123
1001
|
setTextValue(text);
|
|
1124
1002
|
}
|
|
1125
1003
|
};
|
|
1126
|
-
|
|
1127
1004
|
useImperativeHandle(reference, () => {
|
|
1128
1005
|
const currentRef = ref.current || {};
|
|
1129
1006
|
const _instance = {
|
|
@@ -1139,30 +1016,22 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1139
1016
|
if (allValue[unique][allValue[unique].length - 1] !== value) {
|
|
1140
1017
|
allValue[unique].push(value);
|
|
1141
1018
|
}
|
|
1142
|
-
|
|
1143
1019
|
setValueIntoInput(value);
|
|
1144
1020
|
}
|
|
1145
1021
|
}; // methods
|
|
1146
|
-
|
|
1147
1022
|
_instance.__proto__ = {}; // hidden methods
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1023
|
+
currentRef.instance = _instance;
|
|
1024
|
+
// keep old method
|
|
1151
1025
|
currentRef.closeDropdown = () => closeDropdown();
|
|
1152
|
-
|
|
1153
1026
|
currentRef.showDropdown = () => setOpenState(true);
|
|
1154
|
-
|
|
1155
1027
|
currentRef.onClear = onClear;
|
|
1156
1028
|
currentRef.setPreviousValue = setPreviousValue;
|
|
1157
|
-
|
|
1158
1029
|
currentRef.setValue = value => {
|
|
1159
1030
|
if (allValue[unique][allValue[unique].length - 1] !== value) {
|
|
1160
1031
|
allValue[unique].push(value);
|
|
1161
1032
|
}
|
|
1162
|
-
|
|
1163
1033
|
setValueIntoInput(value);
|
|
1164
1034
|
};
|
|
1165
|
-
|
|
1166
1035
|
currentRef.DOM = ref.current;
|
|
1167
1036
|
return currentRef;
|
|
1168
1037
|
});
|
|
@@ -1179,19 +1048,16 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1179
1048
|
} else {
|
|
1180
1049
|
currentObjectDefault[unique] = [];
|
|
1181
1050
|
}
|
|
1182
|
-
|
|
1183
1051
|
return () => {
|
|
1184
1052
|
currentObjectDefault[unique] = null;
|
|
1185
1053
|
};
|
|
1186
1054
|
}, [valueObjectDefault]);
|
|
1187
1055
|
useEffect(() => {
|
|
1188
1056
|
allValue[unique] = [];
|
|
1189
|
-
|
|
1190
1057
|
if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
|
|
1191
1058
|
setValueIntoInput(defaultValue);
|
|
1192
1059
|
setShowClear(clearAble && checkHasValue(defaultValue) && !disabled && !readOnly && !loading);
|
|
1193
1060
|
}
|
|
1194
|
-
|
|
1195
1061
|
return () => {
|
|
1196
1062
|
allValue[unique] = null;
|
|
1197
1063
|
closeDropdown();
|
|
@@ -1200,7 +1066,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1200
1066
|
useEffect(() => {
|
|
1201
1067
|
if (searchDelayTime) {
|
|
1202
1068
|
var _searchDelayTime$matc, _searchDelayTime$matc2;
|
|
1203
|
-
|
|
1204
1069
|
if (searchDelayTime === true) searchDelayTime = getGlobal('delayOnInput');
|
|
1205
1070
|
const units = {
|
|
1206
1071
|
m: 60000,
|
|
@@ -1217,12 +1082,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1217
1082
|
if (allValue[unique][allValue[unique].length - 1] !== valueProp) {
|
|
1218
1083
|
allValue[unique].push(valueProp);
|
|
1219
1084
|
}
|
|
1220
|
-
|
|
1221
1085
|
if (multiple && valueProp) {
|
|
1222
1086
|
setValueMulti(convertData(valueProp, valueExpr));
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1087
|
+
}
|
|
1088
|
+
// Close dropdown treeview by children when select item
|
|
1226
1089
|
if (children && (closeAfterSelect === true || closeAfterSelect === undefined && !multiple)) {
|
|
1227
1090
|
closeDropdown();
|
|
1228
1091
|
}
|
|
@@ -1234,43 +1097,37 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1234
1097
|
}, [valueProp, dataSource]);
|
|
1235
1098
|
useEffect(() => {
|
|
1236
1099
|
inputRef.current.readOnly = readOnly || inputProps.readOnly;
|
|
1237
|
-
|
|
1238
1100
|
if (!readOnly && !disabled) {
|
|
1239
1101
|
inputRef.current.addEventListener('click', onClickInput);
|
|
1240
1102
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1241
1103
|
!!onLoadMore && dropdownListRef.current && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
1242
|
-
}
|
|
1104
|
+
}
|
|
1105
|
+
// else {
|
|
1243
1106
|
// if (multiple || allowSearch) {
|
|
1244
1107
|
// inputRef.current.contentEditable = false;
|
|
1245
1108
|
// }
|
|
1246
1109
|
// }
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
1110
|
if (disabled || readOnly || children) {
|
|
1250
1111
|
inputRef.current.addEventListener('keydown', onPreventKeyDownHandler);
|
|
1251
1112
|
} else {
|
|
1252
1113
|
inputRef.current.addEventListener('keydown', onKeyDown);
|
|
1253
1114
|
}
|
|
1254
|
-
|
|
1255
1115
|
return () => {
|
|
1256
1116
|
if (!ref.current || !inputRef.current || !iconRef.current) return;
|
|
1257
|
-
|
|
1258
1117
|
if (!readOnly && !disabled) {
|
|
1259
1118
|
inputRef.current.removeEventListener('click', onClickInput);
|
|
1260
1119
|
inputRef.current.removeEventListener('input', onChangeInput);
|
|
1261
|
-
}
|
|
1120
|
+
}
|
|
1121
|
+
// else {
|
|
1262
1122
|
// if (multiple && !allowSearch) {
|
|
1263
1123
|
// inputRef.current.contentEditable = true;
|
|
1264
1124
|
// }
|
|
1265
1125
|
// }
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
1126
|
if (disabled || readOnly || children) {
|
|
1269
1127
|
inputRef.current.removeEventListener('keydown', onPreventKeyDownHandler);
|
|
1270
1128
|
} else {
|
|
1271
1129
|
inputRef.current.removeEventListener('keydown', onKeyDown);
|
|
1272
1130
|
}
|
|
1273
|
-
|
|
1274
1131
|
closeDropdown();
|
|
1275
1132
|
};
|
|
1276
1133
|
}, [disabled, readOnly, displayExpr, multiple, allowSearch, viewType, closeAfterSelect, selectBox]);
|
|
@@ -1279,7 +1136,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1279
1136
|
inputRef.current.addEventListener('click', onClickInput);
|
|
1280
1137
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1281
1138
|
}
|
|
1282
|
-
|
|
1283
1139
|
return () => {
|
|
1284
1140
|
if (!disabled && !readOnly && inputRef.current) {
|
|
1285
1141
|
inputRef.current.removeEventListener('click', onClickInput);
|
|
@@ -1291,16 +1147,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1291
1147
|
if (!disabled && !readOnly) {
|
|
1292
1148
|
inputRef.current.addEventListener('click', onClickInput);
|
|
1293
1149
|
}
|
|
1294
|
-
|
|
1295
1150
|
if (dropdownListRef.current) {
|
|
1296
1151
|
var _dropdownListRef$curr5, _dropdownListRef$curr6, _currentObjectDefault6;
|
|
1297
|
-
|
|
1298
1152
|
if (!disabled && !readOnly) {
|
|
1299
1153
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1300
1154
|
}
|
|
1301
|
-
|
|
1302
1155
|
const length = (_dropdownListRef$curr5 = dropdownListRef.current) === null || _dropdownListRef$curr5 === void 0 ? void 0 : (_dropdownListRef$curr6 = _dropdownListRef$curr5.children) === null || _dropdownListRef$curr6 === void 0 ? void 0 : _dropdownListRef$curr6.length;
|
|
1303
|
-
|
|
1304
1156
|
if (length < dataSource.length + ((_currentObjectDefault6 = currentObjectDefault[unique]) === null || _currentObjectDefault6 === void 0 ? void 0 : _currentObjectDefault6.length) && !isSearch[unique]) {
|
|
1305
1157
|
loadMoreItemsDropdown(length);
|
|
1306
1158
|
!!onLoadMore && dataSource.length < total && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
@@ -1312,20 +1164,17 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1312
1164
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1313
1165
|
}
|
|
1314
1166
|
}
|
|
1315
|
-
|
|
1316
1167
|
return () => {
|
|
1317
1168
|
if (inputRef.current) {
|
|
1318
1169
|
inputRef.current.removeEventListener('input', onChangeInput);
|
|
1319
1170
|
inputRef.current.removeEventListener('click', onClickInput);
|
|
1320
1171
|
}
|
|
1321
|
-
|
|
1322
1172
|
!!dropdownListRef.current && dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
1323
1173
|
};
|
|
1324
1174
|
}, [dataSource]);
|
|
1325
1175
|
/* End handler */
|
|
1326
1176
|
|
|
1327
1177
|
/* Start component */
|
|
1328
|
-
|
|
1329
1178
|
const EmptyDataText = jsx("div", {
|
|
1330
1179
|
css: _DropdownItemCSS,
|
|
1331
1180
|
className: 'no-data'
|
|
@@ -1335,20 +1184,17 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1335
1184
|
disabled: disabled,
|
|
1336
1185
|
...labelProps
|
|
1337
1186
|
}, label) : null, [label, required, disabled, labelProps]);
|
|
1338
|
-
|
|
1339
1187
|
const getData = () => {
|
|
1340
1188
|
let dataFilter = JSON.parse(JSON.stringify(dataSource));
|
|
1341
|
-
|
|
1342
1189
|
if (Array.isArray(valueObjectDefault)) {
|
|
1343
1190
|
dataFilter = [...dataFilter, ...dataChoosen.current, ...valueObjectDefault];
|
|
1344
1191
|
} else if (typeof valueObjectDefault === 'object') {
|
|
1345
|
-
dataFilter = [...dataFilter, ...dataChoosen.current, {
|
|
1192
|
+
dataFilter = [...dataFilter, ...dataChoosen.current, {
|
|
1193
|
+
...valueObjectDefault
|
|
1346
1194
|
}];
|
|
1347
1195
|
}
|
|
1348
|
-
|
|
1349
1196
|
return dataFilter;
|
|
1350
1197
|
};
|
|
1351
|
-
|
|
1352
1198
|
const InputView = useMemo(() => {
|
|
1353
1199
|
return jsx("div", {
|
|
1354
1200
|
css: _DropdownFormCSS,
|
|
@@ -1358,7 +1204,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1358
1204
|
}, jsx("div", {
|
|
1359
1205
|
css: _InputCSS,
|
|
1360
1206
|
className: 'DGN-UI-Dropdown-Form-Input'
|
|
1361
|
-
}, multiple && valueMulti !== null && valueMulti !== void 0 && valueMulti.length ? jsx("div", {
|
|
1207
|
+
}, multiple && valueMulti !== null && valueMulti !== void 0 && valueMulti.length ? jsx("div", {
|
|
1208
|
+
...inputProps,
|
|
1362
1209
|
style: {
|
|
1363
1210
|
cursor: 'text',
|
|
1364
1211
|
gap: spacing(0.5),
|
|
@@ -1375,24 +1222,19 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1375
1222
|
let dataFilter = getData();
|
|
1376
1223
|
const data = dataFilter.find(v => v[valueExpr] === vl);
|
|
1377
1224
|
let text = '';
|
|
1378
|
-
|
|
1379
1225
|
if (data) {
|
|
1380
1226
|
var _mask;
|
|
1381
|
-
|
|
1382
1227
|
displayExpr = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr || valueExpr;
|
|
1383
|
-
let mask = data === null || data === void 0 ? void 0 : data[displayExpr];
|
|
1228
|
+
let mask = data === null || data === void 0 ? void 0 : data[displayExpr];
|
|
1384
1229
|
|
|
1230
|
+
// convert {id} - {name} to {<data[id]>} - {<data[name]>}
|
|
1385
1231
|
if (!mask && regexBetween.test(displayExpr)) {
|
|
1386
1232
|
var _displayExpr4;
|
|
1387
|
-
|
|
1388
1233
|
mask = (_displayExpr4 = displayExpr) === null || _displayExpr4 === void 0 ? void 0 : _displayExpr4.replace(regexBetween, _ => data[_]);
|
|
1389
1234
|
}
|
|
1390
|
-
|
|
1391
1235
|
text = (_mask = mask) === null || _mask === void 0 ? void 0 : _mask.replace(regexInclude, '');
|
|
1392
1236
|
}
|
|
1393
|
-
|
|
1394
1237
|
let item = null;
|
|
1395
|
-
|
|
1396
1238
|
if (typeof renderSelectedItem === 'function') {
|
|
1397
1239
|
item = renderSelectedItem({
|
|
1398
1240
|
data,
|
|
@@ -1409,9 +1251,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1409
1251
|
onRemove: e => onRemove(e, vl)
|
|
1410
1252
|
});
|
|
1411
1253
|
}
|
|
1412
|
-
|
|
1413
1254
|
return item;
|
|
1414
|
-
})) : typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none' ? jsx("div", {
|
|
1255
|
+
})) : typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none' ? jsx("div", {
|
|
1256
|
+
...inputProps,
|
|
1415
1257
|
// contentEditable={!disabled && !allowSearch}
|
|
1416
1258
|
style: inputStyle,
|
|
1417
1259
|
ref: inputRef,
|
|
@@ -1480,15 +1322,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1480
1322
|
className: ['DGN-UI-Dropdown', className, error && 'error', loading && 'dgn-dropdown-loading', disabled ? 'disabled' : readOnly && 'readOnly'].join(' ').trim().replace(/\s+/g, ' ')
|
|
1481
1323
|
}, LabelView, InputView, ErrorView), DropdownView);
|
|
1482
1324
|
}));
|
|
1483
|
-
/* Start styled */
|
|
1484
1325
|
|
|
1326
|
+
/* Start styled */
|
|
1485
1327
|
const InputCSS = (multiple, renderSelectedItem) => css`
|
|
1486
1328
|
${flexRow};
|
|
1487
1329
|
${positionRelative};
|
|
1488
1330
|
width: 100%;
|
|
1489
1331
|
${!multiple && renderSelectedItem ? `width: calc(100% - 34px)` : ''}
|
|
1490
1332
|
`;
|
|
1491
|
-
|
|
1492
1333
|
const DropdownInputCSS = (viewType, multiple, placeholder, renderSelectedItem, disabled) => css`
|
|
1493
1334
|
${flexRow};
|
|
1494
1335
|
${alignCenter};
|
|
@@ -1537,7 +1378,6 @@ const DropdownInputCSS = (viewType, multiple, placeholder, renderSelectedItem, d
|
|
|
1537
1378
|
`}
|
|
1538
1379
|
}
|
|
1539
1380
|
`;
|
|
1540
|
-
|
|
1541
1381
|
const IconCSS = (viewType, loading, showClear) => css`
|
|
1542
1382
|
${flexRow};
|
|
1543
1383
|
${alignCenter};
|
|
@@ -1552,7 +1392,6 @@ const IconCSS = (viewType, loading, showClear) => css`
|
|
|
1552
1392
|
display: ${loading ? 'flex' : 'none'};
|
|
1553
1393
|
}
|
|
1554
1394
|
`;
|
|
1555
|
-
|
|
1556
1395
|
const DropdownFormCSS = (viewType, multiple, disabled, placeholder, DropdownInputCSSName) => viewType !== 'outlined' ? css`
|
|
1557
1396
|
${flexRow};
|
|
1558
1397
|
${alignCenter};
|
|
@@ -1667,7 +1506,6 @@ const DropdownFormCSS = (viewType, multiple, disabled, placeholder, DropdownInpu
|
|
|
1667
1506
|
border: 2px solid transparent;
|
|
1668
1507
|
}
|
|
1669
1508
|
`;
|
|
1670
|
-
|
|
1671
1509
|
const DropdownListCSS = loading => css`
|
|
1672
1510
|
${displayBlock};
|
|
1673
1511
|
${positionRelative};
|
|
@@ -1695,7 +1533,6 @@ const DropdownListCSS = loading => css`
|
|
|
1695
1533
|
padding: 1px;
|
|
1696
1534
|
}
|
|
1697
1535
|
`;
|
|
1698
|
-
|
|
1699
1536
|
const DropdownItemCSS = (multiple, selectBox) => css`
|
|
1700
1537
|
${flexRow};
|
|
1701
1538
|
${positionRelative};
|
|
@@ -1722,7 +1559,6 @@ const DropdownItemCSS = (multiple, selectBox) => css`
|
|
|
1722
1559
|
color: ${active};
|
|
1723
1560
|
}
|
|
1724
1561
|
`;
|
|
1725
|
-
|
|
1726
1562
|
const DropdownTextCSS = css`
|
|
1727
1563
|
${paragraph1};
|
|
1728
1564
|
color: inherit;
|
|
@@ -1736,7 +1572,6 @@ const DropdownTextCSS = css`
|
|
|
1736
1572
|
color: ${sub};
|
|
1737
1573
|
}
|
|
1738
1574
|
`;
|
|
1739
|
-
|
|
1740
1575
|
const DropdownRootCSS = (DropdownFormCSSName, IconCSSName, DropdownInputCSSName) => css`
|
|
1741
1576
|
${displayBlock};
|
|
1742
1577
|
${positionRelative};
|
|
@@ -1778,7 +1613,6 @@ const DropdownRootCSS = (DropdownFormCSSName, IconCSSName, DropdownInputCSSName)
|
|
|
1778
1613
|
}
|
|
1779
1614
|
}
|
|
1780
1615
|
`;
|
|
1781
|
-
|
|
1782
1616
|
const DropdownCSS = (top, left, width, isMobile, allowSearch) => css`
|
|
1783
1617
|
${positionFixed};
|
|
1784
1618
|
${parseWidth(width)};
|
|
@@ -1793,7 +1627,6 @@ const DropdownCSS = (top, left, width, isMobile, allowSearch) => css`
|
|
|
1793
1627
|
${flexColReverse.styles};
|
|
1794
1628
|
`}
|
|
1795
1629
|
`;
|
|
1796
|
-
|
|
1797
1630
|
const LoadingProgressCSS = css`
|
|
1798
1631
|
${flexRow};
|
|
1799
1632
|
${justifyCenter};
|
|
@@ -1842,34 +1675,24 @@ Dropdown.defaultProps = {
|
|
|
1842
1675
|
Dropdown.propTypes = {
|
|
1843
1676
|
/**The variant to use. */
|
|
1844
1677
|
viewType: PropTypes.oneOf(['underlined', 'outlined', 'none']),
|
|
1845
|
-
|
|
1846
1678
|
/** The mode of item when rendering. */
|
|
1847
1679
|
itemMode: PropTypes.oneOf(['normal', 'table', 'treeview']),
|
|
1848
|
-
|
|
1849
1680
|
/** Class for component. */
|
|
1850
1681
|
className: PropTypes.string,
|
|
1851
|
-
|
|
1852
1682
|
/** The label of the input. */
|
|
1853
1683
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
1854
|
-
|
|
1855
1684
|
/** The short hint displayed in the input before the user select a value. */
|
|
1856
1685
|
placeholder: PropTypes.string,
|
|
1857
|
-
|
|
1858
1686
|
/** Error displayed below input. */
|
|
1859
1687
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
1860
|
-
|
|
1861
1688
|
/** Used to identify the parent key (only used for `itemMode` is 'treeview'). */
|
|
1862
1689
|
treeViewID: PropTypes.string,
|
|
1863
|
-
|
|
1864
1690
|
/** Used for mapping into a nested list (only used for `itemMode` is 'treeview'). */
|
|
1865
1691
|
treeViewParentID: PropTypes.string,
|
|
1866
|
-
|
|
1867
1692
|
/** Specifies a text string shown when there is no data. */
|
|
1868
1693
|
noDataText: PropTypes.string,
|
|
1869
|
-
|
|
1870
1694
|
/** The icon to display if not found the icon follow `iconExpr`. */
|
|
1871
1695
|
iconDefault: PropTypes.string,
|
|
1872
|
-
|
|
1873
1696
|
/** Field name used for icon display.<br/>
|
|
1874
1697
|
* Example:<br/>
|
|
1875
1698
|
* string: 'icon'<br/>
|
|
@@ -1885,138 +1708,98 @@ Dropdown.propTypes = {
|
|
|
1885
1708
|
suffix: PropTypes.string,
|
|
1886
1709
|
style: PropTypes.object
|
|
1887
1710
|
})]),
|
|
1888
|
-
|
|
1889
1711
|
/** Default value displayed when first render. */
|
|
1890
1712
|
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1891
|
-
|
|
1892
1713
|
/** The displayed value of component. */
|
|
1893
1714
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1894
|
-
|
|
1895
1715
|
/** Field name used for text display in dropdown list.<br/>
|
|
1896
1716
|
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1897
1717
|
* Note: don't use 'id - name', return undefined
|
|
1898
1718
|
*/
|
|
1899
1719
|
displayExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1900
|
-
|
|
1901
1720
|
/** Display sub content. */
|
|
1902
1721
|
subText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
1903
|
-
|
|
1904
1722
|
/** The field name used for the returned result. */
|
|
1905
1723
|
valueExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
1906
|
-
|
|
1907
1724
|
/**
|
|
1908
1725
|
* Duration wait enter search content on search.<br/>
|
|
1909
1726
|
* Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
|
|
1910
1727
|
* If `true`, used default delayOnInput.
|
|
1911
1728
|
*/
|
|
1912
1729
|
searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
1913
|
-
|
|
1914
1730
|
/** Number of items is ignored. */
|
|
1915
1731
|
skip: PropTypes.number,
|
|
1916
|
-
|
|
1917
1732
|
/** Number of items that are rendered each time. */
|
|
1918
1733
|
limit: PropTypes.number,
|
|
1919
|
-
|
|
1920
1734
|
/** The total number of items in the dropdown list. */
|
|
1921
1735
|
total: PropTypes.number,
|
|
1922
|
-
|
|
1923
1736
|
/** If `true`, display clear icon.*/
|
|
1924
1737
|
clearAble: PropTypes.bool,
|
|
1925
|
-
|
|
1926
1738
|
/** If true, the loading indicator is shown. */
|
|
1927
1739
|
loading: PropTypes.bool,
|
|
1928
|
-
|
|
1929
1740
|
/** If true, the component is disabled. */
|
|
1930
1741
|
disabled: PropTypes.bool,
|
|
1931
|
-
|
|
1932
1742
|
/** If true, the component is read-only. */
|
|
1933
1743
|
readOnly: PropTypes.bool,
|
|
1934
|
-
|
|
1935
1744
|
/** If `true`, dropdown will close after select an item. */
|
|
1936
1745
|
closeAfterSelect: PropTypes.bool,
|
|
1937
|
-
|
|
1938
1746
|
/** If `true`, the label will indicate that the input is required. */
|
|
1939
1747
|
required: PropTypes.bool,
|
|
1940
|
-
|
|
1941
1748
|
/** If `true`, value must be an array and the dropdown will support multiple selections. */
|
|
1942
1749
|
multiple: PropTypes.bool,
|
|
1943
|
-
|
|
1944
1750
|
/** If `true`, display input box search. */
|
|
1945
1751
|
allowSearch: PropTypes.bool,
|
|
1946
|
-
|
|
1947
1752
|
/** If `true`, show checkbox in each dropdown item. */
|
|
1948
1753
|
selectBox: PropTypes.bool,
|
|
1949
|
-
|
|
1950
1754
|
/** An object default for value (use for load more). */
|
|
1951
1755
|
valueObjectDefault: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
1952
|
-
|
|
1953
1756
|
/** Style inline of component. */
|
|
1954
1757
|
style: PropTypes.object,
|
|
1955
|
-
|
|
1956
1758
|
/** Attributes applied to the input element. */
|
|
1957
1759
|
inputProps: PropTypes.object,
|
|
1958
|
-
|
|
1959
1760
|
/** Style inline of input element. */
|
|
1960
1761
|
inputStyle: PropTypes.object,
|
|
1961
|
-
|
|
1962
1762
|
/** Style inline of box contain input and icon. */
|
|
1963
1763
|
formStyle: PropTypes.object,
|
|
1964
|
-
|
|
1965
1764
|
/** Style inline of label. */
|
|
1966
1765
|
labelProps: PropTypes.object,
|
|
1967
|
-
|
|
1968
1766
|
/** Style inline of error. */
|
|
1969
1767
|
errorStyle: PropTypes.object,
|
|
1970
|
-
|
|
1971
1768
|
/** Style inline of dropdown items. */
|
|
1972
1769
|
dropdownItemStyle: PropTypes.object,
|
|
1973
|
-
|
|
1974
1770
|
/** The array of elements that appear in the dropdown list. */
|
|
1975
1771
|
dataSource: PropTypes.array,
|
|
1976
|
-
|
|
1977
1772
|
/** Function displays items by custom.<br/>
|
|
1978
1773
|
* renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
|
|
1979
1774
|
* --> such as: displayExpr={'name - role'}
|
|
1980
1775
|
*/
|
|
1981
1776
|
renderItem: PropTypes.func,
|
|
1982
|
-
|
|
1983
1777
|
/** Function or field name used for display selected items, example:<br/>
|
|
1984
1778
|
* renderSelectedItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
1985
1779
|
*/
|
|
1986
1780
|
renderSelectedItem: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
1987
|
-
|
|
1988
1781
|
/** Callback fired when the input value changes.<br/>
|
|
1989
1782
|
* if undefined: the filter function will run (default)
|
|
1990
1783
|
*/
|
|
1991
1784
|
onInput: PropTypes.func,
|
|
1992
|
-
|
|
1993
1785
|
/** Callback fired when key down input */
|
|
1994
1786
|
onKeyDown: PropTypes.func,
|
|
1995
|
-
|
|
1996
1787
|
/** Callback fired when the value changes. */
|
|
1997
1788
|
onChange: PropTypes.func,
|
|
1998
|
-
|
|
1999
1789
|
/** Callback fired when scroll near the end. */
|
|
2000
1790
|
onLoadMore: PropTypes.func,
|
|
2001
|
-
|
|
2002
1791
|
/** Callback fired when dropdown closed. */
|
|
2003
1792
|
onClosed: PropTypes.func,
|
|
2004
|
-
|
|
2005
1793
|
/** The contents in Dropdown box (Exp: TreeView). */
|
|
2006
1794
|
children: PropTypes.node,
|
|
2007
|
-
|
|
2008
1795
|
/** Specifies a data object's field name or an expression whose value is compared to the search string. */
|
|
2009
1796
|
searchExpr: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
|
|
2010
|
-
|
|
2011
1797
|
/** Specifies a comparison operation used to search items. */
|
|
2012
1798
|
searchMode: PropTypes.oneOf(['contains', 'startswith', 'equals']),
|
|
2013
|
-
|
|
2014
1799
|
/** Set restrictions regarding the maximum number of options that can be selected. (Use with prop `multiple`) */
|
|
2015
1800
|
maximumSelectionLength: PropTypes.number,
|
|
2016
|
-
|
|
2017
1801
|
/** If `true`, show multi-line selected item(s). */
|
|
2018
1802
|
multilineSelectedItem: PropTypes.bool,
|
|
2019
|
-
|
|
2020
1803
|
/**
|
|
2021
1804
|
* ref methods
|
|
2022
1805
|
*
|