diginet-core-ui 1.4.52-beta.0 → 1.4.52-beta.10
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.
|
@@ -459,8 +459,7 @@ const Dropdown = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference)
|
|
|
459
459
|
parentID: treeViewParentID,
|
|
460
460
|
value: typeof currentValue[unique] === 'string' ? [currentValue[unique]] : currentValue[unique],
|
|
461
461
|
onChange: (e, value) => onChangeValue(e, '', multiple ? value : e.value),
|
|
462
|
-
renderItem: renderItem
|
|
463
|
-
isInDropdown: true
|
|
462
|
+
renderItem: renderItem
|
|
464
463
|
}) : EmptyDataText);
|
|
465
464
|
};
|
|
466
465
|
|
|
@@ -116,6 +116,7 @@ const MoneyInput = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference
|
|
|
116
116
|
viewType,
|
|
117
117
|
defaultValue,
|
|
118
118
|
value,
|
|
119
|
+
fixedDecimalDigit,
|
|
119
120
|
...other
|
|
120
121
|
} = props;
|
|
121
122
|
const ref = useRef(null);
|
|
@@ -332,11 +333,24 @@ const MoneyInput = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference
|
|
|
332
333
|
if (value === null) {
|
|
333
334
|
inputRef.current.value = '';
|
|
334
335
|
} else {
|
|
335
|
-
|
|
336
|
+
let number = value;
|
|
337
|
+
if (fixedDecimalDigit && !!decimalDigit) {
|
|
338
|
+
var _strVal$split;
|
|
339
|
+
const strVal = String(value);
|
|
340
|
+
const isDecimalNum = strVal.indexOf('.') > -1 && (((_strVal$split = strVal.split('.')) === null || _strVal$split === void 0 ? void 0 : _strVal$split[1]) || '').length >= decimalDigit;
|
|
341
|
+
if (isDecimalNum) {
|
|
342
|
+
const coreToFixed = (num, precision) => {
|
|
343
|
+
return (+(Math.round(+(num + 'e' + precision)) + 'e' + -precision)).toFixed(precision);
|
|
344
|
+
};
|
|
345
|
+
const val = coreToFixed(Number(String(value).replace(thousandSeparator, '')), decimalDigit);
|
|
346
|
+
number = String(val);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const v = getValueWithDecimal(number.toString().replace('.', decimalSymbol));
|
|
336
350
|
if (convertToWords && !decimalDigit && (disabled || readOnly)) {
|
|
337
351
|
let valueConverted = getGlobal('helperInvalid');
|
|
338
|
-
if (Number.isInteger(
|
|
339
|
-
valueConverted = locale.get() === 'vi' ? num2WordsVi.convert(
|
|
352
|
+
if (Number.isInteger(number)) {
|
|
353
|
+
valueConverted = locale.get() === 'vi' ? num2WordsVi.convert(number) : num2WordsEn(number);
|
|
340
354
|
}
|
|
341
355
|
inputRef.current.value = parseValueWithFix(valueConverted);
|
|
342
356
|
} else {
|
|
@@ -508,6 +522,8 @@ MoneyInput.propTypes = {
|
|
|
508
522
|
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
509
523
|
labelProps: PropTypes.object,
|
|
510
524
|
/** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
|
|
511
|
-
helperTextProps: PropTypes.object
|
|
525
|
+
helperTextProps: PropTypes.object,
|
|
526
|
+
/** If `true`, decimal digit is fixed. */
|
|
527
|
+
fixedDecimalDigit: PropTypes.bool
|
|
512
528
|
};
|
|
513
529
|
export default MoneyInput;
|
|
@@ -99,13 +99,13 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
99
99
|
|
|
100
100
|
// if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
|
|
101
101
|
|
|
102
|
-
/**
|
|
103
|
-
* Convert number to format money
|
|
104
|
-
* @param vl {number} - value
|
|
105
|
-
* @type {function}
|
|
106
|
-
* @return {string}
|
|
107
|
-
* @example 1200300.123 => 1,200,300.123
|
|
108
|
-
* @example 1200300,123 => 1.200.300,123
|
|
102
|
+
/**
|
|
103
|
+
* Convert number to format money
|
|
104
|
+
* @param vl {number} - value
|
|
105
|
+
* @type {function}
|
|
106
|
+
* @return {string}
|
|
107
|
+
* @example 1200300.123 => 1,200,300.123
|
|
108
|
+
* @example 1200300,123 => 1.200.300,123
|
|
109
109
|
*/
|
|
110
110
|
const parseNumberToMoney = useCallback((vl, isNumber) => {
|
|
111
111
|
var _number, _number2, _number$, _number3;
|
|
@@ -115,6 +115,18 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
115
115
|
}
|
|
116
116
|
} = inputRef;
|
|
117
117
|
let number = convertMoneyToNumber(vl, isNumber);
|
|
118
|
+
if (fixedDecimalDigit && !!decimalDigit) {
|
|
119
|
+
var _strVal$split;
|
|
120
|
+
const strVal = String(vl);
|
|
121
|
+
const isDecimalNum = strVal.indexOf('.') > -1 && (((_strVal$split = strVal.split('.')) === null || _strVal$split === void 0 ? void 0 : _strVal$split[1]) || '').length >= decimalDigit;
|
|
122
|
+
if (isDecimalNum) {
|
|
123
|
+
const coreToFixed = (num, precision) => {
|
|
124
|
+
return (+(Math.round(+(num + 'e' + precision)) + 'e' + -precision)).toFixed(precision);
|
|
125
|
+
};
|
|
126
|
+
const val = coreToFixed(Number(String(vl).replace(thousandSymbol, '')), decimalDigit);
|
|
127
|
+
number = String(val);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
118
130
|
|
|
119
131
|
// if (disabledNegative && Number(number || 0) < 0) number = clamp(number, min, max);
|
|
120
132
|
// if (typeof max !== 'undefined' && Number(number) > max) number = Math.min(number, max);
|
|
@@ -138,25 +150,16 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
138
150
|
if (((_number3 = number) === null || _number3 === void 0 ? void 0 : _number3.indexOf(thousandSymbol)) > -1 && selectionStart !== number.length + 1) {
|
|
139
151
|
pos.current = selectionStart + (number.toString().length - 1 === vl.toString().length ? 1 : 0);
|
|
140
152
|
}
|
|
141
|
-
if (fixedDecimalDigit && !!decimalDigit) {
|
|
142
|
-
var _strVal$split;
|
|
143
|
-
const strVal = String(vl);
|
|
144
|
-
const isDecimalNum = strVal.indexOf('.') > -1 && (((_strVal$split = strVal.split('.')) === null || _strVal$split === void 0 ? void 0 : _strVal$split[1]) || '').length >= decimalDigit;
|
|
145
|
-
if (isDecimalNum) {
|
|
146
|
-
const val = Number(vl).toFixed(decimalDigit);
|
|
147
|
-
number = String(val);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
153
|
return number;
|
|
151
154
|
}, [decimalSymbol, max, value, decimalDigit, fixedDecimalDigit]);
|
|
152
155
|
|
|
153
|
-
/**
|
|
154
|
-
* Convert money to format number
|
|
155
|
-
* @param vl {string} - value
|
|
156
|
-
* @type {function}
|
|
157
|
-
* @return {number}
|
|
158
|
-
* @example 1,200,300.123 => 1200300.123
|
|
159
|
-
* @example 1.200.300,123 => 1200300.123
|
|
156
|
+
/**
|
|
157
|
+
* Convert money to format number
|
|
158
|
+
* @param vl {string} - value
|
|
159
|
+
* @type {function}
|
|
160
|
+
* @return {number}
|
|
161
|
+
* @example 1,200,300.123 => 1200300.123
|
|
162
|
+
* @example 1.200.300,123 => 1200300.123
|
|
160
163
|
*/
|
|
161
164
|
const convertMoneyToNumber = useCallback((vl, isNumber) => {
|
|
162
165
|
var _number4, _number4$toString, _number4$toString$rep, _number4$toString$rep2, _number4$toString$rep3;
|
|
@@ -281,14 +284,26 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
281
284
|
onFocus && onFocus(e);
|
|
282
285
|
};
|
|
283
286
|
const _onChange = e => {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
if (delayOnChange) {
|
|
288
|
+
var _e$target;
|
|
289
|
+
if (inputTimer.current) clearTimeout(inputTimer.current);
|
|
290
|
+
const target = e.target;
|
|
291
|
+
target.value = globalRef.current.valueString;
|
|
292
|
+
target.valueString = globalRef.current.returnValue;
|
|
293
|
+
// eslint-disable-next-line no-extra-boolean-cast
|
|
294
|
+
if (!!((_e$target = e.target) !== null && _e$target !== void 0 && _e$target.valueString)) {
|
|
295
|
+
if (e.target.valueString.includes(decimalSymbol) && e.target.valueString.split(decimalSymbol)[1] === '') {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
inputTimer.current = setTimeout(() => {
|
|
300
|
+
onChange({
|
|
301
|
+
...e,
|
|
302
|
+
value: globalRef.current.value,
|
|
303
|
+
target
|
|
304
|
+
});
|
|
305
|
+
}, delayOnChange);
|
|
306
|
+
}
|
|
292
307
|
};
|
|
293
308
|
const validateResult = validates && onValidate(Number(convertMoneyToNumber(value) || 0), validates, true);
|
|
294
309
|
useEffect(() => {
|
|
@@ -314,18 +329,13 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
314
329
|
// if (typeof valueProps !== 'undefined')
|
|
315
330
|
// if (disabledNegative && Number(valueProps || 0) < 0) {
|
|
316
331
|
if (!isNaN(valueProps) || !isNaN(value)) {
|
|
332
|
+
var _valueProps;
|
|
317
333
|
if (min === 0 && Number(valueProps || 0) < 0) {
|
|
318
334
|
// nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
|
|
319
335
|
valueProps = clamp(0, min, max);
|
|
320
336
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
inputTimer.current = setTimeout(() => {
|
|
324
|
-
var _valueProps;
|
|
325
|
-
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
326
|
-
}, delayOnChange);
|
|
327
|
-
}
|
|
328
|
-
// setValue(parseNumberToMoney(valueProps?.toString().replace(regexValidNumber, ''), true));
|
|
337
|
+
// setValue(valueProps);
|
|
338
|
+
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
329
339
|
}
|
|
330
340
|
}, [valueProps, decimalDigit]);
|
|
331
341
|
useEffect(() => {
|
|
@@ -483,10 +493,10 @@ NumberInput.propTypes = {
|
|
|
483
493
|
style: PropTypes.object,
|
|
484
494
|
/** Thousand separator character. */
|
|
485
495
|
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
|
|
486
|
-
/** Validation value, argument can:<br/>
|
|
487
|
-
* * string: the validation rule. Example required.<br/>
|
|
488
|
-
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
489
|
-
* * array: the validation rule list, insist object/string
|
|
496
|
+
/** Validation value, argument can:<br/>
|
|
497
|
+
* * string: the validation rule. Example required.<br/>
|
|
498
|
+
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
499
|
+
* * array: the validation rule list, insist object/string
|
|
490
500
|
*/
|
|
491
501
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
492
502
|
/** The value of the input element, required for a controlled component. */
|
|
@@ -37,7 +37,6 @@ const TreeView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference)
|
|
|
37
37
|
expand,
|
|
38
38
|
expandIcon,
|
|
39
39
|
id,
|
|
40
|
-
isInDropdown,
|
|
41
40
|
multiple,
|
|
42
41
|
multipleValueMode,
|
|
43
42
|
onChange,
|
|
@@ -70,7 +69,7 @@ const TreeView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference)
|
|
|
70
69
|
allowNumber: false,
|
|
71
70
|
allowSymbol: false
|
|
72
71
|
}));
|
|
73
|
-
const _TreeViewRootCSS = TreeViewRootCSS(theme
|
|
72
|
+
const _TreeViewRootCSS = TreeViewRootCSS(theme);
|
|
74
73
|
const determinateCheckbox = (input, determinate) => {
|
|
75
74
|
if (multipleValueMode === 'multiple' || disabledRelevantValue) {
|
|
76
75
|
input.classList[determinate ? 'add' : 'remove']('determinate');
|
|
@@ -794,7 +793,7 @@ const TreeView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference)
|
|
|
794
793
|
const TreeViewRootCSS = ({
|
|
795
794
|
colors,
|
|
796
795
|
spacing
|
|
797
|
-
}
|
|
796
|
+
}) => css`
|
|
798
797
|
${displayBlock};
|
|
799
798
|
${positionRelative};
|
|
800
799
|
.DGN-UI-Accordion {
|
|
@@ -834,7 +833,7 @@ const TreeViewRootCSS = ({
|
|
|
834
833
|
.TreeView-Content {
|
|
835
834
|
${displayBlock};
|
|
836
835
|
${positionRelative};
|
|
837
|
-
${
|
|
836
|
+
${parseMaxHeight(240)};
|
|
838
837
|
${overflowYScroll};
|
|
839
838
|
&::-webkit-scrollbar {
|
|
840
839
|
${borderRadius(4)};
|