diginet-core-ui 1.3.99-beta.3 → 1.4.0
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 +0 -1
- package/components/form-control/calendar/function.js +33 -28
- package/components/form-control/calendar/index.js +3 -10
- package/components/form-control/date-picker/index.js +1 -2
- package/components/form-control/date-range-picker/index.js +5 -3
- package/components/form-control/dropdown/index.js +35 -137
- package/components/form-control/input-base/index.js +114 -95
- package/components/form-control/number-input/index2.js +10 -25
- package/components/index.js +1 -2
- package/global/index.js +0 -6
- package/package.json +31 -62
- package/readme.md +3 -0
- package/components/form-control/calendar/v2/function.js +0 -757
- package/components/form-control/calendar/v2/index.js +0 -293
- package/components/form-control/date-picker/v2/index.js +0 -611
- package/components/form-control/time-picker/v2/index.js +0 -755
|
@@ -1308,7 +1308,6 @@ Attachment.defaultProps = {
|
|
|
1308
1308
|
fileType: getGlobal(['errorDefault', 'fileType']),
|
|
1309
1309
|
existingFile: getGlobal(['errorDefault', 'existingFile'])
|
|
1310
1310
|
},
|
|
1311
|
-
viewType: 'detail',
|
|
1312
1311
|
...getGlobal(['components', 'attachment', 'defaultProps'])
|
|
1313
1312
|
};
|
|
1314
1313
|
Attachment.propTypes = {
|
|
@@ -5,7 +5,7 @@ import { Button, ButtonIcon, Typography } from "../..";
|
|
|
5
5
|
import { getGlobal } from "../../../global";
|
|
6
6
|
import locale from "../../../locale";
|
|
7
7
|
import { render } from 'react-dom';
|
|
8
|
-
import { bgColor, border, borderRadius, boxBorder, cursorDefault, cursorPointer, displayFlex, flexCol, flexRow,
|
|
8
|
+
import { bgColor, border, borderRadius, boxBorder, cursorDefault, cursorPointer, displayFlex, flexCol, flexRow, inset, itemsCenter, justifyBetween, mg, mgt, parseHeight, parseMaxWidth, parseMinWidth, parseWidth, parseWidthHeight, pd, pointerEventsNone, positionAbsolute, positionRelative, textCenter, textColor, userSelectNone } from "../../../styles/general";
|
|
9
9
|
import { useTheme } from "../../../theme";
|
|
10
10
|
import { date as moment } from "../../../utils";
|
|
11
11
|
const {
|
|
@@ -41,33 +41,23 @@ const generateCalendarCSS = (unique, boxShadow = true, onClickActive = true) =>
|
|
|
41
41
|
${itemsCenter};
|
|
42
42
|
${parseMaxWidth(400)};
|
|
43
43
|
${mg([4, 4, 0])};
|
|
44
|
-
${gap(8)};
|
|
45
44
|
.${unique.navigator.around} {
|
|
46
45
|
${displayFlex};
|
|
47
46
|
${flexRow};
|
|
48
47
|
}
|
|
49
48
|
.${unique.navigator.center} {
|
|
50
|
-
${displayFlex};
|
|
51
49
|
${parseWidth('100%')};
|
|
52
|
-
button {
|
|
53
|
-
&:hover {
|
|
54
|
-
${borderRadius(20)};
|
|
55
|
-
${bgColor('fill/hover')};
|
|
56
|
-
}
|
|
57
|
-
&:active {
|
|
58
|
-
${bgColor('fill/pressed')};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
.${unique.table.container} {
|
|
64
53
|
${displayFlex};
|
|
65
54
|
${flexRow};
|
|
66
|
-
${mg([2, 0
|
|
55
|
+
${mg([2, 0])};
|
|
67
56
|
}
|
|
68
57
|
.${unique.table.table} {
|
|
69
58
|
${mg([0, 4])};
|
|
70
|
-
${
|
|
59
|
+
${pd(0)};
|
|
60
|
+
${parseWidth('calc(100% - 32px)')};
|
|
71
61
|
border-collapse: separate;
|
|
72
62
|
table-layout: fixed;
|
|
73
63
|
.${unique.table.data} {
|
|
@@ -78,15 +68,15 @@ const generateCalendarCSS = (unique, boxShadow = true, onClickActive = true) =>
|
|
|
78
68
|
${userSelectNone};
|
|
79
69
|
${textColor('text/main')};
|
|
80
70
|
&:nth-of-type(7n - 1) {
|
|
81
|
-
${textColor('
|
|
71
|
+
${textColor('info8')};
|
|
82
72
|
}
|
|
83
73
|
&:nth-of-type(7n) {
|
|
84
|
-
${textColor('
|
|
74
|
+
${textColor('danger8')};
|
|
85
75
|
}
|
|
86
76
|
&.next_month,
|
|
87
77
|
&.previous_month,
|
|
88
78
|
&.${unique.day.limit} {
|
|
89
|
-
|
|
79
|
+
opacity: 0.25;
|
|
90
80
|
}
|
|
91
81
|
&.${unique.day.limit} {
|
|
92
82
|
${pointerEventsNone};
|
|
@@ -152,10 +142,10 @@ const generateCalendarCSS = (unique, boxShadow = true, onClickActive = true) =>
|
|
|
152
142
|
${parseHeight(24)};
|
|
153
143
|
${textColor('text/normal_label')};
|
|
154
144
|
&:nth-of-type(6) {
|
|
155
|
-
${textColor('
|
|
145
|
+
${textColor('info8')};
|
|
156
146
|
}
|
|
157
147
|
&:nth-of-type(7) {
|
|
158
|
-
${textColor('
|
|
148
|
+
${textColor('danger8')};
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
151
|
}
|
|
@@ -217,7 +207,7 @@ const typographyProps = className => {
|
|
|
217
207
|
transition: 'background-color 150ms linear',
|
|
218
208
|
width: 24
|
|
219
209
|
},
|
|
220
|
-
type: '
|
|
210
|
+
type: 'h6'
|
|
221
211
|
};
|
|
222
212
|
};
|
|
223
213
|
/**
|
|
@@ -230,7 +220,26 @@ const buttonIconProps = className => {
|
|
|
230
220
|
return {
|
|
231
221
|
className,
|
|
232
222
|
circular: true,
|
|
233
|
-
viewType: '
|
|
223
|
+
viewType: 'text',
|
|
224
|
+
size: 'small'
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* @description return props of the button icon.
|
|
230
|
+
* @param {Function} fn
|
|
231
|
+
* @returns {Object} props of the button text
|
|
232
|
+
*/
|
|
233
|
+
const buttonTextProps = fn => {
|
|
234
|
+
return {
|
|
235
|
+
onClick: fn,
|
|
236
|
+
color: 'primary',
|
|
237
|
+
size: 'small',
|
|
238
|
+
style: {
|
|
239
|
+
borderRadius: 20,
|
|
240
|
+
textTransform: 'initial',
|
|
241
|
+
width: '100%'
|
|
242
|
+
}
|
|
234
243
|
};
|
|
235
244
|
};
|
|
236
245
|
|
|
@@ -455,7 +464,7 @@ const renderHeader = className => {
|
|
|
455
464
|
className: className.table.header
|
|
456
465
|
}, jsx(Typography, {
|
|
457
466
|
color: 'inherit',
|
|
458
|
-
type: '
|
|
467
|
+
type: 'h6'
|
|
459
468
|
}, weekdays[i])));
|
|
460
469
|
}
|
|
461
470
|
return jsx("thead", null, jsx("tr", {
|
|
@@ -490,15 +499,11 @@ const renderNavigator = (className, refs, dbLeftFn, leftFn, rightFn, dbRightFn,
|
|
|
490
499
|
})), jsx("div", {
|
|
491
500
|
className: className.navigator.center
|
|
492
501
|
}, jsx(Button, {
|
|
493
|
-
|
|
494
|
-
colorHover: 'fill/hover',
|
|
495
|
-
size: 'tiny',
|
|
496
|
-
onClick: fn
|
|
502
|
+
...buttonTextProps(fn)
|
|
497
503
|
}, jsx(Typography, {
|
|
498
504
|
color: 'primary',
|
|
499
505
|
type: 'h3',
|
|
500
|
-
ref: refs.content
|
|
501
|
-
format: ['lowercase']
|
|
506
|
+
ref: refs.content
|
|
502
507
|
}))), jsx("div", {
|
|
503
508
|
className: className.navigator.around
|
|
504
509
|
}, jsx(ButtonIcon, {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
+
|
|
3
4
|
import { jsx } from '@emotion/core';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
6
7
|
import { date as moment } from "../../../utils";
|
|
7
|
-
import {
|
|
8
|
+
import { isAfterLimit, isBeforeLimit, onUpdateCalendar, renderHeader, renderNavigator, isValidDate, generateCalendarCSS } from "./function";
|
|
8
9
|
const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
9
10
|
actions,
|
|
10
11
|
className,
|
|
@@ -16,7 +17,6 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
16
17
|
value,
|
|
17
18
|
...props
|
|
18
19
|
}, reference) => {
|
|
19
|
-
if (!reference) reference = useRef(null);
|
|
20
20
|
// const [id] = useState(randomString(6, { allowSymbol: false }));
|
|
21
21
|
const unique = {
|
|
22
22
|
container: 'DGN-UI-Calendar',
|
|
@@ -49,6 +49,7 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
49
49
|
const tableRef = useRef(null);
|
|
50
50
|
const activeValue = useRef(null);
|
|
51
51
|
const navigatorValue = useRef(null);
|
|
52
|
+
useImperativeHandle(reference, () => ref.current);
|
|
52
53
|
const [, setActiveValue] = useState(Date.now());
|
|
53
54
|
const [, setNavigatorValue] = useState(Date.now());
|
|
54
55
|
const navigatorRefs = {
|
|
@@ -60,14 +61,6 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
60
61
|
};
|
|
61
62
|
const firstDayOfMax = new Date(new Date(max).setDate(1)).setHours(0, 0, 0, 0);
|
|
62
63
|
const firstDayOfMin = new Date(new Date(min).setDate(1)).setHours(0, 0, 0, 0);
|
|
63
|
-
useImperativeHandle(reference, () => {
|
|
64
|
-
const currentRef = ref.current || {};
|
|
65
|
-
currentRef.element = ref.current;
|
|
66
|
-
const _instance = {}; // methods
|
|
67
|
-
_instance.__proto__ = {}; // hidden methods
|
|
68
|
-
currentRef.instance = _instance;
|
|
69
|
-
return currentRef;
|
|
70
|
-
});
|
|
71
64
|
/**
|
|
72
65
|
* END REFERENCE
|
|
73
66
|
*/
|
|
@@ -515,7 +515,7 @@ const PickerCSS = {
|
|
|
515
515
|
${borderRadius4px};
|
|
516
516
|
${bgColor('system.white')};
|
|
517
517
|
${parseWidthHeight(width, 'max-content')};
|
|
518
|
-
${parseMinWidth(window.innerWidth <= 599 ? 280 :
|
|
518
|
+
${parseMinWidth(window.innerWidth <= 599 ? 280 : 314)};
|
|
519
519
|
${parseMaxWidth(400)};
|
|
520
520
|
${scale(0)};
|
|
521
521
|
${left(positionLeft)};
|
|
@@ -543,7 +543,6 @@ 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'),
|
|
547
546
|
pressESCToClose: true,
|
|
548
547
|
readOnly: false,
|
|
549
548
|
required: false,
|
|
@@ -332,10 +332,12 @@ const DateRangePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
332
332
|
const updateFromTo = (times = [new Date(), new Date()]) => {
|
|
333
333
|
const timeFr = new Date(times[0]);
|
|
334
334
|
const timeTo = new Date(times[1]);
|
|
335
|
-
const isSameMonth = timeFr.getMonth() === timeTo.getMonth();
|
|
336
335
|
const from = new Date(timeFr.getFullYear(), timeFr.getMonth());
|
|
337
|
-
|
|
338
|
-
const to =
|
|
336
|
+
const to = new Date(timeTo.getFullYear(), timeTo.getMonth());
|
|
337
|
+
// const to = new Date(
|
|
338
|
+
// timeTo.getFullYear(),
|
|
339
|
+
// +moment(timeTo).diff(timeFr, 'months') === 0 ? timeTo.getMonth() + 1 : timeTo.getMonth()
|
|
340
|
+
// );
|
|
339
341
|
updateValueFr(from);
|
|
340
342
|
updateValueTo(to);
|
|
341
343
|
};
|
|
@@ -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,
|
|
4
|
+
import { Avatar, ButtonIcon, Checkbox, Chip, CircularProgress, HelperText, InputBase, Label, TreeView, Typography } from "../..";
|
|
5
5
|
import Popover from "../../popover";
|
|
6
6
|
import { getGlobal } from "../../../global";
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
@@ -83,7 +83,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
83
83
|
searchExpr,
|
|
84
84
|
searchMode,
|
|
85
85
|
selectBox,
|
|
86
|
-
skip,
|
|
87
86
|
style,
|
|
88
87
|
subText,
|
|
89
88
|
total,
|
|
@@ -111,11 +110,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
111
110
|
// const timeout = useRef(null);
|
|
112
111
|
const loadMoreTimer = useRef(null);
|
|
113
112
|
const dataChosen = useRef([]);
|
|
114
|
-
const popupRef = useRef(null);
|
|
115
|
-
const filter = useRef({
|
|
116
|
-
skip: skip || 0,
|
|
117
|
-
limit: limit || 50
|
|
118
|
-
});
|
|
119
113
|
const [unique] = useState(randomString(6, {
|
|
120
114
|
allowNumber: false,
|
|
121
115
|
allowSymbol: false
|
|
@@ -125,14 +119,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
125
119
|
const [textValue, setTextValue] = useState('');
|
|
126
120
|
const [txtSearch, setTxtSearch] = useState('');
|
|
127
121
|
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
|
-
});
|
|
136
122
|
let valueTemp = valueProp || defaultValue || [];
|
|
137
123
|
|
|
138
124
|
// only mode multi
|
|
@@ -145,7 +131,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
145
131
|
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, disabled, readOnly, multilineSelectedItem);
|
|
146
132
|
const _IconCSS = IconCSS(viewType);
|
|
147
133
|
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, disabled, placeholder, _DropdownInputCSS.name);
|
|
148
|
-
const _DropdownListCSS = DropdownListCSS(
|
|
134
|
+
const _DropdownListCSS = DropdownListCSS(loading);
|
|
149
135
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
150
136
|
const _DropdownRootCSS = DropdownRootCSS(_DropdownFormCSS.name, _DropdownInputCSS.name);
|
|
151
137
|
|
|
@@ -162,7 +148,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
162
148
|
!!blur && inputRef.current.blur();
|
|
163
149
|
};
|
|
164
150
|
const onClickInput = e => {
|
|
165
|
-
if (disabled || readOnly ||
|
|
151
|
+
if (disabled || readOnly || loading) return;
|
|
166
152
|
if (!dropdownListRef.current) {
|
|
167
153
|
if (!multiple || !Array.from(inputRef.current.querySelectorAll('.DGN-UI-Chip')).some(item => item.contains(e === null || e === void 0 ? void 0 : e.target))) {
|
|
168
154
|
setOpenState(true);
|
|
@@ -195,7 +181,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
195
181
|
className: 'DGN-Dropdown-List',
|
|
196
182
|
onKeyDown: moveOnItem,
|
|
197
183
|
tabIndex: -1
|
|
198
|
-
},
|
|
184
|
+
}, dataSource !== null && dataSource !== void 0 && dataSource.length ? children : EmptyDataText) : itemMode === 'normal' ? mapDropdown() : mapTreeView();
|
|
199
185
|
// const { innerHeight } = window;
|
|
200
186
|
// const { top, left, height, width } = formRef.current.getBoundingClientRect();
|
|
201
187
|
|
|
@@ -234,13 +220,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
234
220
|
marginBottom: 1
|
|
235
221
|
},
|
|
236
222
|
onKeyDown: pressESCHandler,
|
|
237
|
-
readOnly: loadingState,
|
|
238
223
|
autoFocus: true
|
|
239
224
|
})) : null, multiple && maximumSelectionLength ? jsx(Typography, {
|
|
240
225
|
css: pd([2, 4])
|
|
241
226
|
}, getGlobal('selected'), " ", (valueMulti === null || valueMulti === void 0 ? void 0 : valueMulti.length) || 0, "/", maximumSelectionLength) : null, jsx("div", {
|
|
242
227
|
className: 'DGN-Dropdown-Box'
|
|
243
|
-
}, dropdown),
|
|
228
|
+
}, dropdown), loading ? jsx("div", {
|
|
244
229
|
css: LoadingProgressCSS,
|
|
245
230
|
className: 'DGN-Dropdown-Loading-Progress'
|
|
246
231
|
}, jsx(CircularProgress, {
|
|
@@ -254,7 +239,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
254
239
|
window.addEventListener('resize', customizeWidthDropdown);
|
|
255
240
|
// document.addEventListener('wheel', onWheelHandler);
|
|
256
241
|
// document.addEventListener('mousedown', onClickOutsideOfInput);
|
|
257
|
-
if (onLoadMore &&
|
|
242
|
+
if (onLoadMore && dataSource.length < total) {
|
|
258
243
|
dropdownListRef.current && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
259
244
|
}
|
|
260
245
|
}, 10);
|
|
@@ -370,7 +355,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
370
355
|
const mapDropdown = () => {
|
|
371
356
|
var _dataSourceUsable, _currentObjectDefault;
|
|
372
357
|
const items = [];
|
|
373
|
-
let dataSourceUsable = [...
|
|
358
|
+
let dataSourceUsable = [...dataSource];
|
|
374
359
|
|
|
375
360
|
// search dataSource dựa trên txtSearch
|
|
376
361
|
dataSourceUsable = (_dataSourceUsable = dataSourceUsable) === null || _dataSourceUsable === void 0 ? void 0 : _dataSourceUsable.filter(i => {
|
|
@@ -492,8 +477,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
492
477
|
className: 'DGN-Dropdown-List',
|
|
493
478
|
onKeyDown: moveOnItem,
|
|
494
479
|
tabIndex: -1
|
|
495
|
-
},
|
|
496
|
-
dataSource:
|
|
480
|
+
}, dataSource !== null && dataSource !== void 0 && dataSource.length ? jsx(TreeView, {
|
|
481
|
+
dataSource: dataSource,
|
|
497
482
|
displayExpr: displayExpr,
|
|
498
483
|
valueExpr: valueExpr,
|
|
499
484
|
multiple: multiple,
|
|
@@ -515,7 +500,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
515
500
|
// remove item cũ và append child item mới khi load more
|
|
516
501
|
const loadMoreItemsDropdown = (i = 0, pattern) => {
|
|
517
502
|
var _currentObjectDefault2, _displayExpr2;
|
|
518
|
-
const dataSourceUsable = [...
|
|
503
|
+
const dataSourceUsable = [...dataSource];
|
|
519
504
|
// Nếu có load more thì đẩy đội tượng mặc định lên đầu
|
|
520
505
|
let notExistItem = 0;
|
|
521
506
|
if (onLoadMore && (_currentObjectDefault2 = currentObjectDefault[unique]) !== null && _currentObjectDefault2 !== void 0 && _currentObjectDefault2.length) {
|
|
@@ -663,65 +648,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
663
648
|
// : updatePosition(formRef.current, dropdownRef.current, closeDropdown);
|
|
664
649
|
// };
|
|
665
650
|
|
|
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
|
-
};
|
|
725
651
|
const onLoadMoreHandler = e => {
|
|
726
652
|
if (loadMoreTimer.current) {
|
|
727
653
|
clearTimeout(loadMoreTimer.current);
|
|
@@ -736,16 +662,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
736
662
|
var _dropdownListRef$curr, _currentObjectDefault3;
|
|
737
663
|
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);
|
|
738
664
|
dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
739
|
-
|
|
740
|
-
filter.current.skip = length;
|
|
741
|
-
filter.current.limit = limit;
|
|
742
|
-
handleActionLoadData();
|
|
743
|
-
} else !!onLoadMore && onLoadMore({
|
|
665
|
+
!!onLoadMore && onLoadMore({
|
|
744
666
|
skip: length,
|
|
745
667
|
limit: limit
|
|
746
668
|
});
|
|
747
669
|
}
|
|
748
|
-
}
|
|
670
|
+
});
|
|
749
671
|
};
|
|
750
672
|
const onPreventKeyDownHandler = e => {
|
|
751
673
|
e.preventDefault();
|
|
@@ -778,11 +700,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
778
700
|
// }
|
|
779
701
|
// return;
|
|
780
702
|
}
|
|
781
|
-
|
|
782
|
-
if (action !== null && action !== void 0 && action.loadData && !!onLoadMore) {
|
|
783
|
-
filter.current.strSearch = e.target.value;
|
|
784
|
-
handleActionLoadData(true);
|
|
785
|
-
}
|
|
786
703
|
// const value = e.target.value || e.target.textContent;
|
|
787
704
|
// if (
|
|
788
705
|
// typeof renderSelectedItem === 'function' &&
|
|
@@ -804,7 +721,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
804
721
|
if (valueProp === undefined) {
|
|
805
722
|
setValueMulti(value);
|
|
806
723
|
setValueIntoInput(value);
|
|
807
|
-
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !
|
|
724
|
+
setShowClear(clearAble && checkHasValue(value) && !disabled && !readOnly && !loading);
|
|
808
725
|
}
|
|
809
726
|
!!onChange && onChange({
|
|
810
727
|
value
|
|
@@ -923,7 +840,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
923
840
|
});
|
|
924
841
|
};
|
|
925
842
|
const onClear = e => {
|
|
926
|
-
if (disabled || readOnly ||
|
|
843
|
+
if (disabled || readOnly || loading || !clearAble) return;
|
|
927
844
|
currentValue[unique] = multiple ? [] : '';
|
|
928
845
|
if (multiple) {
|
|
929
846
|
setValueMulti([]);
|
|
@@ -969,7 +886,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
969
886
|
}
|
|
970
887
|
return;
|
|
971
888
|
}
|
|
972
|
-
const length =
|
|
889
|
+
const length = dataSource.length;
|
|
973
890
|
const displayKey = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr;
|
|
974
891
|
if (displayKey && Array.isArray(displayKey)) {
|
|
975
892
|
displayExpr = displayExpr.join(' - ');
|
|
@@ -986,8 +903,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
986
903
|
valueArr.forEach(v => {
|
|
987
904
|
var _currentObjectDefault4;
|
|
988
905
|
for (let i = 0; i < length; i++) {
|
|
989
|
-
if (typeof
|
|
990
|
-
setMultipleValueHandler(
|
|
906
|
+
if (typeof dataSource[i] === 'object' && dataSource[i][valueExpr] === v || dataSource[i] === v) {
|
|
907
|
+
setMultipleValueHandler(dataSource[i], v, keyArr, i);
|
|
991
908
|
return;
|
|
992
909
|
}
|
|
993
910
|
}
|
|
@@ -1002,8 +919,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1002
919
|
var _currentObjectDefault5;
|
|
1003
920
|
currentValue[unique] = source;
|
|
1004
921
|
for (let i = 0; i < length; i++) {
|
|
1005
|
-
if (
|
|
1006
|
-
setSingleValueHandler(
|
|
922
|
+
if (dataSource[i][valueExpr] === source || dataSource[i] === source) {
|
|
923
|
+
setSingleValueHandler(dataSource[i], keyArr);
|
|
1007
924
|
return;
|
|
1008
925
|
}
|
|
1009
926
|
}
|
|
@@ -1110,17 +1027,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1110
1027
|
return currentRef;
|
|
1111
1028
|
});
|
|
1112
1029
|
useEffect(() => {
|
|
1113
|
-
|
|
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]);
|
|
1030
|
+
setShowClear(clearAble && checkHasValue(valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue) && !disabled && !readOnly && !loading);
|
|
1031
|
+
}, [clearAble, valueProp, defaultValue, disabled, readOnly, loading]);
|
|
1124
1032
|
useEffect(() => {
|
|
1125
1033
|
if (valueObjectDefault) {
|
|
1126
1034
|
if (Array.isArray(valueObjectDefault)) {
|
|
@@ -1139,9 +1047,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1139
1047
|
allValue[unique] = [];
|
|
1140
1048
|
if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
|
|
1141
1049
|
setValueIntoInput(defaultValue);
|
|
1142
|
-
setShowClear(clearAble && checkHasValue(defaultValue) && !disabled && !readOnly && !
|
|
1050
|
+
setShowClear(clearAble && checkHasValue(defaultValue) && !disabled && !readOnly && !loading);
|
|
1143
1051
|
}
|
|
1144
|
-
if (action !== null && action !== void 0 && action.loadData) handleActionLoadData();
|
|
1145
1052
|
return () => {
|
|
1146
1053
|
allValue[unique] = null;
|
|
1147
1054
|
closeDropdown();
|
|
@@ -1180,12 +1087,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1180
1087
|
}
|
|
1181
1088
|
}, [valueProp]);
|
|
1182
1089
|
useEffect(() => {
|
|
1183
|
-
if (
|
|
1184
|
-
// valueProp !== undefined &&
|
|
1185
|
-
!dropdownListRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique])) {
|
|
1090
|
+
if (valueProp !== undefined && (!dropdownListRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique]))) {
|
|
1186
1091
|
setValueIntoInput(valueProp);
|
|
1187
1092
|
}
|
|
1188
|
-
}, [valueProp,
|
|
1093
|
+
}, [valueProp, dataSource]);
|
|
1189
1094
|
useEffect(() => {
|
|
1190
1095
|
inputRef.current.readOnly = readOnly || inputProps.readOnly;
|
|
1191
1096
|
if (!readOnly && !disabled) {
|
|
@@ -1228,9 +1133,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1228
1133
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1229
1134
|
}
|
|
1230
1135
|
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;
|
|
1231
|
-
if (length <
|
|
1136
|
+
if (length < dataSource.length + ((_currentObjectDefault6 = currentObjectDefault[unique]) === null || _currentObjectDefault6 === void 0 ? void 0 : _currentObjectDefault6.length) && !isSearch[unique]) {
|
|
1232
1137
|
loadMoreItemsDropdown(length);
|
|
1233
|
-
!!onLoadMore &&
|
|
1138
|
+
!!onLoadMore && dataSource.length < total && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
1234
1139
|
} else {
|
|
1235
1140
|
isSearch[unique] = false;
|
|
1236
1141
|
}
|
|
@@ -1246,7 +1151,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1246
1151
|
}
|
|
1247
1152
|
!!dropdownListRef.current && dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
1248
1153
|
};
|
|
1249
|
-
}, [
|
|
1154
|
+
}, [dataSource]);
|
|
1250
1155
|
useLayoutEffect(() => {
|
|
1251
1156
|
if (ref.current) {
|
|
1252
1157
|
const {
|
|
@@ -1268,7 +1173,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1268
1173
|
...labelProps
|
|
1269
1174
|
}, label) : null, [label, required, disabled, labelProps]);
|
|
1270
1175
|
const getData = () => {
|
|
1271
|
-
let dataFilter = JSON.parse(JSON.stringify(
|
|
1176
|
+
let dataFilter = JSON.parse(JSON.stringify(dataSource));
|
|
1272
1177
|
if (Array.isArray(valueObjectDefault)) {
|
|
1273
1178
|
dataFilter = [...dataFilter, ...dataChosen.current, ...valueObjectDefault];
|
|
1274
1179
|
} else if (typeof valueObjectDefault === 'object') {
|
|
@@ -1364,14 +1269,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1364
1269
|
ref: iconRef,
|
|
1365
1270
|
css: _IconCSS,
|
|
1366
1271
|
className: 'DGN-UI-Dropdown-Icon'
|
|
1367
|
-
},
|
|
1272
|
+
}, loading ? jsx(CircularProgress, {
|
|
1368
1273
|
size: 24
|
|
1369
1274
|
}) : null, showClear ? jsx(ButtonIcon, {
|
|
1370
1275
|
css: mgr([1]),
|
|
1371
1276
|
viewType: 'ghost',
|
|
1372
1277
|
name: 'Close',
|
|
1373
1278
|
onClick: onClear
|
|
1374
|
-
}) : null, !
|
|
1279
|
+
}) : null, !loading ? jsx(ButtonIcon, {
|
|
1375
1280
|
key: openState,
|
|
1376
1281
|
css: animation,
|
|
1377
1282
|
viewType: 'ghost',
|
|
@@ -1379,7 +1284,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1379
1284
|
onClick: setShowDropdown,
|
|
1380
1285
|
disabled: disabled || readOnly
|
|
1381
1286
|
}) : null));
|
|
1382
|
-
}, [openState, showClear, textValue, valueMulti,
|
|
1287
|
+
}, [openState, showClear, textValue, valueMulti, clearAble, dataSource, disabled, displayExpr, inputProps, inputStyle, loading, multilineSelectedItem, multiple, onChange, placeholder, readOnly, renderSelectedItem, valueExpr, valueObjectDefault, viewType]);
|
|
1383
1288
|
const ErrorView = useMemo(() => {
|
|
1384
1289
|
return error ? jsx(HelperText, {
|
|
1385
1290
|
...helperTextProps,
|
|
@@ -1396,19 +1301,15 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1396
1301
|
onClose: closeDropdown
|
|
1397
1302
|
}, showDropdown());
|
|
1398
1303
|
// return openState ? createPortal(showDropdown(), document.body) : null;
|
|
1399
|
-
}, [openState, popoverWidth, valueMulti,
|
|
1304
|
+
}, [openState, popoverWidth, valueMulti, dataSource, loading, maximumSelectionLength, multilineSelectedItem, multiple, selectBox, txtSearch]);
|
|
1400
1305
|
/* End component */
|
|
1401
1306
|
|
|
1402
1307
|
return jsx(Fragment, null, jsx("div", {
|
|
1403
1308
|
ref: ref,
|
|
1404
1309
|
css: _DropdownRootCSS,
|
|
1405
1310
|
style: style,
|
|
1406
|
-
className: classNames('DGN-UI-Dropdown', className, error && 'error',
|
|
1407
|
-
}, LabelView, InputView, ErrorView), DropdownView
|
|
1408
|
-
ref: popupRef,
|
|
1409
|
-
type: 'danger',
|
|
1410
|
-
...popupDataState
|
|
1411
|
-
}));
|
|
1311
|
+
className: classNames('DGN-UI-Dropdown', className, error && 'error', loading && 'dgn-dropdown-loading', disabled ? 'disabled' : readOnly && 'readOnly')
|
|
1312
|
+
}, LabelView, InputView, ErrorView), DropdownView);
|
|
1412
1313
|
}));
|
|
1413
1314
|
|
|
1414
1315
|
/* Start styled */
|
|
@@ -1732,9 +1633,6 @@ Dropdown.defaultProps = {
|
|
|
1732
1633
|
viewType: 'underlined'
|
|
1733
1634
|
};
|
|
1734
1635
|
Dropdown.propTypes = {
|
|
1735
|
-
action: PropTypes.shape({
|
|
1736
|
-
loadData: PropTypes.func
|
|
1737
|
-
}),
|
|
1738
1636
|
/** If `true`, display input box search. */
|
|
1739
1637
|
allowSearch: PropTypes.bool,
|
|
1740
1638
|
/** The contents in Dropdown box (Exp: TreeView). */
|
|
@@ -1810,7 +1708,7 @@ Dropdown.propTypes = {
|
|
|
1810
1708
|
/** Callback fired when key down input */
|
|
1811
1709
|
onKeyDown: PropTypes.func,
|
|
1812
1710
|
/** Callback fired when scroll near the end. */
|
|
1813
|
-
onLoadMore: PropTypes.
|
|
1711
|
+
onLoadMore: PropTypes.func,
|
|
1814
1712
|
/** The short hint displayed in the input before the user select a value. */
|
|
1815
1713
|
placeholder: PropTypes.string,
|
|
1816
1714
|
/** If `true`, the component is read-only. */
|