diginet-core-ui 1.3.67 → 1.3.68
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/avatar/index.js +19 -19
- package/components/badge/index.js +5 -5
- package/components/button/icon.js +21 -21
- package/components/button/index.js +13 -13
- package/components/form-control/attachment/index.js +21 -21
- package/components/form-control/calendar/function.js +113 -113
- package/components/form-control/input-base/index.js +47 -10
- package/components/form-control/money-input/index.js +6 -2
- package/components/form-control/number-input/index2.js +13 -4
- package/components/form-control/phone-input/index.js +6 -2
- package/components/form-control/text-input/index.js +13 -3
- package/components/paging/page-info.js +285 -101
- package/components/paging/page-selector2.js +95 -56
- package/components/popover/index.js +21 -21
- package/icons/effect.js +15 -15
- package/package.json +1 -1
- package/readme.md +6 -0
- package/styles/utils.js +10 -10
- package/utils/classNames.js +30 -0
- package/utils/index.js +1 -0
- package/utils/useInput.js +1 -8
|
@@ -45,20 +45,24 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
45
45
|
onKeyDown,
|
|
46
46
|
onKeyUp,
|
|
47
47
|
delayOnChange,
|
|
48
|
+
autoWidth,
|
|
48
49
|
...props
|
|
49
50
|
}, reference) => {
|
|
51
|
+
const _onChange = e => {
|
|
52
|
+
onChange && onChange(e);
|
|
53
|
+
dynamicWidth(e);
|
|
54
|
+
};
|
|
55
|
+
|
|
50
56
|
const {
|
|
51
57
|
bind
|
|
52
|
-
} = useInput(
|
|
53
|
-
|
|
54
|
-
valueProp,
|
|
55
|
-
onChange,
|
|
56
|
-
onInput,
|
|
57
|
-
delayOnChange
|
|
58
|
-
});
|
|
58
|
+
} = useInput(defaultValue, valueProp, _onChange, onInput, delayOnChange);
|
|
59
|
+
if (!autoWidth && inputProps !== null && inputProps !== void 0 && inputProps.autoWidth) autoWidth = inputProps.autoWidth;
|
|
59
60
|
if (!inputBaseRef) inputBaseRef = useRef(null);
|
|
60
61
|
const ref = useRef(null);
|
|
61
62
|
const valueArray = useRef([]);
|
|
63
|
+
const canvas = document.createElement('canvas');
|
|
64
|
+
const styleInputBase = useRef(null);
|
|
65
|
+
const widthInit = useRef(null);
|
|
62
66
|
const isEnabled = !readOnly && !disabled;
|
|
63
67
|
/* Start styled */
|
|
64
68
|
|
|
@@ -68,6 +72,7 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
68
72
|
align-items: center;
|
|
69
73
|
position: relative;
|
|
70
74
|
height: max-content;
|
|
75
|
+
width: ${autoWidth ? 'max-content' : 'auto'};
|
|
71
76
|
&:hover,
|
|
72
77
|
&:focus-within {
|
|
73
78
|
.start-icon:not(.non-effect) {
|
|
@@ -231,9 +236,10 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
231
236
|
flex: 1 1 auto;
|
|
232
237
|
`;
|
|
233
238
|
const inputCSS = css`
|
|
234
|
-
width: 100
|
|
239
|
+
width: ${autoWidth ? '10px' : '100%'};
|
|
235
240
|
border: none;
|
|
236
241
|
outline: none;
|
|
242
|
+
transition: all 0.1s;
|
|
237
243
|
color: ${colors.input};
|
|
238
244
|
background-color: transparent;
|
|
239
245
|
padding-top: 0;
|
|
@@ -507,6 +513,12 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
507
513
|
if (multiline && !/\d+/.test(rows)) {
|
|
508
514
|
inputBaseRef.current.style.height = 0;
|
|
509
515
|
inputBaseRef.current.style.height = Math.max(defaultHeight, inputBaseRef.current.scrollHeight) + 'px';
|
|
516
|
+
} else {
|
|
517
|
+
dynamicWidth({
|
|
518
|
+
target: {
|
|
519
|
+
value: valueProp
|
|
520
|
+
}
|
|
521
|
+
});
|
|
510
522
|
}
|
|
511
523
|
}
|
|
512
524
|
|
|
@@ -532,8 +544,27 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
532
544
|
}, [disabled]);
|
|
533
545
|
/* End handler */
|
|
534
546
|
|
|
547
|
+
const saveInitInfo = refs => {
|
|
548
|
+
inputBaseRef.current = refs;
|
|
549
|
+
if (!autoWidth) return;
|
|
550
|
+
const style = window.getComputedStyle(refs) || refs.currentStyle;
|
|
551
|
+
if (!widthInit.current) widthInit.current = parseInt(style.width);
|
|
552
|
+
styleInputBase.current = style;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const dynamicWidth = e => {
|
|
556
|
+
if (!autoWidth || !inputBaseRef.current) return;
|
|
557
|
+
if (!canvas || !styleInputBase.current || !inputBaseRef.current) return;
|
|
558
|
+
const context = canvas.getContext('2d');
|
|
559
|
+
context.font = styleInputBase.current.font;
|
|
560
|
+
const {
|
|
561
|
+
width
|
|
562
|
+
} = context.measureText(e.target.value);
|
|
563
|
+
inputBaseRef.current.style.width = `${Math.max(width, widthInit.current)}px`;
|
|
564
|
+
};
|
|
535
565
|
/* Start component */
|
|
536
566
|
|
|
567
|
+
|
|
537
568
|
const newClass = (viewType === 'outlined' ? 'outlined' : 'underlined') + (nonStyle ? ' non-style' : '');
|
|
538
569
|
const MultipleInputComp = jsx("div", {
|
|
539
570
|
css: multilineCSS,
|
|
@@ -605,7 +636,10 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
605
636
|
readOnly: readOnly,
|
|
606
637
|
style: inputStyle || (inputProps === null || inputProps === void 0 ? void 0 : inputProps.style),
|
|
607
638
|
className: [newClass, inputProps === null || inputProps === void 0 ? void 0 : inputProps.className].join(' '),
|
|
608
|
-
ref:
|
|
639
|
+
ref: refs => {
|
|
640
|
+
if (!refs) return;
|
|
641
|
+
saveInitInfo(refs);
|
|
642
|
+
},
|
|
609
643
|
css: inputCSS,
|
|
610
644
|
onKeyDown: onKeyDown,
|
|
611
645
|
onKeyUp: onKeyUp,
|
|
@@ -744,6 +778,9 @@ InputBase.propTypes = {
|
|
|
744
778
|
inputRef: PropTypes.any,
|
|
745
779
|
|
|
746
780
|
/** delayOnChange of InputBase component */
|
|
747
|
-
delayOnChange: PropTypes.number
|
|
781
|
+
delayOnChange: PropTypes.number,
|
|
782
|
+
|
|
783
|
+
/** autoWidth of TextInput component, don't run with multiline = true */
|
|
784
|
+
autoWidth: PropTypes.bool
|
|
748
785
|
};
|
|
749
786
|
export default InputBase;
|
|
@@ -123,6 +123,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
123
123
|
convertToWords,
|
|
124
124
|
prefix,
|
|
125
125
|
suffix,
|
|
126
|
+
labelProps,
|
|
126
127
|
...props
|
|
127
128
|
}, reference) => {
|
|
128
129
|
const ref = useRef(null);
|
|
@@ -418,7 +419,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
418
419
|
css: MoneyInputRoot,
|
|
419
420
|
className: ['DGN-UI-Money-Input', className].join(' ').trim().replace(/\s+/g, ' '),
|
|
420
421
|
...props
|
|
421
|
-
}, !!label && jsx(Label, {
|
|
422
|
+
}, !!label && jsx(Label, { ...labelProps,
|
|
422
423
|
required: required,
|
|
423
424
|
disabled: disabled
|
|
424
425
|
}, label), jsx(InputBase, {
|
|
@@ -581,6 +582,9 @@ MoneyInput.propTypes = {
|
|
|
581
582
|
onFocus: PropTypes.func,
|
|
582
583
|
|
|
583
584
|
/** inputRef of MoneyInput component */
|
|
584
|
-
inputRef: PropTypes.any
|
|
585
|
+
inputRef: PropTypes.any,
|
|
586
|
+
|
|
587
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
588
|
+
labelProps: PropTypes.object
|
|
585
589
|
};
|
|
586
590
|
export default MoneyInput;
|
|
@@ -51,7 +51,9 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
51
51
|
delayOnChange,
|
|
52
52
|
fixedDecimalDigit,
|
|
53
53
|
className,
|
|
54
|
-
maxDigit
|
|
54
|
+
maxDigit,
|
|
55
|
+
autoWidth,
|
|
56
|
+
labelProps
|
|
55
57
|
}, reference) => {
|
|
56
58
|
inputRef = inputRef || useRef(null);
|
|
57
59
|
const pos = useRef(null);
|
|
@@ -156,7 +158,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
156
158
|
let value = (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : e.target.value;
|
|
157
159
|
if (fixedDecimalDigit) value = Number(value).toFixed(decimalDigit);
|
|
158
160
|
|
|
159
|
-
if (value && (typeof min !== 'undefined' || typeof max !== 'undefined')) {
|
|
161
|
+
if ((value || value === '' && typeof min !== 'undefined') && (typeof min !== 'undefined' || typeof max !== 'undefined')) {
|
|
160
162
|
value = convertMoneyToNumber(value);
|
|
161
163
|
|
|
162
164
|
if (Number(value) < min || Number(value) > max) {
|
|
@@ -269,7 +271,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
269
271
|
ref: ref,
|
|
270
272
|
css: NumberInputRoot,
|
|
271
273
|
className: ['DGN-UI-NumberInput', className].join(' ').trim().replace(/\s+/g, ' ')
|
|
272
|
-
}, !!label && jsx(Label, {
|
|
274
|
+
}, !!label && jsx(Label, { ...labelProps,
|
|
273
275
|
required: required,
|
|
274
276
|
disabled: disabled
|
|
275
277
|
}, label), jsx(InputBase, {
|
|
@@ -283,6 +285,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
283
285
|
readOnly: readOnly,
|
|
284
286
|
status: !!error || validateResult ? 'danger' : 'default',
|
|
285
287
|
inputProps: inputProps,
|
|
288
|
+
autoWidth: autoWidth,
|
|
286
289
|
inputStyle: inputStyle,
|
|
287
290
|
startIcon: startIcon,
|
|
288
291
|
endIcon: endIcon,
|
|
@@ -435,6 +438,12 @@ NumberInput.propTypes = {
|
|
|
435
438
|
className: PropTypes.string,
|
|
436
439
|
|
|
437
440
|
/** max character is number of NumberInput component */
|
|
438
|
-
maxDigit: PropTypes.number
|
|
441
|
+
maxDigit: PropTypes.number,
|
|
442
|
+
|
|
443
|
+
/** autoWidth of TextInput component, don't run with multiline = true */
|
|
444
|
+
autoWidth: PropTypes.bool,
|
|
445
|
+
|
|
446
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
447
|
+
labelProps: PropTypes.object
|
|
439
448
|
};
|
|
440
449
|
export default NumberInput;
|
|
@@ -42,6 +42,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
42
42
|
onInput,
|
|
43
43
|
onKeyDown,
|
|
44
44
|
onKeyUp,
|
|
45
|
+
labelProps,
|
|
45
46
|
...props
|
|
46
47
|
}, reference) => {
|
|
47
48
|
const ref = useRef(null);
|
|
@@ -295,7 +296,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
295
296
|
marginBottom: '20px'
|
|
296
297
|
},
|
|
297
298
|
...props
|
|
298
|
-
}, jsx(Label, {
|
|
299
|
+
}, jsx(Label, { ...labelProps,
|
|
299
300
|
required: required,
|
|
300
301
|
disabled: disabled
|
|
301
302
|
}, label), jsx(InputBase, {
|
|
@@ -413,6 +414,9 @@ PhoneInput.propTypes = {
|
|
|
413
414
|
onFocus: PropTypes.func,
|
|
414
415
|
|
|
415
416
|
/** inputRef of PhoneInput component */
|
|
416
|
-
inputRef: PropTypes.any
|
|
417
|
+
inputRef: PropTypes.any,
|
|
418
|
+
|
|
419
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
420
|
+
labelProps: PropTypes.object
|
|
417
421
|
};
|
|
418
422
|
export default PhoneInput;
|
|
@@ -66,6 +66,7 @@ const TextInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
66
66
|
onKeyUp,
|
|
67
67
|
onPaste,
|
|
68
68
|
validates,
|
|
69
|
+
autoWidth,
|
|
69
70
|
...props
|
|
70
71
|
}, reference) => {
|
|
71
72
|
const ref = useRef(null);
|
|
@@ -244,11 +245,12 @@ const TextInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
244
245
|
}
|
|
245
246
|
}, [error, value]);
|
|
246
247
|
useEffect(() => {
|
|
247
|
-
if (placeholder !== undefined) {
|
|
248
|
+
if (placeholder !== undefined && inputRef.current) {
|
|
248
249
|
inputRef.current.placeholder = placeholder;
|
|
249
250
|
}
|
|
250
251
|
}, [placeholder]);
|
|
251
252
|
useEffect(() => {
|
|
253
|
+
if (!inputRef.current) return;
|
|
252
254
|
inputRef.current.readOnly = !!readOnly;
|
|
253
255
|
|
|
254
256
|
if (/^(quick)?Edit/i.test(type) && !multiline && readOnly) {
|
|
@@ -347,6 +349,7 @@ const TextInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
347
349
|
disabled: disabled,
|
|
348
350
|
readOnly: readOnly,
|
|
349
351
|
multiline: multiline,
|
|
352
|
+
autoWidth: autoWidth,
|
|
350
353
|
rows: rows,
|
|
351
354
|
maxRows: maxRows,
|
|
352
355
|
status: isError || validateResult ? 'danger' : 'default',
|
|
@@ -387,7 +390,8 @@ TextInput.defaultProps = {
|
|
|
387
390
|
disabled: false,
|
|
388
391
|
readOnly: false,
|
|
389
392
|
multiline: false,
|
|
390
|
-
iconStyle: {}
|
|
393
|
+
iconStyle: {},
|
|
394
|
+
autoWidth: false
|
|
391
395
|
};
|
|
392
396
|
TextInput.propTypes = {
|
|
393
397
|
/** type of input */
|
|
@@ -500,6 +504,12 @@ TextInput.propTypes = {
|
|
|
500
504
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
501
505
|
|
|
502
506
|
/** inputRef of TextInput component */
|
|
503
|
-
inputRef: PropTypes.any
|
|
507
|
+
inputRef: PropTypes.any,
|
|
508
|
+
|
|
509
|
+
/** autoWidth of TextInput component, don't run with multiline = true */
|
|
510
|
+
autoWidth: PropTypes.bool,
|
|
511
|
+
|
|
512
|
+
/** If `true`, a textarea element is rendered. */
|
|
513
|
+
multiline: PropTypes.bool
|
|
504
514
|
};
|
|
505
515
|
export default TextInput;
|