diginet-core-ui 1.4.52-beta.1 → 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
- const v = getValueWithDecimal(value.toString().replace('.', decimalSymbol));
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(value)) {
339
- valueConverted = locale.get() === 'vi' ? num2WordsVi.convert(value) : num2WordsEn(value);
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;
@@ -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,15 +150,6 @@ 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
 
@@ -282,11 +285,18 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
282
285
  };
283
286
  const _onChange = e => {
284
287
  if (delayOnChange) {
288
+ var _e$target;
285
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
+ }
286
299
  inputTimer.current = setTimeout(() => {
287
- const target = e.target;
288
- target.value = globalRef.current.valueString;
289
- target.valueString = globalRef.current.returnValue;
290
300
  onChange({
291
301
  ...e,
292
302
  value: globalRef.current.value,
@@ -324,8 +334,8 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
324
334
  // nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
325
335
  valueProps = clamp(0, min, max);
326
336
  }
337
+ // setValue(valueProps);
327
338
  setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
328
- // setValue(parseNumberToMoney(valueProps?.toString().replace(regexValidNumber, ''), true));
329
339
  }
330
340
  }, [valueProps, decimalDigit]);
331
341
  useEffect(() => {
@@ -393,7 +403,7 @@ const NumberInputRootCSS = ({
393
403
  }
394
404
  `;
395
405
  NumberInput.defaultProps = {
396
- delayOnChange: 1000
406
+ delayOnChange: 500
397
407
  // autoFocus: false,
398
408
  // className: '',
399
409
  // decimalDigit: Infinity,
@@ -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, isInDropdown);
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
- }, isInDropdown) => css`
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
- ${isInDropdown && parseMaxHeight(240)};
836
+ ${parseMaxHeight(240)};
838
837
  ${overflowYScroll};
839
838
  &::-webkit-scrollbar {
840
839
  ${borderRadius(4)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.4.52-beta.1",
3
+ "version": "1.4.52-beta.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",