iglooform 2.5.14 → 2.5.15

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.
@@ -6,7 +6,9 @@ export interface AmountProps extends InputProps, IglooComponentProps {
6
6
  currencyProps?: InputProps;
7
7
  amount?: number;
8
8
  amountProps?: InputProps;
9
- seperator?: ',';
9
+ seperator?: ',' | '.';
10
+ separator?: ',' | '.';
11
+ decimalSeparator?: ',' | '.';
10
12
  }
11
13
  declare const Amount: FC<AmountProps>;
12
14
  export default Amount;
@@ -1,6 +1,6 @@
1
1
  import "antd/es/input/style";
2
2
  import _Input from "antd/es/input";
3
- var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "disabled"];
3
+ var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "separator", "decimalSeparator", "disabled"];
4
4
 
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
6
 
@@ -19,16 +19,16 @@ import classnames from 'classnames';
19
19
  import { staticFormatMessage } from '../locale';
20
20
  import './style/index.less';
21
21
 
22
- var thousands = function thousands(number) {
22
+ var thousands = function thousands(number, decimalSeparator, separator) {
23
23
  if (number === null || number === undefined) return undefined;
24
- var arr = String(number).split('.');
24
+ var arr = String(number).replace('.', decimalSeparator).split(decimalSeparator);
25
25
  return arr.map(function (s, index) {
26
26
  if (index === 0) {
27
- return s.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
27
+ return s.replace(/(?=(?!\b)(\d{3})+$)/g, separator);
28
28
  }
29
29
 
30
- return s.replace(/(\d{3})(?=[^$])/g, '$1,');
31
- }).join('.');
30
+ return s.replace(/(\d{3})(?=[^$])/g, "$1".concat(separator));
31
+ }).join(decimalSeparator);
32
32
  };
33
33
 
