intelicoreact 1.5.32 → 1.5.33

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.
@@ -24,6 +24,7 @@ const InputCurrency = _ref => {
24
24
  max,
25
25
  error,
26
26
  isNoCheckMinMax,
27
+ allowZero = false,
27
28
  onlyNumbers = {
28
29
  // type: "int",
29
30
  type: "float",
@@ -40,10 +41,25 @@ const InputCurrency = _ref => {
40
41
  let newValue = event.target.value;
41
42
  newValue = newValue.replace(currencySymbol, "");
42
43
  const preparedValue = (0, _fieldValueFormatters.filterNumeric)(newValue, onlyNumbers);
43
- newValue = formatNumberWithCommas(preparedValue);
44
- newValue = "".concat(currencySymbol).concat(newValue);
45
- setInputValue(newValue);
46
- if (value !== parseFloat(preparedValue)) onChange(!isNaN(parseFloat(preparedValue)) ? parseFloat(preparedValue) : "");
44
+ const parsedValue = parseFloat(preparedValue);
45
+ if (!isNaN(parsedValue)) {
46
+ if (parsedValue === 0 || preparedValue === '0') {
47
+ if (allowZero) {
48
+ setInputValue("".concat(currencySymbol, "0"));
49
+ onChange(0);
50
+ } else {
51
+ setInputValue(currencySymbol);
52
+ onChange("");
53
+ }
54
+ } else {
55
+ const formattedValue = formatNumberWithCommas(preparedValue);
56
+ setInputValue("".concat(currencySymbol).concat(formattedValue));
57
+ onChange(parsedValue);
58
+ }
59
+ } else {
60
+ setInputValue(currencySymbol);
61
+ onChange("");
62
+ }
47
63
  };
48
64
  const onInputClick = () => {
49
65
  if (!inputValue) {
@@ -72,10 +88,22 @@ const InputCurrency = _ref => {
72
88
  return true;
73
89
  };
74
90
  (0, _react.useEffect)(() => {
75
- if (value && parseFloat(value) !== parseFloat((0, _fieldValueFormatters.filterNumeric)(inputValue, onlyNumbers))) {
76
- if (checkMinMax(null, value)) setInputValue("".concat(currencySymbol).concat(formatNumberWithCommas(value)));
91
+ if (value === 0 || value === '0') {
92
+ if (allowZero) {
93
+ setInputValue("".concat(currencySymbol, "0"));
94
+ onChange(0);
95
+ } else {
96
+ setInputValue(currencySymbol);
97
+ onChange('');
98
+ }
99
+ } else if (value) {
100
+ if (checkMinMax(null, value)) {
101
+ setInputValue("".concat(currencySymbol).concat(formatNumberWithCommas(value)));
102
+ }
103
+ } else {
104
+ setInputValue(currencySymbol);
77
105
  }
78
- }, [value]);
106
+ }, [value, currencySymbol, allowZero]);
79
107
  return /*#__PURE__*/_react.default.createElement("div", {
80
108
  className: (0, _classnames.default)("input-currency-box", className, {
81
109
  disabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.5.32",
3
+ "version": "1.5.33",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [