diginet-core-ui 1.4.52-beta.0 → 1.4.52-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.
|
@@ -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;
|
|
@@ -114,6 +114,15 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
114
114
|
selectionStart
|
|
115
115
|
}
|
|
116
116
|
} = inputRef;
|
|
117
|
+
if (fixedDecimalDigit && !!decimalDigit) {
|
|
118
|
+
var _strVal$split;
|
|
119
|
+
const strVal = String(vl);
|
|
120
|
+
const isDecimalNum = strVal.indexOf('.') > -1 && (((_strVal$split = strVal.split('.')) === null || _strVal$split === void 0 ? void 0 : _strVal$split[1]) || '').length >= decimalDigit;
|
|
121
|
+
if (isDecimalNum) {
|
|
122
|
+
const val = Number(vl.replace(thousandSymbol, '')).toFixed(decimalDigit);
|
|
123
|
+
number = String(val);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
117
126
|
let number = convertMoneyToNumber(vl, isNumber);
|
|
118
127
|
|
|
119
128
|
// if (disabledNegative && Number(number || 0) < 0) number = clamp(number, min, max);
|
|
@@ -138,25 +147,16 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
138
147
|
if (((_number3 = number) === null || _number3 === void 0 ? void 0 : _number3.indexOf(thousandSymbol)) > -1 && selectionStart !== number.length + 1) {
|
|
139
148
|
pos.current = selectionStart + (number.toString().length - 1 === vl.toString().length ? 1 : 0);
|
|
140
149
|
}
|
|
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
150
|
return number;
|
|
151
151
|
}, [decimalSymbol, max, value, decimalDigit, fixedDecimalDigit]);
|
|
152
152
|
|
|
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
|
|
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
|
|
160
160
|
*/
|
|
161
161
|
const convertMoneyToNumber = useCallback((vl, isNumber) => {
|
|
162
162
|
var _number4, _number4$toString, _number4$toString$rep, _number4$toString$rep2, _number4$toString$rep3;
|
|
@@ -281,14 +281,19 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
281
281
|
onFocus && onFocus(e);
|
|
282
282
|
};
|
|
283
283
|
const _onChange = e => {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
284
|
+
if (delayOnChange) {
|
|
285
|
+
if (inputTimer.current) clearTimeout(inputTimer.current);
|
|
286
|
+
inputTimer.current = setTimeout(() => {
|
|
287
|
+
const target = e.target;
|
|
288
|
+
target.value = globalRef.current.valueString;
|
|
289
|
+
target.valueString = globalRef.current.returnValue;
|
|
290
|
+
onChange({
|
|
291
|
+
...e,
|
|
292
|
+
value: globalRef.current.value,
|
|
293
|
+
target
|
|
294
|
+
});
|
|
295
|
+
}, delayOnChange);
|
|
296
|
+
}
|
|
292
297
|
};
|
|
293
298
|
const validateResult = validates && onValidate(Number(convertMoneyToNumber(value) || 0), validates, true);
|
|
294
299
|
useEffect(() => {
|
|
@@ -314,17 +319,12 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
314
319
|
// if (typeof valueProps !== 'undefined')
|
|
315
320
|
// if (disabledNegative && Number(valueProps || 0) < 0) {
|
|
316
321
|
if (!isNaN(valueProps) || !isNaN(value)) {
|
|
322
|
+
var _valueProps;
|
|
317
323
|
if (min === 0 && Number(valueProps || 0) < 0) {
|
|
318
324
|
// nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
|
|
319
325
|
valueProps = clamp(0, min, max);
|
|
320
326
|
}
|
|
321
|
-
|
|
322
|
-
if (inputTimer.current) clearTimeout(inputTimer.current);
|
|
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
|
-
}
|
|
327
|
+
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
328
328
|
// setValue(parseNumberToMoney(valueProps?.toString().replace(regexValidNumber, ''), true));
|
|
329
329
|
}
|
|
330
330
|
}, [valueProps, decimalDigit]);
|
|
@@ -393,7 +393,7 @@ const NumberInputRootCSS = ({
|
|
|
393
393
|
}
|
|
394
394
|
`;
|
|
395
395
|
NumberInput.defaultProps = {
|
|
396
|
-
delayOnChange:
|
|
396
|
+
delayOnChange: 1000
|
|
397
397
|
// autoFocus: false,
|
|
398
398
|
// className: '',
|
|
399
399
|
// decimalDigit: Infinity,
|
|
@@ -483,10 +483,10 @@ NumberInput.propTypes = {
|
|
|
483
483
|
style: PropTypes.object,
|
|
484
484
|
/** Thousand separator character. */
|
|
485
485
|
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
|
|
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
|
|
490
490
|
*/
|
|
491
491
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
492
492
|
/** The value of the input element, required for a controlled component. */
|