34
34
  var Amount = function Amount(_ref) {
@@ -39,8 +39,11 @@ var Amount = function Amount(_ref) {
39
39
  _ref$amountProps = _ref.amountProps,
40
40
  amountProps = _ref$amountProps === void 0 ? {} : _ref$amountProps,
41
41
  value = _ref.value,
42
- _ref$seperator = _ref.seperator,
43
- seperator = _ref$seperator === void 0 ? ',' : _ref$seperator,
42
+ seperator = _ref.seperator,
43
+ _ref$separator = _ref.separator,
44
+ separator = _ref$separator === void 0 ? seperator || ',' : _ref$separator,
45
+ _ref$decimalSeparator = _ref.decimalSeparator,
46
+ decimalSeparator = _ref$decimalSeparator === void 0 ? '.' : _ref$decimalSeparator,
44
47
  disabled = _ref.disabled,
45
48
  rest = _objectWithoutProperties(_ref, _excluded);
46
49
 
@@ -48,11 +51,11 @@ var Amount = function Amount(_ref) {
48
51
  var onChange = rest.onChange;
49
52
 
50
53
  if (typeof value === 'string') {
51
- if (value.endsWith('.')) {
52
- e.target.value = value.replace('.', '');
54
+ if (value.endsWith(decimalSeparator)) {
55
+ e.target.value = value.replace(decimalSeparator, '');
53
56
  }
54
57
 
55
- if (value.endsWith('0') && value.includes('.')) {
58
+ if (value.endsWith('0') && value.includes(decimalSeparator)) {
56
59
  e.target.value = value.replace(/[0]+$/, '');
57
60
  }
58
61
 
@@ -67,7 +70,7 @@ var Amount = function Amount(_ref) {
67
70
  className: classnames('igloo-input-amount', {
68
71
  'igloo-input-disable': disabled
69
72
  }, className),
70
- value: thousands(value),
73
+ value: thousands(value, decimalSeparator, separator),
71
74
  addonBefore: currency ? _jsx("span", {
72
75
  className: "igloo-input-areacode",
73
76
  children: currency
@@ -76,24 +79,31 @@ var Amount = function Amount(_ref) {
76
79
  };
77
80
 
78
81
  Amount.formItemPropsHandler = function (_ref2) {
79
- var _ref2$seperator = _ref2.seperator,
80
- seperator = _ref2$seperator === void 0 ? ',' : _ref2$seperator;
82
+ var _ref2$separator = _ref2.separator,
83
+ separator = _ref2$separator === void 0 ? ',' : _ref2$separator,
84
+ _ref2$decimalSeparato = _ref2.decimalSeparator,
85
+ decimalSeparator = _ref2$decimalSeparato === void 0 ? '.' : _ref2$decimalSeparato;
81
86
  return {
82
87
  getValueFromEvent: function getValueFromEvent(e) {
83
88
  var value = e.target.value;
84
- var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
89
+ console.log('======', separator, decimalSeparator);
90
+ var str = value.replaceAll(separator, '').replaceAll(/[^0-9\.,]/g, '');
85
91
 
86
- if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
92
+ if (str.endsWith(decimalSeparator) || str.includes(decimalSeparator) && str.endsWith('0')) {
87
93
  return str;
88
94
  }
89
95
 
96
+ if (decimalSeparator === ',') {
97
+ str = str.replace(',', '.');
98
+ }
99
+
90
100
  return str ? parseFloat(str) : undefined;
91
101
  },
92
102
  rules: [{
93
103
  validator: function validator(_, value) {
94
104
  if (!value) return Promise.resolve();
95
- var seperatorArr = String(value).split('.');
96
- return seperatorArr.length > 2 ? Promise.reject(staticFormatMessage({
105
+ var separatorArr = String(value).split(decimalSeparator);
106
+ return separatorArr.length > 2 ? Promise.reject(staticFormatMessage({
97
107
  id: 'Please enter a valid amount.'
98
108
  })) : Promise.resolve();
99
109
  }
@@ -6,7 +6,9 @@ export interface AmountProps extends InputProps, IglooComponentProps {
6
6
  currencyProps?: InputProps;
7
7
  amount?: number;
8
8
  amountProps?: InputProps;
9
- seperator?: ',';
9
+ seperator?: ',' | '.';
10
+ separator?: ',' | '.';
11
+ decimalSeparator?: ',' | '.';
10
12
  }
11
13
  declare const Amount: FC<AmountProps>;
12
14
  export default Amount;
@@ -21,7 +21,7 @@ var _locale = require("../locale");
21
21
 
22
22
  require("./style/index.less");
23
23
 
24
- var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "disabled"];
24
+ var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "separator", "decimalSeparator", "disabled"];
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
@@ -35,16 +35,16 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
35
35
 
36
36
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
37
37
 
38
- var thousands = function thousands(number) {
38
+ var thousands = function thousands(number, decimalSeparator, separator) {
39
39
  if (number === null || number === undefined) return undefined;
40
- var arr = String(number).split('.');
40
+ var arr = String(number).replace('.', decimalSeparator).split(decimalSeparator);
41
41
  return arr.map(function (s, index) {
42
42
  if (index === 0) {
43
- return s.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
43
+ return s.replace(/(?=(?!\b)(\d{3})+$)/g, separator);
44
44
  }
45
45
 
46
- return s.replace(/(\d{3})(?=[^$])/g, '$1,');
47
- }).join('.');
46
+ return s.replace(/(\d{3})(?=[^$])/g, "$1".concat(separator));
47
+ }).join(decimalSeparator);
48
48
  };
49
49
 
50
50
  var Amount = function Amount(_ref) {
@@ -55,8 +55,11 @@ var Amount = function Amount(_ref) {
55
55
  _ref$amountProps = _ref.amountProps,
56
56
  amountProps = _ref$amountProps === void 0 ? {} : _ref$amountProps,
57
57
  value = _ref.value,
58
- _ref$seperator = _ref.seperator,
59
- seperator = _ref$seperator === void 0 ? ',' : _ref$seperator,
58
+ seperator = _ref.seperator,
59
+ _ref$separator = _ref.separator,
60
+ separator = _ref$separator === void 0 ? seperator || ',' : _ref$separator,
61
+ _ref$decimalSeparator = _ref.decimalSeparator,
62
+ decimalSeparator = _ref$decimalSeparator === void 0 ? '.' : _ref$decimalSeparator,
60
63
  disabled = _ref.disabled,
61
64
  rest = _objectWithoutProperties(_ref, _excluded);
62
65
 
@@ -64,11 +67,11 @@ var Amount = function Amount(_ref) {
64
67
  var onChange = rest.onChange;
65
68
 
66
69
  if (typeof value === 'string') {
67
- if (value.endsWith('.')) {
68
- e.target.value = value.replace('.', '');
70
+ if (value.endsWith(decimalSeparator)) {
71
+ e.target.value = value.replace(decimalSeparator, '');
69
72
  }
70
73
 
71
- if (value.endsWith('0') && value.includes('.')) {
74
+ if (value.endsWith('0') && value.includes(decimalSeparator)) {
72
75
  e.target.value = value.replace(/[0]+$/, '');
73
76
  }
74
77
 
@@ -83,7 +86,7 @@ var Amount = function Amount(_ref) {
83
86
  className: (0, _classnames.default)('igloo-input-amount', {
84
87
  'igloo-input-disable': disabled
85
88
  }, className),
86
- value: thousands(value),
89
+ value: thousands(value, decimalSeparator, separator),
87
90
  addonBefore: currency ? (0, _jsxRuntime.jsx)("span", {
88
91
  className: "igloo-input-areacode",
89
92
  children: currency
@@ -92,24 +95,31 @@ var Amount = function Amount(_ref) {
92
95
  };
93
96
 
94
97
  Amount.formItemPropsHandler = function (_ref2) {
95
- var _ref2$seperator = _ref2.seperator,
96
- seperator = _ref2$seperator === void 0 ? ',' : _ref2$seperator;
98
+ var _ref2$separator = _ref2.separator,
99
+ separator = _ref2$separator === void 0 ? ',' : _ref2$separator,
100
+ _ref2$decimalSeparato = _ref2.decimalSeparator,
101
+ decimalSeparator = _ref2$decimalSeparato === void 0 ? '.' : _ref2$decimalSeparato;
97
102
  return {
98
103
  getValueFromEvent: function getValueFromEvent(e) {
99
104
  var value = e.target.value;
100
- var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
105
+ console.log('======', separator, decimalSeparator);
106
+ var str = value.replaceAll(separator, '').replaceAll(/[^0-9\.,]/g, '');
101
107
 
102
- if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
108
+ if (str.endsWith(decimalSeparator) || str.includes(decimalSeparator) && str.endsWith('0')) {
103
109
  return str;
104
110
  }
105
111
 
112
+ if (decimalSeparator === ',') {
113
+ str = str.replace(',', '.');
114
+ }
115
+
106
116
  return str ? parseFloat(str) : undefined;
107
117
  },
108
118
  rules: [{
109
119
  validator: function validator(_, value) {
110
120
  if (!value) return Promise.resolve();
111
- var seperatorArr = String(value).split('.');
112
- return seperatorArr.length > 2 ? Promise.reject((0, _locale.staticFormatMessage)({
121
+ var separatorArr = String(value).split(decimalSeparator);
122
+ return separatorArr.length > 2 ? Promise.reject((0, _locale.staticFormatMessage)({
113
123
  id: 'Please enter a valid amount.'
114
124
  })) : Promise.resolve();
115
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.14",
3
+ "version": "2.5.15",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",