diginet-core-ui 1.3.51 → 1.3.52-beta.3
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/index.js +1 -1
- package/components/accordion/summary.js +17 -18
- package/components/alert/index.js +1 -1
- package/components/avatar/index.js +46 -32
- package/components/chip/index.js +1 -2
- package/components/form-control/checkbox/index.js +1 -1
- package/components/form-control/dropdown/index.js +61 -54
- package/components/form-control/form-group/index.js +1 -1
- package/components/form-control/input-base/index.js +1 -0
- package/components/grid/Col.js +30 -1
- package/components/grid/Row.js +31 -4
- package/components/modal/modal.js +4 -4
- package/components/paging/page-info.js +87 -27
- package/components/popover/index.js +45 -17
- package/components/typography/index.js +75 -68
- package/package.json +54 -31
- package/readme.md +4 -0
- package/utils/useInput.js +3 -1
|
@@ -82,7 +82,7 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
82
82
|
display: 'none'
|
|
83
83
|
}
|
|
84
84
|
})));
|
|
85
|
-
}, [id, disabled, className, boxShadow, onClick, children, expanded, onExpand, onCollapse, expandState]);
|
|
85
|
+
}, [id, disabled, className, style, boxShadow, onClick, children, expanded, onExpand, onCollapse, expandState]);
|
|
86
86
|
}));
|
|
87
87
|
const AccordionRootCSS = css`
|
|
88
88
|
${displayBlock};
|
|
@@ -35,26 +35,25 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
35
35
|
const _SummaryRootCSS = SummaryRootCSS(background);
|
|
36
36
|
|
|
37
37
|
const _onClick = e => {
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
if (disabled) return;
|
|
39
|
+
const target = e.target;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if (onClickAccordion) {
|
|
42
|
+
onClickAccordion();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (onClick && (!expandIconRef.current || !expandIconRef.current.contains(target))) {
|
|
47
|
+
onClick(e);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
51
|
+
if (expandState) {
|
|
52
|
+
if (expanded === undefined) setExpandState(false);
|
|
53
|
+
!!onCollapse && onCollapse(e);
|
|
54
|
+
} else if (!expandState) {
|
|
55
|
+
if (expanded === undefined) setExpandState(true);
|
|
56
|
+
!!onExpand && onExpand(e);
|
|
58
57
|
}
|
|
59
58
|
};
|
|
60
59
|
|
|
@@ -137,7 +136,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
137
136
|
}) : jsx("span", {
|
|
138
137
|
className: 'Accordion-Collapse-Icon effect'
|
|
139
138
|
}, collapseIcon)))));
|
|
140
|
-
}, [id, expandIcon, expandIconAt, className, background, children, collapseIcon, expandIconProps, expandState]);
|
|
139
|
+
}, [id, expandIcon, expandIconAt, className, background, children, collapseIcon, expandIconProps, style, expandState, disabled]);
|
|
141
140
|
}));
|
|
142
141
|
AccordionSummary.defaultProps = {
|
|
143
142
|
expandIconAt: 'start',
|
|
@@ -10,8 +10,8 @@ import ButtonIcon from '../button/icon';
|
|
|
10
10
|
import Icon from '../../icons';
|
|
11
11
|
import { hexToRGBA } from '../../styles/color-helper';
|
|
12
12
|
import { typography } from '../../styles/typography';
|
|
13
|
-
import { alignCenter, border, borderBox, borderRadius4px, breakWord, displayBlock, flexRow, justifyStart, positionRelative, userSelectNone } from '../../styles/general';
|
|
14
13
|
import { useTheme } from '../../theme';
|
|
14
|
+
import { alignCenter, border, borderBox, borderRadius4px, breakWord, displayBlock, flexRow, justifyStart, positionRelative, userSelectNone } from '../../styles/general';
|
|
15
15
|
const {
|
|
16
16
|
heading3,
|
|
17
17
|
heading4,
|
|
@@ -12,18 +12,22 @@ import { getGlobal } from '../../global';
|
|
|
12
12
|
import AvatarDefault from '../../assets/avatar/default.svg';
|
|
13
13
|
import { alignCenter, borderNone, displayBlock, displayNone, flexCol, inlineFlex, overflowHidden, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative, userSelectNone } from '../../styles/general';
|
|
14
14
|
import isMobile from '../../utils/isMobile';
|
|
15
|
-
import
|
|
15
|
+
import theme from '../../theme/settings';
|
|
16
16
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
colors: {
|
|
18
|
+
system: {
|
|
19
|
+
white
|
|
20
|
+
},
|
|
21
|
+
fill: {
|
|
22
|
+
tooltip: fillTooltip
|
|
23
|
+
},
|
|
24
|
+
text: {
|
|
25
|
+
tooltip: textTooltip
|
|
26
|
+
}
|
|
22
27
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = colors;
|
|
28
|
+
spacing,
|
|
29
|
+
zIndex: zIndexCORE
|
|
30
|
+
} = theme;
|
|
27
31
|
const existed = {},
|
|
28
32
|
urlAvatar = {},
|
|
29
33
|
popupHandler = {};
|
|
@@ -34,6 +38,18 @@ const blurKeyframe = keyframes`
|
|
|
34
38
|
75% { -webkit-filter: blur(1px);}
|
|
35
39
|
100% { -webkit-filter: blur(0px);}
|
|
36
40
|
`;
|
|
41
|
+
|
|
42
|
+
const checkFileType = (type, matchType) => {
|
|
43
|
+
if (typeof matchType === 'object' && matchType instanceof RegExp) {
|
|
44
|
+
return matchType.test(type);
|
|
45
|
+
} else if (typeof matchType === 'object' && Array.isArray(matchType)) {
|
|
46
|
+
const pattern = new RegExp('^image/(' + matchType.join('|') + ')', 'i');
|
|
47
|
+
return pattern.test(type);
|
|
48
|
+
} else {
|
|
49
|
+
return new RegExp(matchType).test(type);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
37
53
|
const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
38
54
|
src,
|
|
39
55
|
defaultSrc,
|
|
@@ -56,7 +72,9 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
56
72
|
readOnly,
|
|
57
73
|
disabled,
|
|
58
74
|
lazyLoading,
|
|
59
|
-
id
|
|
75
|
+
id,
|
|
76
|
+
allowEdit,
|
|
77
|
+
onClick
|
|
60
78
|
}, reference) => {
|
|
61
79
|
if (!defaultSrc) defaultSrc = AvatarDefault;
|
|
62
80
|
const ref = useRef(null);
|
|
@@ -94,23 +112,12 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
94
112
|
}
|
|
95
113
|
};
|
|
96
114
|
|
|
97
|
-
const checkFileType = type => {
|
|
98
|
-
if (typeof matchType === 'object' && matchType instanceof RegExp) {
|
|
99
|
-
return matchType.test(type);
|
|
100
|
-
} else if (typeof matchType === 'object' && Array.isArray(matchType)) {
|
|
101
|
-
const pattern = new RegExp('^image/(' + matchType.join('|') + ')', 'i');
|
|
102
|
-
return pattern.test(type);
|
|
103
|
-
} else {
|
|
104
|
-
return new RegExp(matchType).test(type);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
115
|
const onChangeAvatar = input => {
|
|
109
116
|
const [file] = input.target.files;
|
|
110
117
|
if (!file) return;
|
|
111
118
|
const reader = new FileReader();
|
|
112
119
|
|
|
113
|
-
if (!checkFileType(file.type)) {
|
|
120
|
+
if (!checkFileType(file.type, matchType)) {
|
|
114
121
|
input.target.value = '';
|
|
115
122
|
popupHandler[unique].show(wrongTypeError);
|
|
116
123
|
return;
|
|
@@ -194,12 +201,15 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
194
201
|
if (hoverAble) setViewMoreInfo(false);
|
|
195
202
|
};
|
|
196
203
|
|
|
197
|
-
const _onClick =
|
|
204
|
+
const _onClick = event => {
|
|
205
|
+
onClick && event.stopPropagation();
|
|
198
206
|
if (disabled) return;
|
|
199
207
|
|
|
200
208
|
if (readOnly) {
|
|
201
209
|
if (_isMobile) showMoreInfo();
|
|
202
|
-
} else
|
|
210
|
+
} else {
|
|
211
|
+
allowEdit ? triggerInput() : onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
212
|
+
}
|
|
203
213
|
};
|
|
204
214
|
|
|
205
215
|
const _onMouseEnter = () => {
|
|
@@ -264,7 +274,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
264
274
|
onMouseLeave: _onMouseLeave,
|
|
265
275
|
tabIndex: "-1",
|
|
266
276
|
onBlur: closeMoreInfo
|
|
267
|
-
}, renderImage())), !readOnly && !disabled && jsx("span", {
|
|
277
|
+
}, renderImage())), allowEdit && !readOnly && !disabled && jsx("span", {
|
|
268
278
|
css: _ActionIconCSS
|
|
269
279
|
}, jsx(ButtonIcon, {
|
|
270
280
|
viewType: 'ghost',
|
|
@@ -315,7 +325,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
315
325
|
icon: 'danger',
|
|
316
326
|
fullScreen: true
|
|
317
327
|
}));
|
|
318
|
-
}, [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble, outlined, actionIconWidth, actionIconHeight, lazyLoading, defaultSrc, direction, data, maxSizeError, srcState, isInView, onLoaded, viewAvatar, viewMoreInfo]);
|
|
328
|
+
}, [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble, outlined, actionIconWidth, actionIconHeight, lazyLoading, defaultSrc, direction, data, maxSizeError, allowEdit, srcState, isInView, onLoaded, viewAvatar, viewMoreInfo]);
|
|
319
329
|
}));
|
|
320
330
|
|
|
321
331
|
const ActionIconCSS = actionIconWidth => css`
|
|
@@ -325,7 +335,7 @@ const ActionIconCSS = actionIconWidth => css`
|
|
|
325
335
|
min-width: ${actionIconWidth}px;
|
|
326
336
|
transition: opacity 0.5s;
|
|
327
337
|
opacity: 0;
|
|
328
|
-
z-index:
|
|
338
|
+
z-index: ${zIndexCORE(2)};
|
|
329
339
|
`;
|
|
330
340
|
|
|
331
341
|
const AvatarPreviewCSS = readOnly => css`
|
|
@@ -380,12 +390,13 @@ const AvatarRootCSS = (width, height, outlined) => css`
|
|
|
380
390
|
const MoreInfoCSS = css`
|
|
381
391
|
${displayBlock};
|
|
382
392
|
${positionRelative};
|
|
383
|
-
padding:
|
|
393
|
+
padding: ${spacing([2])};
|
|
384
394
|
`;
|
|
385
395
|
const blurAnimationCSS = css`
|
|
386
396
|
animation: ${blurKeyframe} 1s ease;
|
|
387
397
|
`;
|
|
388
398
|
Avatar.defaultProps = {
|
|
399
|
+
allowEdit: false,
|
|
389
400
|
disabled: false,
|
|
390
401
|
readOnly: false,
|
|
391
402
|
clearAble: true,
|
|
@@ -404,6 +415,9 @@ Avatar.defaultProps = {
|
|
|
404
415
|
lazyLoading: false
|
|
405
416
|
};
|
|
406
417
|
Avatar.propTypes = {
|
|
418
|
+
/** If `true`, allow to edit avatar. */
|
|
419
|
+
allowEdit: PropTypes.bool,
|
|
420
|
+
|
|
407
421
|
/** prevent all events, only view */
|
|
408
422
|
disabled: PropTypes.bool,
|
|
409
423
|
|
|
@@ -470,12 +484,12 @@ Avatar.propTypes = {
|
|
|
470
484
|
/** will run after change avatar */
|
|
471
485
|
onChange: PropTypes.func,
|
|
472
486
|
|
|
487
|
+
/** Callback fired when the component is clicked. */
|
|
488
|
+
onClick: PropTypes.func,
|
|
489
|
+
|
|
473
490
|
/** lazy loading */
|
|
474
491
|
lazyLoading: PropTypes.bool,
|
|
475
492
|
|
|
476
|
-
/** any props else */
|
|
477
|
-
props: PropTypes.any,
|
|
478
|
-
|
|
479
493
|
/**
|
|
480
494
|
* ref methods
|
|
481
495
|
*
|
package/components/chip/index.js
CHANGED
|
@@ -114,8 +114,7 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
114
114
|
className: size
|
|
115
115
|
}, jsx(Typography, {
|
|
116
116
|
type: size === 'small' ? 'p2' : 'p1',
|
|
117
|
-
color: 'inherit'
|
|
118
|
-
lineClamp: 1
|
|
117
|
+
color: 'inherit'
|
|
119
118
|
}, renderLabel()));
|
|
120
119
|
}, [label, size, startIcon, endIcon, clearAble]);
|
|
121
120
|
const endIconView = useMemo(() => {
|
|
@@ -70,7 +70,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
70
70
|
total,
|
|
71
71
|
placeholder,
|
|
72
72
|
error,
|
|
73
|
-
keyExpr,
|
|
74
73
|
displayExpr,
|
|
75
74
|
subText,
|
|
76
75
|
valueExpr,
|
|
@@ -156,10 +155,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
156
155
|
const onClickInput = e => {
|
|
157
156
|
if (!boxRef.current) {
|
|
158
157
|
if (!multiple || !Array.from(inputRef.current.querySelectorAll('.DGN-UI-Chip')).some(item => item.contains(e.target))) {
|
|
159
|
-
if ((renderSelectedItem || iconExpr && iconExpr !== 'none') && !multiple) {
|
|
158
|
+
if ((typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none') && !multiple) {
|
|
159
|
+
var _inputRef$current$chi;
|
|
160
|
+
|
|
160
161
|
inputRef.current.innerHTML = inputRef.current.textContent.trim();
|
|
161
162
|
inputRef.current.contentEditable = 'plaintext-only';
|
|
162
|
-
const caret = inputRef.current.childNodes.length ? 1 : 0;
|
|
163
|
+
const caret = (_inputRef$current$chi = inputRef.current.childNodes) !== null && _inputRef$current$chi !== void 0 && _inputRef$current$chi.length ? 1 : 0;
|
|
163
164
|
const range = document.createRange();
|
|
164
165
|
range.setStart(inputRef.current, caret);
|
|
165
166
|
range.setEnd(inputRef.current, caret);
|
|
@@ -281,7 +282,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
281
282
|
window.addEventListener('resize', customizeWidthDropdown);
|
|
282
283
|
document.addEventListener('wheel', onWheelHandler);
|
|
283
284
|
document.addEventListener('mousedown', onClickOutsideOfInput);
|
|
284
|
-
document.addEventListener('keydown', preventScroll);
|
|
285
285
|
boxRef.current && boxRef.current.addEventListener('keydown', moveOnItem);
|
|
286
286
|
|
|
287
287
|
if (onLoadMore && dataSource.length < total) {
|
|
@@ -306,15 +306,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
306
306
|
}
|
|
307
307
|
};
|
|
308
308
|
|
|
309
|
-
const preventScroll = e => {
|
|
310
|
-
if (/Arrow(Up|Down)/.test(e.key)) {
|
|
311
|
-
e.preventDefault();
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return true;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
309
|
const pressESCHandler = event => {
|
|
319
310
|
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
320
311
|
closeDropdown();
|
|
@@ -339,11 +330,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
339
330
|
};
|
|
340
331
|
|
|
341
332
|
const closeDropdown = () => {
|
|
342
|
-
const node = document.querySelector(`.DGN-Dropdown-${unique}`);
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
inputRef.current.contentEditable = true;
|
|
346
|
-
}
|
|
333
|
+
const node = document.querySelector(`.DGN-Dropdown-${unique}`); // if ((renderSelectedItem || (iconExpr && iconExpr !== 'none')) && !multiple && inputRef.current && !disabled) {
|
|
334
|
+
// inputRef.current.contentEditable = true;
|
|
335
|
+
// }
|
|
347
336
|
|
|
348
337
|
if (node) {
|
|
349
338
|
node.style.pointerEvents = `none`;
|
|
@@ -359,7 +348,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
359
348
|
document.removeEventListener('mousedown', onClickOutsideOfInput);
|
|
360
349
|
window.removeEventListener('resize', customizeWidthDropdown);
|
|
361
350
|
document.removeEventListener('wheel', onWheelHandler);
|
|
362
|
-
document.removeEventListener('keydown', preventScroll);
|
|
363
351
|
|
|
364
352
|
if (onLoadMore && boxRef.current) {
|
|
365
353
|
boxRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
@@ -400,12 +388,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
400
388
|
};
|
|
401
389
|
|
|
402
390
|
const mapDropdown = (pattern, keyArr) => {
|
|
391
|
+
var _currentObjectDefault;
|
|
392
|
+
|
|
403
393
|
const items = [];
|
|
404
394
|
const dataSourceUsable = [...dataSource];
|
|
405
395
|
|
|
406
396
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
407
397
|
|
|
408
|
-
if (currentObjectDefault[unique] && currentObjectDefault[unique].length) {
|
|
398
|
+
if (currentObjectDefault[unique] && (_currentObjectDefault = currentObjectDefault[unique]) !== null && _currentObjectDefault !== void 0 && _currentObjectDefault.length) {
|
|
409
399
|
const length = currentObjectDefault[unique].length;
|
|
410
400
|
let existItemQuantity = 0;
|
|
411
401
|
|
|
@@ -503,7 +493,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
503
493
|
}, displayText)));
|
|
504
494
|
}
|
|
505
495
|
|
|
506
|
-
if (items.length === limit) {
|
|
496
|
+
if ((items === null || items === void 0 ? void 0 : items.length) === limit) {
|
|
507
497
|
timerRef.current = setTimeout(() => {
|
|
508
498
|
loadMoreItemsDropdown(index + 1, pattern);
|
|
509
499
|
}, 1000);
|
|
@@ -514,7 +504,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
514
504
|
return jsx("div", {
|
|
515
505
|
css: DropdownBoxCSS,
|
|
516
506
|
ref: boxRef
|
|
517
|
-
}, items.length ? items : jsx("div", {
|
|
507
|
+
}, items !== null && items !== void 0 && items.length ? items : jsx("div", {
|
|
518
508
|
css: _DropdownItemCSS,
|
|
519
509
|
className: 'no-data'
|
|
520
510
|
}, ' ', noDataText, ' '));
|
|
@@ -547,13 +537,13 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
547
537
|
};
|
|
548
538
|
|
|
549
539
|
const loadMoreItemsDropdown = (i = 0, pattern) => {
|
|
550
|
-
var _displayExpr3;
|
|
540
|
+
var _currentObjectDefault2, _displayExpr3;
|
|
551
541
|
|
|
552
542
|
const dataSourceUsable = [...dataSource]; // Nếu có load more thì đẩy đội tượng mặc định lên đầu
|
|
553
543
|
|
|
554
544
|
let notExistItem = 0;
|
|
555
545
|
|
|
556
|
-
if (onLoadMore && currentObjectDefault[unique].length) {
|
|
546
|
+
if (onLoadMore && (_currentObjectDefault2 = currentObjectDefault[unique]) !== null && _currentObjectDefault2 !== void 0 && _currentObjectDefault2.length) {
|
|
557
547
|
const length = currentObjectDefault[unique].length;
|
|
558
548
|
|
|
559
549
|
for (let index = length - 1; index >= 0; index--) {
|
|
@@ -744,7 +734,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
744
734
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
745
735
|
|
|
746
736
|
if (scrollHeight === Math.ceil(scrollTop) + offsetHeight && boxRef.current) {
|
|
747
|
-
|
|
737
|
+
var _boxRef$current$query;
|
|
738
|
+
|
|
739
|
+
const length = (_boxRef$current$query = boxRef.current.querySelectorAll(`.css-${_DropdownItemCSS.name}`)) === null || _boxRef$current$query === void 0 ? void 0 : _boxRef$current$query.length;
|
|
748
740
|
boxRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
749
741
|
!!onLoadMore && onLoadMore({
|
|
750
742
|
skip: length,
|
|
@@ -784,7 +776,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
784
776
|
|
|
785
777
|
const value = e.target.value || e.target.textContent;
|
|
786
778
|
|
|
787
|
-
if (renderSelectedItem && e.target.childNodes && Array.from(e.target.childNodes).some(node => node.toString() !== '[object Text]')) {
|
|
779
|
+
if (typeof renderSelectedItem === 'function' && e.target.childNodes && Array.from(e.target.childNodes).some(node => node.toString() !== '[object Text]')) {
|
|
788
780
|
const cursor = document.getSelection().anchorOffset;
|
|
789
781
|
e.target.innerHTML = value;
|
|
790
782
|
document.getSelection().collapse(e.target, cursor);
|
|
@@ -824,7 +816,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
824
816
|
if (valueProp === undefined) {
|
|
825
817
|
let item = null;
|
|
826
818
|
|
|
827
|
-
if (
|
|
819
|
+
if (typeof renderSelectedItem === 'function') {
|
|
828
820
|
item = renderSelectedItem({
|
|
829
821
|
data,
|
|
830
822
|
index
|
|
@@ -926,7 +918,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
926
918
|
};
|
|
927
919
|
|
|
928
920
|
const onClear = e => {
|
|
929
|
-
if (disabled || readOnly || loading) return;
|
|
921
|
+
if (disabled || readOnly || loading || !clearAble) return;
|
|
930
922
|
currentValue[unique] = multiple ? [] : '';
|
|
931
923
|
|
|
932
924
|
if (inputRef.current.tagName.toLowerCase() === 'div') {
|
|
@@ -940,6 +932,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
940
932
|
} // onChangeValue('', '');
|
|
941
933
|
|
|
942
934
|
|
|
935
|
+
setShowClear(false);
|
|
943
936
|
e && e.target && e.target.blur();
|
|
944
937
|
updatePositionDropdown();
|
|
945
938
|
onInput === null || onInput === void 0 ? void 0 : onInput({ ...(inputRef === null || inputRef === void 0 ? void 0 : inputRef.current),
|
|
@@ -963,7 +956,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
963
956
|
inputRef.current.innerHTML = '';
|
|
964
957
|
currentValue[unique] = [];
|
|
965
958
|
} else {
|
|
966
|
-
if (renderSelectedItem || iconExpr && iconExpr !== 'none' && !isSearch[unique]) {
|
|
959
|
+
if (typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none' && !isSearch[unique]) {
|
|
967
960
|
inputRef.current.innerHTML = '';
|
|
968
961
|
} else if (!isSearch[unique]) {
|
|
969
962
|
inputRef.current.value = '';
|
|
@@ -976,7 +969,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
976
969
|
}
|
|
977
970
|
|
|
978
971
|
const length = dataSource.length;
|
|
979
|
-
const displayKey =
|
|
972
|
+
const displayKey = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr;
|
|
980
973
|
|
|
981
974
|
if (displayKey && Array.isArray(displayKey)) {
|
|
982
975
|
displayExpr = displayExpr.join(' - ');
|
|
@@ -995,6 +988,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
995
988
|
currentValue[unique] = [];
|
|
996
989
|
inputRef.current.innerHTML = '';
|
|
997
990
|
valueArr.forEach(v => {
|
|
991
|
+
var _currentObjectDefault3;
|
|
992
|
+
|
|
998
993
|
for (let i = 0; i < length; i++) {
|
|
999
994
|
if (typeof dataSource[i] === 'object' && dataSource[i][valueExpr] === v || dataSource[i] === v) {
|
|
1000
995
|
setMultipleValueHandler(dataSource[i], v, keyArr, i);
|
|
@@ -1002,7 +997,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1002
997
|
}
|
|
1003
998
|
}
|
|
1004
999
|
|
|
1005
|
-
if (currentObjectDefault[unique].length) {
|
|
1000
|
+
if ((_currentObjectDefault3 = currentObjectDefault[unique]) !== null && _currentObjectDefault3 !== void 0 && _currentObjectDefault3.length) {
|
|
1006
1001
|
const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === v || valueObject === v);
|
|
1007
1002
|
|
|
1008
1003
|
if (itemOfValue) {
|
|
@@ -1011,6 +1006,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1011
1006
|
}
|
|
1012
1007
|
});
|
|
1013
1008
|
} else {
|
|
1009
|
+
var _currentObjectDefault4;
|
|
1010
|
+
|
|
1014
1011
|
currentValue[unique] = source;
|
|
1015
1012
|
|
|
1016
1013
|
for (let i = 0; i < length; i++) {
|
|
@@ -1020,7 +1017,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1020
1017
|
}
|
|
1021
1018
|
}
|
|
1022
1019
|
|
|
1023
|
-
if (currentObjectDefault[unique].length) {
|
|
1020
|
+
if ((_currentObjectDefault4 = currentObjectDefault[unique]) !== null && _currentObjectDefault4 !== void 0 && _currentObjectDefault4.length) {
|
|
1024
1021
|
const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === source || valueObject === source);
|
|
1025
1022
|
|
|
1026
1023
|
if (itemOfValue) {
|
|
@@ -1038,14 +1035,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1038
1035
|
const setMultipleValueHandler = (data, value, keyArr, index) => {
|
|
1039
1036
|
let item = null;
|
|
1040
1037
|
|
|
1041
|
-
if (
|
|
1038
|
+
if (typeof renderSelectedItem === 'function') {
|
|
1042
1039
|
item = renderSelectedItem({
|
|
1043
1040
|
data,
|
|
1044
1041
|
index
|
|
1045
1042
|
});
|
|
1046
1043
|
} else {
|
|
1047
1044
|
const icon = getIconFromData(data);
|
|
1048
|
-
const text = keyArr ? renderData(data, keyArr) : data[
|
|
1045
|
+
const text = keyArr ? renderData(data, keyArr) : data[renderSelectedItem || displayExpr];
|
|
1049
1046
|
item = jsx(Chip, {
|
|
1050
1047
|
startIcon: icon,
|
|
1051
1048
|
label: text,
|
|
@@ -1068,9 +1065,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1068
1065
|
};
|
|
1069
1066
|
|
|
1070
1067
|
const setSingleValueHandler = (data, keyArr) => {
|
|
1071
|
-
const text = keyArr ? renderData(data, keyArr) : data[
|
|
1068
|
+
const text = keyArr ? renderData(data, keyArr) : typeof renderSelectedItem === 'string' ? data[renderSelectedItem] : data[displayExpr || valueExpr] || data;
|
|
1072
1069
|
|
|
1073
|
-
if (
|
|
1070
|
+
if (typeof renderSelectedItem === 'function') {
|
|
1074
1071
|
inputRef.current.innerHTML = '';
|
|
1075
1072
|
const item = renderSelectedItem({
|
|
1076
1073
|
data
|
|
@@ -1286,15 +1283,17 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1286
1283
|
}
|
|
1287
1284
|
|
|
1288
1285
|
if (boxRef.current) {
|
|
1286
|
+
var _boxRef$current$query2, _currentObjectDefault5;
|
|
1287
|
+
|
|
1289
1288
|
if (!disabled && !readOnly) {
|
|
1290
1289
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1291
1290
|
}
|
|
1292
1291
|
|
|
1293
1292
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
1294
1293
|
|
|
1295
|
-
const length = boxRef.current.querySelectorAll(`.css-${_DropdownItemCSS.name}`).length;
|
|
1294
|
+
const length = (_boxRef$current$query2 = boxRef.current.querySelectorAll(`.css-${_DropdownItemCSS.name}`)) === null || _boxRef$current$query2 === void 0 ? void 0 : _boxRef$current$query2.length;
|
|
1296
1295
|
|
|
1297
|
-
if (length < dataSource.length + currentObjectDefault[unique].length && !isSearch[unique]) {
|
|
1296
|
+
if (length < dataSource.length + ((_currentObjectDefault5 = currentObjectDefault[unique]) === null || _currentObjectDefault5 === void 0 ? void 0 : _currentObjectDefault5.length) && !isSearch[unique]) {
|
|
1298
1297
|
loadMoreItemsDropdown(length);
|
|
1299
1298
|
!!onLoadMore && dataSource.length < total && boxRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
1300
1299
|
} else {
|
|
@@ -1325,11 +1324,11 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1325
1324
|
...labelProps
|
|
1326
1325
|
}, label) : null, [label, required, disabled, labelProps]);
|
|
1327
1326
|
const inputComp = useMemo(() => {
|
|
1328
|
-
const _InputCSS = InputCSS(multiple, renderSelectedItem);
|
|
1327
|
+
const _InputCSS = InputCSS(multiple, typeof renderSelectedItem === 'function');
|
|
1329
1328
|
|
|
1330
|
-
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem, disabled);
|
|
1329
|
+
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, placeholder, itemMultipleSize, typeof renderSelectedItem === 'function', disabled);
|
|
1331
1330
|
|
|
1332
|
-
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem);
|
|
1331
|
+
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, itemMultipleSize, typeof renderSelectedItem === 'function', disabled);
|
|
1333
1332
|
|
|
1334
1333
|
return jsx("div", {
|
|
1335
1334
|
css: _DropdownFormCSS,
|
|
@@ -1352,8 +1351,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1352
1351
|
e.preventDefault();
|
|
1353
1352
|
return false;
|
|
1354
1353
|
}
|
|
1355
|
-
}) : renderSelectedItem || iconExpr && iconExpr !== 'none' ? jsx("div", { ...inputProps,
|
|
1356
|
-
contentEditable:
|
|
1354
|
+
}) : typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none' ? jsx("div", { ...inputProps,
|
|
1355
|
+
contentEditable: !disabled,
|
|
1357
1356
|
style: inputStyle,
|
|
1358
1357
|
ref: inputRef,
|
|
1359
1358
|
css: _DropdownInputCSS,
|
|
@@ -1413,7 +1412,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1413
1412
|
|
|
1414
1413
|
return jsx(Fragment, null, jsx("div", {
|
|
1415
1414
|
ref: dropdownRef,
|
|
1416
|
-
css: DropdownRootCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem, loading, showClear),
|
|
1415
|
+
css: DropdownRootCSS(viewType, multiple, placeholder, itemMultipleSize, typeof renderSelectedItem === 'function', loading, showClear),
|
|
1417
1416
|
className: ['DGN-UI-Dropdown', className, error && 'error', loading && 'dgn-dropdown-loading', disabled ? 'disabled' : readOnly && 'readOnly'].join(' ').trim().replace(/\s+/g, ' '),
|
|
1418
1417
|
style: style
|
|
1419
1418
|
}, labelComp, inputComp, errorComp), dropdownComp);
|
|
@@ -1447,7 +1446,7 @@ const DropdownIconCSS = css`
|
|
|
1447
1446
|
}
|
|
1448
1447
|
`;
|
|
1449
1448
|
|
|
1450
|
-
const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem) => css`
|
|
1449
|
+
const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem, disabled) => css`
|
|
1451
1450
|
${flexRow};
|
|
1452
1451
|
${alignCenter};
|
|
1453
1452
|
${outlineNone};
|
|
@@ -1455,7 +1454,7 @@ const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, ren
|
|
|
1455
1454
|
${borderNone};
|
|
1456
1455
|
${paragraph1};
|
|
1457
1456
|
width: 100%;
|
|
1458
|
-
color: ${main};
|
|
1457
|
+
color: ${disabled ? systemDisabled : main};
|
|
1459
1458
|
padding-top: 0;
|
|
1460
1459
|
padding-bottom: ${viewType !== 'outlined' ? 0 : 'inherit'};
|
|
1461
1460
|
padding-left: ${viewType !== 'outlined' ? 0 : '16px'};
|
|
@@ -1489,7 +1488,19 @@ const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, ren
|
|
|
1489
1488
|
padding: ${itemMultipleSize === 'medium' ? 2 : 1}px;
|
|
1490
1489
|
}
|
|
1491
1490
|
}
|
|
1491
|
+
.DGN-UI-Typography {
|
|
1492
|
+
${disabled && `
|
|
1493
|
+
color: ${systemDisabled}
|
|
1494
|
+
`}
|
|
1495
|
+
}
|
|
1492
1496
|
.css-${DropdownIconCSS.name} {
|
|
1497
|
+
${disabled && `
|
|
1498
|
+
svg {
|
|
1499
|
+
path {
|
|
1500
|
+
fill: ${systemDisabled};
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
`}
|
|
1493
1504
|
${renderSelectedItem ? `
|
|
1494
1505
|
min-height: 24px;
|
|
1495
1506
|
min-width: 24px;
|
|
@@ -1538,10 +1549,9 @@ const DropdownFormCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1538
1549
|
}
|
|
1539
1550
|
.css-${DropdownInputCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem).name} {
|
|
1540
1551
|
color: ${active};
|
|
1552
|
+
}
|
|
1541
1553
|
}
|
|
1542
|
-
}
|
|
1543
1554
|
`}
|
|
1544
|
-
|
|
1545
1555
|
&:focus-within {
|
|
1546
1556
|
border-bottom-color: ${focus};
|
|
1547
1557
|
&::after {
|
|
@@ -1566,7 +1576,7 @@ const DropdownFormCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1566
1576
|
left: 0;
|
|
1567
1577
|
right: 0;
|
|
1568
1578
|
bottom: 0;
|
|
1569
|
-
border-bottom: 1px solid ${rest};
|
|
1579
|
+
border-bottom: 1px solid ${disabled ? systemDisabled : rest};
|
|
1570
1580
|
}
|
|
1571
1581
|
&::after {
|
|
1572
1582
|
${positionAbsolute};
|
|
@@ -1585,7 +1595,7 @@ const DropdownFormCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1585
1595
|
${positionRelative};
|
|
1586
1596
|
${borderRadius4px};
|
|
1587
1597
|
${borderBox};
|
|
1588
|
-
${border(1, rest)};
|
|
1598
|
+
${border(1, disabled ? systemDisabled : rest)};
|
|
1589
1599
|
width: 100%;
|
|
1590
1600
|
min-height: 40px;
|
|
1591
1601
|
${!disabled && `
|
|
@@ -1821,9 +1831,6 @@ Dropdown.propTypes = {
|
|
|
1821
1831
|
/** the displayed value for each change */
|
|
1822
1832
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1823
1833
|
|
|
1824
|
-
/** field name used for text display in input */
|
|
1825
|
-
keyExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1826
|
-
|
|
1827
1834
|
/** field name used for text display<br/>
|
|
1828
1835
|
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1829
1836
|
* Note: don't use 'id - name', return undefined
|
|
@@ -1915,7 +1922,7 @@ Dropdown.propTypes = {
|
|
|
1915
1922
|
/** function displays selected items by custom, example:<br/>
|
|
1916
1923
|
* renderItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
1917
1924
|
*/
|
|
1918
|
-
renderSelectedItem: PropTypes.func,
|
|
1925
|
+
renderSelectedItem: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
1919
1926
|
|
|
1920
1927
|
/** the function will run when entering input<br/>
|
|
1921
1928
|
* if undefined: the filter function will run (default)
|