diginet-core-ui 1.3.98 → 1.3.99-beta.2
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/form-control/attachment/index.js +26 -16
- package/components/form-control/date-picker/index.js +1 -0
- package/components/form-control/dropdown/index.js +178 -61
- package/components/form-control/input-base/index.js +95 -114
- package/components/form-control/number-input/index2.js +25 -10
- package/components/form-control/time-picker/v2/index.js +755 -0
- package/components/index.js +1 -1
- package/components/tab/tab-container.js +1 -10
- package/components/tab/tab-header.js +6 -11
- package/components/tab/tab-panel.js +7 -14
- package/components/tab/tab.js +16 -24
- package/global/index.js +6 -0
- package/package.json +62 -31
- package/readme.md +6 -0
- package/styles/general.js +7 -1
- package/styles/typography.js +40 -7
|
@@ -478,15 +478,18 @@ const Attachment = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
478
478
|
};
|
|
479
479
|
|
|
480
480
|
const checkExistingFile = newFile => {
|
|
481
|
-
const files =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
481
|
+
const files = [...dataState, ...newDataState];
|
|
482
|
+
return files.some(file => ((file === null || file === void 0 ? void 0 : file.FileName) || (file === null || file === void 0 ? void 0 : file.name)) === ((newFile === null || newFile === void 0 ? void 0 : newFile.FileName) || (newFile === null || newFile === void 0 ? void 0 : newFile.name)) && ((file === null || file === void 0 ? void 0 : file.FileSize) || (file === null || file === void 0 ? void 0 : file.size)) === ((newFile === null || newFile === void 0 ? void 0 : newFile.FileSize) || (newFile === null || newFile === void 0 ? void 0 : newFile.size)));
|
|
483
|
+
// const files = allNewAttached.getAll('files');
|
|
484
|
+
// if (files && files.length) {
|
|
485
|
+
// const length = files.length;
|
|
486
|
+
// for (let i = 0; i < length; i++) {
|
|
487
|
+
// if (parseStringify(newFile) === parseStringify(files[i])) return true;
|
|
488
|
+
// }
|
|
489
|
+
// }
|
|
490
|
+
// return false;
|
|
489
491
|
};
|
|
492
|
+
|
|
490
493
|
const checkAcceptFileType = newFile => {
|
|
491
494
|
if (!accept || !accept.length) return true;
|
|
492
495
|
const type = typeof accept === 'string' ? accept : accept.join('-');
|
|
@@ -682,14 +685,17 @@ const Attachment = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
682
685
|
document.removeEventListener('keydown', onKeyDown);
|
|
683
686
|
document.removeEventListener('click', clickOutOfItem);
|
|
684
687
|
};
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
688
|
+
|
|
689
|
+
// const parseStringify = fileInfo =>
|
|
690
|
+
// JSON.stringify({
|
|
691
|
+
// lastModified: fileInfo.lastModified,
|
|
692
|
+
// lastModifiedDate: fileInfo.lastModifiedDate,
|
|
693
|
+
// name: fileInfo.name,
|
|
694
|
+
// size: fileInfo.size,
|
|
695
|
+
// type: fileInfo.type,
|
|
696
|
+
// webkitRelativePath: fileInfo.webkitRelativePath,
|
|
697
|
+
// });
|
|
698
|
+
|
|
693
699
|
const mountDomain = item => {
|
|
694
700
|
if (!item) return item;
|
|
695
701
|
const cloneItem = JSON.parse(JSON.stringify(item));
|
|
@@ -777,6 +783,9 @@ const Attachment = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
777
783
|
}
|
|
778
784
|
};
|
|
779
785
|
}, [data]);
|
|
786
|
+
useEffect(() => {
|
|
787
|
+
setNewDataState([]);
|
|
788
|
+
}, [dataState]);
|
|
780
789
|
useEffect(() => {
|
|
781
790
|
if (inputProps && Object.keys(inputProps).length) {
|
|
782
791
|
Object.keys(inputProps).forEach(name => {
|
|
@@ -1299,6 +1308,7 @@ Attachment.defaultProps = {
|
|
|
1299
1308
|
fileType: getGlobal(['errorDefault', 'fileType']),
|
|
1300
1309
|
existingFile: getGlobal(['errorDefault', 'existingFile'])
|
|
1301
1310
|
},
|
|
1311
|
+
viewType: 'detail',
|
|
1302
1312
|
...getGlobal(['components', 'attachment', 'defaultProps'])
|
|
1303
1313
|
};
|
|
1304
1314
|
Attachment.propTypes = {
|
|
@@ -543,6 +543,7 @@ DatePicker.defaultProps = {
|
|
|
543
543
|
disabled: false,
|
|
544
544
|
displayAnotherMonth: true,
|
|
545
545
|
displayFormat: locale.get() === 'vi' ? 'DD/MM/YYYY' : 'MM/DD/YYYY',
|
|
546
|
+
placeholder: getGlobal('inputPlaceholder'),
|
|
546
547
|
pressESCToClose: true,
|
|
547
548
|
readOnly: false,
|
|
548
549
|
required: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
|
-
import { Avatar, ButtonIcon, Checkbox, Chip, CircularProgress, HelperText, InputBase, Label, TreeView, Typography } from "../..";
|
|
4
|
+
import { Avatar, ButtonIcon, Checkbox, Chip, CircularProgress, HelperText, InputBase, Label, Popup, TreeView, Typography } from "../..";
|
|
5
5
|
import Popover from "../../popover";
|
|
6
6
|
import { getGlobal } from "../../../global";
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
@@ -33,6 +33,16 @@ const convertData = (dt, valueExpr) => {
|
|
|
33
33
|
valueTemp = valueTemp.map(i => i[valueExpr] || i);
|
|
34
34
|
return valueTemp;
|
|
35
35
|
};
|
|
36
|
+
const convertSearchDelayTime = searchDelayTime => {
|
|
37
|
+
var _searchDelayTime$matc, _searchDelayTime$matc2;
|
|
38
|
+
if (searchDelayTime === true) return getGlobal('delayOnInput');
|
|
39
|
+
const units = {
|
|
40
|
+
m: 60000,
|
|
41
|
+
s: 1000,
|
|
42
|
+
ms: 1
|
|
43
|
+
};
|
|
44
|
+
return typeof searchDelayTime === 'number' ? searchDelayTime : (((_searchDelayTime$matc = searchDelayTime.match(/[^a-z]+/i)) === null || _searchDelayTime$matc === void 0 ? void 0 : _searchDelayTime$matc[0]) || 1) * units[((_searchDelayTime$matc2 = searchDelayTime.match(/ms|s|m/i)) === null || _searchDelayTime$matc2 === void 0 ? void 0 : _searchDelayTime$matc2[0]) || 's'];
|
|
45
|
+
};
|
|
36
46
|
const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
37
47
|
action = {},
|
|
38
48
|
allowSearch,
|
|
@@ -73,6 +83,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
73
83
|
searchExpr,
|
|
74
84
|
searchMode,
|
|
75
85
|
selectBox,
|
|
86
|
+
skip,
|
|
76
87
|
style,
|
|
77
88
|
subText,
|
|
78
89
|
total,
|
|
@@ -86,6 +97,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
86
97
|
if (!reference) reference = useRef(null);
|
|
87
98
|
if (multiple && selectBox === undefined) selectBox = true;
|
|
88
99
|
if (typeof searchExpr === 'string') searchExpr = [searchExpr];
|
|
100
|
+
searchDelayTime = convertSearchDelayTime(searchDelayTime);
|
|
89
101
|
const ref = useRef(null);
|
|
90
102
|
const dropdownRef = useRef(null);
|
|
91
103
|
const timer = useRef(null);
|
|
@@ -96,9 +108,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
96
108
|
const dropdownListRef = useRef(null);
|
|
97
109
|
const searchRef = useRef(null);
|
|
98
110
|
// const lastSearchRef = useRef(null);
|
|
99
|
-
const timeout = useRef(null);
|
|
111
|
+
// const timeout = useRef(null);
|
|
100
112
|
const loadMoreTimer = useRef(null);
|
|
101
113
|
const dataChosen = useRef([]);
|
|
114
|
+
const popupRef = useRef(null);
|
|
115
|
+
const filter = useRef({
|
|
116
|
+
skip: skip || 0,
|
|
117
|
+
limit: limit || 50
|
|
118
|
+
});
|
|
102
119
|
const [unique] = useState(randomString(6, {
|
|
103
120
|
allowNumber: false,
|
|
104
121
|
allowSymbol: false
|
|
@@ -108,6 +125,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
108
125
|
const [textValue, setTextValue] = useState('');
|
|
109
126
|
const [txtSearch, setTxtSearch] = useState('');
|
|
110
127
|
const [popoverWidth, setPopoverWidth] = useState(0);
|
|
128
|
+
const [loadingState, setLoadingState] = useState(loading);
|
|
129
|
+
const [totalState, setTotalState] = useState(total);
|
|
130
|
+
const [dataSourceState, setDataSourceState] = useState(dataSource);
|
|
131
|
+
const [popupDataState, setPopupDataState] = useState({
|
|
132
|
+
title: '',
|
|
133
|
+
substitle: '',
|
|
134
|
+
description: ''
|
|
135
|
+
});
|
|
111
136
|
let valueTemp = valueProp || defaultValue || [];
|
|
112
137
|
|
|
113
138
|
// only mode multi
|
|
@@ -120,7 +145,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
120
145
|
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, disabled, readOnly, multilineSelectedItem);
|
|
121
146
|
const _IconCSS = IconCSS(viewType);
|
|
122
147
|
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, disabled, placeholder, _DropdownInputCSS.name);
|
|
123
|
-
const _DropdownListCSS = DropdownListCSS(
|
|
148
|
+
const _DropdownListCSS = DropdownListCSS(loadingState);
|
|
124
149
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
125
150
|
const _DropdownRootCSS = DropdownRootCSS(_DropdownFormCSS.name, _DropdownInputCSS.name);
|
|
126
151
|
|
|
@@ -137,7 +162,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
137
162
|
!!blur && inputRef.current.blur();
|
|
138
163
|
};
|
|
139
164
|
const onClickInput = e => {
|
|
140
|
-
if (disabled || readOnly ||
|
|
165
|
+
if (disabled || readOnly || loadingState) return;
|
|
141
166
|
if (!dropdownListRef.current) {
|
|
142
167
|
if (!multiple || !Array.from(inputRef.current.querySelectorAll('.DGN-UI-Chip')).some(item => item.contains(e === null || e === void 0 ? void 0 : e.target))) {
|
|
143
168
|
setOpenState(true);
|
|
@@ -170,7 +195,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
170
195
|
className: 'DGN-Dropdown-List',
|
|
171
196
|
onKeyDown: moveOnItem,
|
|
172
197
|
tabIndex: -1
|
|
173
|
-
},
|
|
198
|
+
}, dataSourceState !== null && dataSourceState !== void 0 && dataSourceState.length ? children : EmptyDataText) : itemMode === 'normal' ? mapDropdown() : mapTreeView();
|
|
174
199
|
// const { innerHeight } = window;
|
|
175
200
|
// const { top, left, height, width } = formRef.current.getBoundingClientRect();
|
|
176
201
|
|
|
@@ -209,12 +234,13 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
209
234
|
marginBottom: 1
|
|
210
235
|
},
|
|
211
236
|
onKeyDown: pressESCHandler,
|
|
237
|
+
readOnly: loadingState,
|
|
212
238
|
autoFocus: true
|
|
213
239
|
})) : null, multiple && maximumSelectionLength ? jsx(Typography, {
|
|
214
240
|
css: pd([2, 4])
|
|
215
241
|
}, getGlobal('selected'), " ", (valueMulti === null || valueMulti === void 0 ? void 0 : valueMulti.length) || 0, "/", maximumSelectionLength) : null, jsx("div", {
|
|
216
242
|
className: 'DGN-Dropdown-Box'
|
|
217
|
-
}, dropdown),
|
|
243
|
+
}, dropdown), loadingState ? jsx("div", {
|
|
218
244
|
css: LoadingProgressCSS,
|
|
219
245
|
className: 'DGN-Dropdown-Loading-Progress'
|
|
220
246
|
}, jsx(CircularProgress, {
|
|
@@ -228,7 +254,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
228
254
|
window.addEventListener('resize', customizeWidthDropdown);
|
|
229
255
|
// document.addEventListener('wheel', onWheelHandler);
|
|
230
256
|
// document.addEventListener('mousedown', onClickOutsideOfInput);
|
|
231
|
-
if (onLoadMore &&
|
|
257
|
+
if (onLoadMore && dataSourceState.length < totalState) {
|
|
232
258
|
dropdownListRef.current && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
233
259
|
}
|
|
234
260
|
}, 10);
|
|
@@ -344,7 +370,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
344
370
|
const mapDropdown = () => {
|
|
345
371
|
var _dataSourceUsable, _currentObjectDefault;
|
|
346
372
|
const items = [];
|
|
347
|
-
let dataSourceUsable = [...
|
|
373
|
+
let dataSourceUsable = [...dataSourceState];
|
|
348
374
|
|
|
349
375
|
// search dataSource dựa trên txtSearch
|
|
350
376
|
dataSourceUsable = (_dataSourceUsable = dataSourceUsable) === null || _dataSourceUsable === void 0 ? void 0 : _dataSourceUsable.filter(i => {
|
|
@@ -382,12 +408,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
382
408
|
// if (handleRenderBySearch(data, pattern)) continue;
|
|
383
409
|
// } else if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
|
|
384
410
|
|
|
385
|
-
if (
|
|
386
|
-
displayText = renderItem({
|
|
387
|
-
data,
|
|
388
|
-
index
|
|
389
|
-
});
|
|
390
|
-
} else if (subText) {
|
|
411
|
+
if (subText) {
|
|
391
412
|
displayText = jsx(Fragment, null, jsx(Typography, {
|
|
392
413
|
className: 'DGN-UI-Dropdown-PrimaryText',
|
|
393
414
|
type: 'p1'
|
|
@@ -403,7 +424,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
403
424
|
const value = typeof data === 'object' ? data[valueExpr] : data;
|
|
404
425
|
let itemDisabled = typeof data === 'object' ? data['disabled'] : false;
|
|
405
426
|
const icon = getIconFromData(data);
|
|
406
|
-
const text =
|
|
427
|
+
const text = renderItem && typeof renderItem === 'function' ? renderItem({
|
|
428
|
+
data,
|
|
429
|
+
index
|
|
430
|
+
}) : jsx(Typography, {
|
|
407
431
|
type: 'p1'
|
|
408
432
|
}, displayText);
|
|
409
433
|
if (multiple && selectBox) {
|
|
@@ -468,8 +492,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
468
492
|
className: 'DGN-Dropdown-List',
|
|
469
493
|
onKeyDown: moveOnItem,
|
|
470
494
|
tabIndex: -1
|
|
471
|
-
},
|
|
472
|
-
dataSource:
|
|
495
|
+
}, dataSourceState !== null && dataSourceState !== void 0 && dataSourceState.length ? jsx(TreeView, {
|
|
496
|
+
dataSource: dataSourceState,
|
|
473
497
|
displayExpr: displayExpr,
|
|
474
498
|
valueExpr: valueExpr,
|
|
475
499
|
multiple: multiple,
|
|
@@ -491,7 +515,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
491
515
|
// remove item cũ và append child item mới khi load more
|
|
492
516
|
const loadMoreItemsDropdown = (i = 0, pattern) => {
|
|
493
517
|
var _currentObjectDefault2, _displayExpr2;
|
|
494
|
-
const dataSourceUsable = [...
|
|
518
|
+
const dataSourceUsable = [...dataSourceState];
|
|
495
519
|
// Nếu có load more thì đẩy đội tượng mặc định lên đầu
|
|
496
520
|
let notExistItem = 0;
|
|
497
521
|
if (onLoadMore && (_currentObjectDefault2 = currentObjectDefault[unique]) !== null && _currentObjectDefault2 !== void 0 && _currentObjectDefault2.length) {
|
|
@@ -639,6 +663,65 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
639
663
|
// : updatePosition(formRef.current, dropdownRef.current, closeDropdown);
|
|
640
664
|
// };
|
|
641
665
|
|
|
666
|
+
const handleActionLoadData = isReset => {
|
|
667
|
+
const {
|
|
668
|
+
skip,
|
|
669
|
+
limit,
|
|
670
|
+
strSearch: search
|
|
671
|
+
} = filter.current;
|
|
672
|
+
const params = onLoadMore ? {
|
|
673
|
+
skip,
|
|
674
|
+
limit,
|
|
675
|
+
search
|
|
676
|
+
} : {
|
|
677
|
+
search
|
|
678
|
+
};
|
|
679
|
+
const callbackSave = (error, data) => {
|
|
680
|
+
setLoadingState(false);
|
|
681
|
+
if (error) {
|
|
682
|
+
let _data = {};
|
|
683
|
+
if (error.originalError) {
|
|
684
|
+
const {
|
|
685
|
+
message,
|
|
686
|
+
originalError,
|
|
687
|
+
customMessage,
|
|
688
|
+
code: codeError
|
|
689
|
+
} = error;
|
|
690
|
+
const _customMessage = customMessage && typeof customMessage === 'object' ? customMessage[codeError] : customMessage;
|
|
691
|
+
let messageError = '';
|
|
692
|
+
Object.keys(originalError).forEach(key => {
|
|
693
|
+
messageError += `${key}: ${JSON.stringify(originalError[key], null, 8)}\n`;
|
|
694
|
+
});
|
|
695
|
+
_data = {
|
|
696
|
+
title: getGlobal('error') + (codeError ? `: ${codeError}` : ''),
|
|
697
|
+
subtitle: _customMessage || message || getGlobal('unknownError'),
|
|
698
|
+
description: messageError
|
|
699
|
+
};
|
|
700
|
+
} else {
|
|
701
|
+
var _data$data;
|
|
702
|
+
const message = (data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.Message) || data;
|
|
703
|
+
_data = {
|
|
704
|
+
description: message || getGlobal('unknownError')
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
setPopupDataState(_data);
|
|
708
|
+
popupRef.current.instance.show();
|
|
709
|
+
return false;
|
|
710
|
+
} else if (data) {
|
|
711
|
+
let rows = [];
|
|
712
|
+
if (Array.isArray(data)) {
|
|
713
|
+
rows = data;
|
|
714
|
+
} else {
|
|
715
|
+
rows = data && data.rows ? data.rows : dataSourceState;
|
|
716
|
+
const total = data && data.total ? data.total : data.length;
|
|
717
|
+
setTotalState(total);
|
|
718
|
+
}
|
|
719
|
+
setDataSourceState(isReset ? rows : dataSourceState.concat(rows));
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
setLoadingState(true);
|
|
723
|
+
action.loadData(params, callbackSave);
|
|
724
|
+
};
|
|
642
725
|
const onLoadMoreHandler = e => {
|
|
643
726
|
if (loadMoreTimer.current) {
|
|
644
727
|
clearTimeout(loadMoreTimer.current);
|
|
@@ -653,12 +736,16 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
653
736
|
var _dropdownListRef$curr, _currentObjectDefault3;
|
|
654
737
|
const length = ((_dropdownListRef$curr = dropdownListRef.current.children) === null || _dropdownListRef$curr === void 0 ? void 0 : _dropdownListRef$curr.length) - (((_currentObjectDefault3 = currentObjectDefault[unique]) === null || _currentObjectDefault3 === void 0 ? void 0 : _currentObjectDefault3.length) || 0);
|
|
655
738
|
dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
656
|
-
!!onLoadMore && onLoadMore
|
|
739
|
+
if (!!onLoadMore && typeof onLoadMore === 'boolean' && action !== null && action !== void 0 && action.loadData) {
|
|
740
|
+
filter.current.skip = length;
|
|
741
|
+
filter.current.limit = limit;
|
|
742
|
+
handleActionLoadData();
|
|
743
|
+
} else !!onLoadMore && onLoadMore({
|
|
657
744
|
skip: length,
|
|
658
745
|
limit: limit
|
|
659
746
|
});
|
|
660
747
|
}
|
|
661
|
-
});
|
|
748
|
+
}, 300);
|
|
662
749
|
};
|
|
663
750
|
const onPreventKeyDownHandler = e => {
|
|
664
751
|
e.preventDefault();
|
|
@@ -691,6 +778,11 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
691
778
|
// }
|
|
692
779
|
// return;
|
|
693
780
|
}
|
|
781
|
+
|
|
782
|
+
if (action !== null && action !== void 0 && action.loadData && !!onLoadMore) {
|
|
783
|
+
filter.current.strSearch = e.target.value;
|
|
784
|
+
handleActionLoadData(true);
|
|
785
|
+
}
|
|
694
786
|
// const value = e.target.value || e.target.textContent;
|
|
695
787
|
// if (
|
|
696
788
|
// typeof renderSelectedItem === 'function' &&
|
|
@@ -712,7 +804,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
712
804
|
if (valueProp === undefined) {
|
|
713
805
|
setValueMulti(value);
|
|
714
806
|
setValueIntoInput(value);
|
|
715
|
-
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !
|
|
807
|
+
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !loadingState);
|
|
716
808
|
}
|
|
717
809
|
!!onChange && onChange({
|
|
718
810
|
value
|
|
@@ -831,7 +923,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
831
923
|
});
|
|
832
924
|
};
|
|
833
925
|
const onClear = e => {
|
|
834
|
-
if (disabled || readOnly ||
|
|
926
|
+
if (disabled || readOnly || loadingState || !clearAble) return;
|
|
835
927
|
currentValue[unique] = multiple ? [] : '';
|
|
836
928
|
if (multiple) {
|
|
837
929
|
setValueMulti([]);
|
|
@@ -850,7 +942,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
850
942
|
onInput === null || onInput === void 0 ? void 0 : onInput({
|
|
851
943
|
...(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current),
|
|
852
944
|
target: {
|
|
853
|
-
value:
|
|
945
|
+
value: ''
|
|
854
946
|
}
|
|
855
947
|
});
|
|
856
948
|
!!onChange && onChange({
|
|
@@ -877,7 +969,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
877
969
|
}
|
|
878
970
|
return;
|
|
879
971
|
}
|
|
880
|
-
const length =
|
|
972
|
+
const length = dataSourceState.length;
|
|
881
973
|
const displayKey = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr;
|
|
882
974
|
if (displayKey && Array.isArray(displayKey)) {
|
|
883
975
|
displayExpr = displayExpr.join(' - ');
|
|
@@ -894,8 +986,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
894
986
|
valueArr.forEach(v => {
|
|
895
987
|
var _currentObjectDefault4;
|
|
896
988
|
for (let i = 0; i < length; i++) {
|
|
897
|
-
if (typeof
|
|
898
|
-
setMultipleValueHandler(
|
|
989
|
+
if (typeof dataSourceState[i] === 'object' && dataSourceState[i][valueExpr] === v || dataSourceState[i] === v) {
|
|
990
|
+
setMultipleValueHandler(dataSourceState[i], v, keyArr, i);
|
|
899
991
|
return;
|
|
900
992
|
}
|
|
901
993
|
}
|
|
@@ -910,8 +1002,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
910
1002
|
var _currentObjectDefault5;
|
|
911
1003
|
currentValue[unique] = source;
|
|
912
1004
|
for (let i = 0; i < length; i++) {
|
|
913
|
-
if (
|
|
914
|
-
setSingleValueHandler(
|
|
1005
|
+
if (dataSourceState[i][valueExpr] === source || dataSourceState[i] === source) {
|
|
1006
|
+
setSingleValueHandler(dataSourceState[i], keyArr);
|
|
915
1007
|
return;
|
|
916
1008
|
}
|
|
917
1009
|
}
|
|
@@ -961,11 +1053,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
961
1053
|
}, content);
|
|
962
1054
|
if (typeof renderSelectedItem === 'function') {
|
|
963
1055
|
inputRef.current.innerHTML = '';
|
|
964
|
-
const item =
|
|
1056
|
+
const item = renderSelectedItem({
|
|
965
1057
|
data
|
|
966
|
-
})
|
|
1058
|
+
});
|
|
967
1059
|
const el = document.createElement('div');
|
|
968
1060
|
el.style.display = 'flex';
|
|
1061
|
+
el.style.width = '100%';
|
|
969
1062
|
el.style.minHeight = '24px';
|
|
970
1063
|
if (!multilineSelectedItem) el.style.maxHeight = '24px';
|
|
971
1064
|
ReactDOM.render(item, inputRef.current.appendChild(el));
|
|
@@ -1017,8 +1110,17 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1017
1110
|
return currentRef;
|
|
1018
1111
|
});
|
|
1019
1112
|
useEffect(() => {
|
|
1020
|
-
|
|
1021
|
-
}, [
|
|
1113
|
+
setLoadingState(loading);
|
|
1114
|
+
}, [loading]);
|
|
1115
|
+
useEffect(() => {
|
|
1116
|
+
setTotalState(total);
|
|
1117
|
+
}, [total]);
|
|
1118
|
+
useEffect(() => {
|
|
1119
|
+
setDataSourceState(dataSource);
|
|
1120
|
+
}, [dataSource]);
|
|
1121
|
+
useEffect(() => {
|
|
1122
|
+
setShowClear(clearAble && checkHasValue(valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue) && !disabled && !readOnly && !loadingState);
|
|
1123
|
+
}, [clearAble, valueProp, defaultValue, disabled, readOnly, loadingState]);
|
|
1022
1124
|
useEffect(() => {
|
|
1023
1125
|
if (valueObjectDefault) {
|
|
1024
1126
|
if (Array.isArray(valueObjectDefault)) {
|
|
@@ -1037,28 +1139,34 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1037
1139
|
allValue[unique] = [];
|
|
1038
1140
|
if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
|
|
1039
1141
|
setValueIntoInput(defaultValue);
|
|
1040
|
-
setShowClear(clearAble && checkHasValue(defaultValue) && !disabled && !readOnly && !
|
|
1142
|
+
setShowClear(clearAble && checkHasValue(defaultValue) && !disabled && !readOnly && !loadingState);
|
|
1041
1143
|
}
|
|
1144
|
+
if (action !== null && action !== void 0 && action.loadData) handleActionLoadData();
|
|
1042
1145
|
return () => {
|
|
1043
1146
|
allValue[unique] = null;
|
|
1044
1147
|
closeDropdown();
|
|
1045
1148
|
};
|
|
1046
1149
|
}, []);
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1150
|
+
|
|
1151
|
+
// useEffect(() => {
|
|
1152
|
+
// if (searchDelayTime) {
|
|
1153
|
+
// if (searchDelayTime === true) searchDelayTime = getGlobal('delayOnInput');
|
|
1154
|
+
// const units = {
|
|
1155
|
+
// m: 60000,
|
|
1156
|
+
// s: 1000,
|
|
1157
|
+
// ms: 1,
|
|
1158
|
+
// };
|
|
1159
|
+
// timeout.current =
|
|
1160
|
+
// typeof searchDelayTime === 'number'
|
|
1161
|
+
// ? searchDelayTime
|
|
1162
|
+
// : (searchDelayTime.match(/[^a-z]+/i)?.[0] || 1) *
|
|
1163
|
+
// units[searchDelayTime.match(/ms|s|m/i)?.[0] || 's'];
|
|
1164
|
+
// return () => {
|
|
1165
|
+
// timeout.current = null;
|
|
1166
|
+
// };
|
|
1167
|
+
// }
|
|
1168
|
+
// }, [searchDelayTime]);
|
|
1169
|
+
|
|
1062
1170
|
useEffect(() => {
|
|
1063
1171
|
if (allValue[unique][allValue[unique].length - 1] !== valueProp) {
|
|
1064
1172
|
allValue[unique].push(valueProp);
|
|
@@ -1072,10 +1180,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1072
1180
|
}
|
|
1073
1181
|
}, [valueProp]);
|
|
1074
1182
|
useEffect(() => {
|
|
1075
|
-
if (
|
|
1183
|
+
if (
|
|
1184
|
+
// valueProp !== undefined &&
|
|
1185
|
+
!dropdownListRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique])) {
|
|
1076
1186
|
setValueIntoInput(valueProp);
|
|
1077
1187
|
}
|
|
1078
|
-
}, [valueProp,
|
|
1188
|
+
}, [valueProp, dataSourceState]);
|
|
1079
1189
|
useEffect(() => {
|
|
1080
1190
|
inputRef.current.readOnly = readOnly || inputProps.readOnly;
|
|
1081
1191
|
if (!readOnly && !disabled) {
|
|
@@ -1118,9 +1228,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1118
1228
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1119
1229
|
}
|
|
1120
1230
|
const length = (_dropdownListRef$curr2 = dropdownListRef.current) === null || _dropdownListRef$curr2 === void 0 ? void 0 : (_dropdownListRef$curr3 = _dropdownListRef$curr2.children) === null || _dropdownListRef$curr3 === void 0 ? void 0 : _dropdownListRef$curr3.length;
|
|
1121
|
-
if (length <
|
|
1231
|
+
if (length < dataSourceState.length + ((_currentObjectDefault6 = currentObjectDefault[unique]) === null || _currentObjectDefault6 === void 0 ? void 0 : _currentObjectDefault6.length) && !isSearch[unique]) {
|
|
1122
1232
|
loadMoreItemsDropdown(length);
|
|
1123
|
-
!!onLoadMore &&
|
|
1233
|
+
!!onLoadMore && dataSourceState.length < totalState && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
1124
1234
|
} else {
|
|
1125
1235
|
isSearch[unique] = false;
|
|
1126
1236
|
}
|
|
@@ -1136,7 +1246,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1136
1246
|
}
|
|
1137
1247
|
!!dropdownListRef.current && dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
1138
1248
|
};
|
|
1139
|
-
}, [
|
|
1249
|
+
}, [dataSourceState]);
|
|
1140
1250
|
useLayoutEffect(() => {
|
|
1141
1251
|
if (ref.current) {
|
|
1142
1252
|
const {
|
|
@@ -1158,7 +1268,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1158
1268
|
...labelProps
|
|
1159
1269
|
}, label) : null, [label, required, disabled, labelProps]);
|
|
1160
1270
|
const getData = () => {
|
|
1161
|
-
let dataFilter = JSON.parse(JSON.stringify(
|
|
1271
|
+
let dataFilter = JSON.parse(JSON.stringify(dataSourceState));
|
|
1162
1272
|
if (Array.isArray(valueObjectDefault)) {
|
|
1163
1273
|
dataFilter = [...dataFilter, ...dataChosen.current, ...valueObjectDefault];
|
|
1164
1274
|
} else if (typeof valueObjectDefault === 'object') {
|
|
@@ -1254,14 +1364,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1254
1364
|
ref: iconRef,
|
|
1255
1365
|
css: _IconCSS,
|
|
1256
1366
|
className: 'DGN-UI-Dropdown-Icon'
|
|
1257
|
-
},
|
|
1367
|
+
}, loadingState ? jsx(CircularProgress, {
|
|
1258
1368
|
size: 24
|
|
1259
1369
|
}) : null, showClear ? jsx(ButtonIcon, {
|
|
1260
1370
|
css: mgr([1]),
|
|
1261
1371
|
viewType: 'ghost',
|
|
1262
1372
|
name: 'Close',
|
|
1263
1373
|
onClick: onClear
|
|
1264
|
-
}) : null, !
|
|
1374
|
+
}) : null, !loadingState ? jsx(ButtonIcon, {
|
|
1265
1375
|
key: openState,
|
|
1266
1376
|
css: animation,
|
|
1267
1377
|
viewType: 'ghost',
|
|
@@ -1269,7 +1379,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1269
1379
|
onClick: setShowDropdown,
|
|
1270
1380
|
disabled: disabled || readOnly
|
|
1271
1381
|
}) : null));
|
|
1272
|
-
}, [openState, showClear, textValue, valueMulti, clearAble, dataSource, disabled, displayExpr, inputProps, inputStyle,
|
|
1382
|
+
}, [openState, showClear, textValue, valueMulti, loadingState, dataSourceState, clearAble, dataSource, disabled, displayExpr, inputProps, inputStyle, multilineSelectedItem, multiple, onChange, placeholder, readOnly, renderSelectedItem, valueExpr, valueObjectDefault, viewType]);
|
|
1273
1383
|
const ErrorView = useMemo(() => {
|
|
1274
1384
|
return error ? jsx(HelperText, {
|
|
1275
1385
|
...helperTextProps,
|
|
@@ -1286,15 +1396,19 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1286
1396
|
onClose: closeDropdown
|
|
1287
1397
|
}, showDropdown());
|
|
1288
1398
|
// return openState ? createPortal(showDropdown(), document.body) : null;
|
|
1289
|
-
}, [openState, popoverWidth, valueMulti,
|
|
1399
|
+
}, [openState, popoverWidth, valueMulti, loadingState, dataSourceState, dataSource, maximumSelectionLength, multilineSelectedItem, multiple, selectBox, txtSearch]);
|
|
1290
1400
|
/* End component */
|
|
1291
1401
|
|
|
1292
1402
|
return jsx(Fragment, null, jsx("div", {
|
|
1293
1403
|
ref: ref,
|
|
1294
1404
|
css: _DropdownRootCSS,
|
|
1295
1405
|
style: style,
|
|
1296
|
-
className: classNames('DGN-UI-Dropdown', className, error && 'error',
|
|
1297
|
-
}, LabelView, InputView, ErrorView), DropdownView
|
|
1406
|
+
className: classNames('DGN-UI-Dropdown', className, error && 'error', loadingState && 'dgn-dropdown-loading', disabled ? 'disabled' : readOnly && 'readOnly')
|
|
1407
|
+
}, LabelView, InputView, ErrorView), DropdownView, jsx(Popup, {
|
|
1408
|
+
ref: popupRef,
|
|
1409
|
+
type: 'danger',
|
|
1410
|
+
...popupDataState
|
|
1411
|
+
}));
|
|
1298
1412
|
}));
|
|
1299
1413
|
|
|
1300
1414
|
/* Start styled */
|
|
@@ -1618,6 +1732,9 @@ Dropdown.defaultProps = {
|
|
|
1618
1732
|
viewType: 'underlined'
|
|
1619
1733
|
};
|
|
1620
1734
|
Dropdown.propTypes = {
|
|
1735
|
+
action: PropTypes.shape({
|
|
1736
|
+
loadData: PropTypes.func
|
|
1737
|
+
}),
|
|
1621
1738
|
/** If `true`, display input box search. */
|
|
1622
1739
|
allowSearch: PropTypes.bool,
|
|
1623
1740
|
/** The contents in Dropdown box (Exp: TreeView). */
|
|
@@ -1693,7 +1810,7 @@ Dropdown.propTypes = {
|
|
|
1693
1810
|
/** Callback fired when key down input */
|
|
1694
1811
|
onKeyDown: PropTypes.func,
|
|
1695
1812
|
/** Callback fired when scroll near the end. */
|
|
1696
|
-
onLoadMore: PropTypes.func,
|
|
1813
|
+
onLoadMore: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
|
|
1697
1814
|
/** The short hint displayed in the input before the user select a value. */
|
|
1698
1815
|
placeholder: PropTypes.string,
|
|
1699
1816
|
/** If `true`, the component is read-only. */
|