@commercetools-uikit/money-field 17.0.1 → 18.0.0
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.
package/README.md
CHANGED
|
@@ -63,7 +63,9 @@ export default Example;
|
|
|
63
63
|
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
64
64
|
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
65
65
|
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
66
|
+
| `warnings` | `Record` | | | A map of warnings. Warning messages for known warnings are rendered automatically.
<br/>
Unknown warnings will be forwarded to renderWarning. |
|
|
66
67
|
| `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error. |
|
|
68
|
+
| `renderWarning` | `Function`<br/>[See signature.](#signature-renderWarning) | | | Called with custom warnings, as renderWarning(key, warning). This function can return a message which will be wrapped in a WarningMessage.
<br />
It can also return null to show no warning. |
|
|
67
69
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
68
70
|
| `touched` | `Object`<br/>[See signature.](#signature-touched) | | | Indicates whether the `currencyCode` or `amount` fields were touched.
<br />
Errors will only be shown when the field was touched. |
|
|
69
71
|
| `isTouched` | `unknown` | | | |
|
|
@@ -96,6 +98,12 @@ export default Example;
|
|
|
96
98
|
(key: string, error?: boolean) => ReactNode;
|
|
97
99
|
```
|
|
98
100
|
|
|
101
|
+
### Signature `renderWarning`
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
(key: string, warning?: boolean) => ReactNode;
|
|
105
|
+
```
|
|
106
|
+
|
|
99
107
|
### Signature `touched`
|
|
100
108
|
|
|
101
109
|
```ts
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
6
|
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
7
7
|
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
8
|
-
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
9
8
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
10
9
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
10
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
11
11
|
var _pt = require('prop-types');
|
|
12
12
|
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
13
13
|
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
@@ -28,6 +28,7 @@ var Spacings = require('@commercetools-uikit/spacings');
|
|
|
28
28
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
29
29
|
var MoneyInput = require('@commercetools-uikit/money-input');
|
|
30
30
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
31
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
31
32
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
32
33
|
|
|
33
34
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -50,27 +51,32 @@ var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
|
50
51
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
51
52
|
var MoneyInput__default = /*#__PURE__*/_interopDefault(MoneyInput);
|
|
52
53
|
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
54
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
53
55
|
|
|
54
|
-
function ownKeys(
|
|
55
|
-
function _objectSpread(
|
|
56
|
-
function
|
|
57
|
-
function _isNativeReflectConstruct() {
|
|
56
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
57
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
58
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
59
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
58
60
|
const sequentialId = utils.createSequentialId('money-field-');
|
|
59
61
|
const sequentialErrorsId = utils.createSequentialId('money-field-error-')();
|
|
62
|
+
const sequentialWarningsId = utils.createSequentialId('money-field-warning-')();
|
|
60
63
|
const hasErrors = errors => {
|
|
61
64
|
var _context;
|
|
62
65
|
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
63
66
|
};
|
|
67
|
+
const hasWarnings = warnings => {
|
|
68
|
+
var _context2;
|
|
69
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
70
|
+
};
|
|
64
71
|
let MoneyField = /*#__PURE__*/function (_Component) {
|
|
65
72
|
_inherits(MoneyField, _Component);
|
|
66
|
-
var _super = _createSuper(MoneyField);
|
|
67
73
|
function MoneyField() {
|
|
68
74
|
var _this;
|
|
69
75
|
_classCallCheck(this, MoneyField);
|
|
70
76
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
71
77
|
args[_key] = arguments[_key];
|
|
72
78
|
}
|
|
73
|
-
_this =
|
|
79
|
+
_this = _callSuper(this, MoneyField, [...args]);
|
|
74
80
|
_this.state = {
|
|
75
81
|
// We generate an id in case no id is provided by the parent to attach the
|
|
76
82
|
// label to the input component.
|
|
@@ -85,6 +91,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
85
91
|
// This avoids showing an error when the user just selected a language but
|
|
86
92
|
// didn't add an amount yet.
|
|
87
93
|
const hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
94
|
+
const hasWarning = MoneyInput__default["default"].isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
88
95
|
if (!this.props.isReadOnly) {
|
|
89
96
|
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'MoneyField: `onChange` is required when field is not read only.') : void 0;
|
|
90
97
|
}
|
|
@@ -118,6 +125,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
118
125
|
isReadOnly: this.props.isReadOnly,
|
|
119
126
|
onChange: this.props.onChange,
|
|
120
127
|
hasError: hasError,
|
|
128
|
+
hasWarning: hasWarning,
|
|
121
129
|
hasHighPrecisionBadge: this.props.hasHighPrecisionBadge,
|
|
122
130
|
menuPortalTarget: this.props.menuPortalTarget,
|
|
123
131
|
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
@@ -130,6 +138,11 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
130
138
|
errors: this.props.errors,
|
|
131
139
|
isVisible: hasError,
|
|
132
140
|
renderError: this.props.renderError
|
|
141
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
142
|
+
id: sequentialWarningsId,
|
|
143
|
+
warnings: this.props.warnings,
|
|
144
|
+
isVisible: hasWarning,
|
|
145
|
+
renderWarning: this.props.renderWarning
|
|
133
146
|
})]
|
|
134
147
|
})
|
|
135
148
|
});
|
|
@@ -159,7 +172,9 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
159
172
|
id: _pt__default["default"].string,
|
|
160
173
|
horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
161
174
|
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
175
|
+
warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
162
176
|
renderError: _pt__default["default"].func,
|
|
177
|
+
renderWarning: _pt__default["default"].func,
|
|
163
178
|
isRequired: _pt__default["default"].bool,
|
|
164
179
|
touched: _pt__default["default"].shape({
|
|
165
180
|
amount: _pt__default["default"].bool,
|
|
@@ -184,14 +199,12 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
184
199
|
title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
|
|
185
200
|
hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
186
201
|
description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
187
|
-
onInfoButtonClick: _pt__default["default"].func
|
|
188
|
-
hintIcon: _pt__default["default"].element,
|
|
189
|
-
hasHighPrecisionBadge: _pt__default["default"].bool
|
|
202
|
+
onInfoButtonClick: _pt__default["default"].func
|
|
190
203
|
} : {};
|
|
191
204
|
var MoneyField$1 = MoneyField;
|
|
192
205
|
|
|
193
206
|
// NOTE: This string will be replaced on build time with the package version.
|
|
194
|
-
var version = "
|
|
207
|
+
var version = "18.0.0";
|
|
195
208
|
|
|
196
209
|
exports["default"] = MoneyField$1;
|
|
197
210
|
exports.version = version;
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
6
|
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
7
7
|
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
8
|
-
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
9
8
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
10
9
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
10
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
11
11
|
require('prop-types');
|
|
12
12
|
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
13
13
|
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
@@ -28,6 +28,7 @@ var Spacings = require('@commercetools-uikit/spacings');
|
|
|
28
28
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
29
29
|
var MoneyInput = require('@commercetools-uikit/money-input');
|
|
30
30
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
31
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
31
32
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
32
33
|
|
|
33
34
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -48,27 +49,32 @@ var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
|
48
49
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
49
50
|
var MoneyInput__default = /*#__PURE__*/_interopDefault(MoneyInput);
|
|
50
51
|
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
52
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
51
53
|
|
|
52
|
-
function ownKeys(
|
|
53
|
-
function _objectSpread(
|
|
54
|
-
function
|
|
55
|
-
function _isNativeReflectConstruct() {
|
|
54
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
55
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
56
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
57
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
56
58
|
const sequentialId = utils.createSequentialId('money-field-');
|
|
57
59
|
const sequentialErrorsId = utils.createSequentialId('money-field-error-')();
|
|
60
|
+
const sequentialWarningsId = utils.createSequentialId('money-field-warning-')();
|
|
58
61
|
const hasErrors = errors => {
|
|
59
62
|
var _context;
|
|
60
63
|
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
61
64
|
};
|
|
65
|
+
const hasWarnings = warnings => {
|
|
66
|
+
var _context2;
|
|
67
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
68
|
+
};
|
|
62
69
|
let MoneyField = /*#__PURE__*/function (_Component) {
|
|
63
70
|
_inherits(MoneyField, _Component);
|
|
64
|
-
var _super = _createSuper(MoneyField);
|
|
65
71
|
function MoneyField() {
|
|
66
72
|
var _this;
|
|
67
73
|
_classCallCheck(this, MoneyField);
|
|
68
74
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
69
75
|
args[_key] = arguments[_key];
|
|
70
76
|
}
|
|
71
|
-
_this =
|
|
77
|
+
_this = _callSuper(this, MoneyField, [...args]);
|
|
72
78
|
_this.state = {
|
|
73
79
|
// We generate an id in case no id is provided by the parent to attach the
|
|
74
80
|
// label to the input component.
|
|
@@ -83,6 +89,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
83
89
|
// This avoids showing an error when the user just selected a language but
|
|
84
90
|
// didn't add an amount yet.
|
|
85
91
|
const hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
92
|
+
const hasWarning = MoneyInput__default["default"].isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
86
93
|
if (!this.props.isReadOnly) ;
|
|
87
94
|
if (this.props.hintIcon) ;
|
|
88
95
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
@@ -111,6 +118,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
111
118
|
isReadOnly: this.props.isReadOnly,
|
|
112
119
|
onChange: this.props.onChange,
|
|
113
120
|
hasError: hasError,
|
|
121
|
+
hasWarning: hasWarning,
|
|
114
122
|
hasHighPrecisionBadge: this.props.hasHighPrecisionBadge,
|
|
115
123
|
menuPortalTarget: this.props.menuPortalTarget,
|
|
116
124
|
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
@@ -123,6 +131,11 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
123
131
|
errors: this.props.errors,
|
|
124
132
|
isVisible: hasError,
|
|
125
133
|
renderError: this.props.renderError
|
|
134
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
135
|
+
id: sequentialWarningsId,
|
|
136
|
+
warnings: this.props.warnings,
|
|
137
|
+
isVisible: hasWarning,
|
|
138
|
+
renderWarning: this.props.renderWarning
|
|
126
139
|
})]
|
|
127
140
|
})
|
|
128
141
|
});
|
|
@@ -152,7 +165,7 @@ MoneyField.propTypes = {};
|
|
|
152
165
|
var MoneyField$1 = MoneyField;
|
|
153
166
|
|
|
154
167
|
// NOTE: This string will be replaced on build time with the package version.
|
|
155
|
-
var version = "
|
|
168
|
+
var version = "18.0.0";
|
|
156
169
|
|
|
157
170
|
exports["default"] = MoneyField$1;
|
|
158
171
|
exports.version = version;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
2
2
|
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
3
3
|
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
4
|
-
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
5
4
|
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
6
5
|
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
6
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
7
7
|
import _pt from 'prop-types';
|
|
8
8
|
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
9
9
|
import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
|
|
@@ -24,28 +24,33 @@ import Spacings from '@commercetools-uikit/spacings';
|
|
|
24
24
|
import FieldLabel from '@commercetools-uikit/field-label';
|
|
25
25
|
import MoneyInput from '@commercetools-uikit/money-input';
|
|
26
26
|
import FieldErrors from '@commercetools-uikit/field-errors';
|
|
27
|
+
import FieldWarnings from '@commercetools-uikit/field-warnings';
|
|
27
28
|
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
28
29
|
|
|
29
|
-
function ownKeys(
|
|
30
|
-
function _objectSpread(
|
|
31
|
-
function
|
|
32
|
-
function _isNativeReflectConstruct() {
|
|
30
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
31
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
33
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
33
34
|
const sequentialId = createSequentialId('money-field-');
|
|
34
35
|
const sequentialErrorsId = createSequentialId('money-field-error-')();
|
|
36
|
+
const sequentialWarningsId = createSequentialId('money-field-warning-')();
|
|
35
37
|
const hasErrors = errors => {
|
|
36
38
|
var _context;
|
|
37
39
|
return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
|
|
38
40
|
};
|
|
41
|
+
const hasWarnings = warnings => {
|
|
42
|
+
var _context2;
|
|
43
|
+
return warnings && _someInstanceProperty(_context2 = _Object$values(warnings)).call(_context2, Boolean);
|
|
44
|
+
};
|
|
39
45
|
let MoneyField = /*#__PURE__*/function (_Component) {
|
|
40
46
|
_inherits(MoneyField, _Component);
|
|
41
|
-
var _super = _createSuper(MoneyField);
|
|
42
47
|
function MoneyField() {
|
|
43
48
|
var _this;
|
|
44
49
|
_classCallCheck(this, MoneyField);
|
|
45
50
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
46
51
|
args[_key] = arguments[_key];
|
|
47
52
|
}
|
|
48
|
-
_this =
|
|
53
|
+
_this = _callSuper(this, MoneyField, [...args]);
|
|
49
54
|
_this.state = {
|
|
50
55
|
// We generate an id in case no id is provided by the parent to attach the
|
|
51
56
|
// label to the input component.
|
|
@@ -60,6 +65,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
60
65
|
// This avoids showing an error when the user just selected a language but
|
|
61
66
|
// didn't add an amount yet.
|
|
62
67
|
const hasError = MoneyInput.isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
68
|
+
const hasWarning = MoneyInput.isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
63
69
|
if (!this.props.isReadOnly) {
|
|
64
70
|
process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'MoneyField: `onChange` is required when field is not read only.') : void 0;
|
|
65
71
|
}
|
|
@@ -93,6 +99,7 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
93
99
|
isReadOnly: this.props.isReadOnly,
|
|
94
100
|
onChange: this.props.onChange,
|
|
95
101
|
hasError: hasError,
|
|
102
|
+
hasWarning: hasWarning,
|
|
96
103
|
hasHighPrecisionBadge: this.props.hasHighPrecisionBadge,
|
|
97
104
|
menuPortalTarget: this.props.menuPortalTarget,
|
|
98
105
|
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
@@ -105,6 +112,11 @@ let MoneyField = /*#__PURE__*/function (_Component) {
|
|
|
105
112
|
errors: this.props.errors,
|
|
106
113
|
isVisible: hasError,
|
|
107
114
|
renderError: this.props.renderError
|
|
115
|
+
}), jsx(FieldWarnings, {
|
|
116
|
+
id: sequentialWarningsId,
|
|
117
|
+
warnings: this.props.warnings,
|
|
118
|
+
isVisible: hasWarning,
|
|
119
|
+
renderWarning: this.props.renderWarning
|
|
108
120
|
})]
|
|
109
121
|
})
|
|
110
122
|
});
|
|
@@ -134,7 +146,9 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
134
146
|
id: _pt.string,
|
|
135
147
|
horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
136
148
|
errors: _pt.objectOf(_pt.bool),
|
|
149
|
+
warnings: _pt.objectOf(_pt.bool),
|
|
137
150
|
renderError: _pt.func,
|
|
151
|
+
renderWarning: _pt.func,
|
|
138
152
|
isRequired: _pt.bool,
|
|
139
153
|
touched: _pt.shape({
|
|
140
154
|
amount: _pt.bool,
|
|
@@ -159,13 +173,11 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
159
173
|
title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
|
|
160
174
|
hint: _pt.oneOfType([_pt.string, _pt.node]),
|
|
161
175
|
description: _pt.oneOfType([_pt.string, _pt.node]),
|
|
162
|
-
onInfoButtonClick: _pt.func
|
|
163
|
-
hintIcon: _pt.element,
|
|
164
|
-
hasHighPrecisionBadge: _pt.bool
|
|
176
|
+
onInfoButtonClick: _pt.func
|
|
165
177
|
} : {};
|
|
166
178
|
var MoneyField$1 = MoneyField;
|
|
167
179
|
|
|
168
180
|
// NOTE: This string will be replaced on build time with the package version.
|
|
169
|
-
var version = "
|
|
181
|
+
var version = "18.0.0";
|
|
170
182
|
|
|
171
183
|
export { MoneyField$1 as default, version };
|
|
@@ -2,6 +2,7 @@ import { Component, type ReactElement, type ReactNode } from 'react';
|
|
|
2
2
|
import { type Props as ReactSelectProps } from 'react-select';
|
|
3
3
|
import { type TCurrencyCode } from '@commercetools-uikit/money-input';
|
|
4
4
|
type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
5
|
+
type TFieldWarnings = Record<string, boolean>;
|
|
5
6
|
type TFieldErrors = Record<string, boolean>;
|
|
6
7
|
type TCustomFormErrors<Values> = {
|
|
7
8
|
[K in keyof Values]?: TFieldErrors;
|
|
@@ -26,7 +27,9 @@ export type TMoneyFieldProps = {
|
|
|
26
27
|
id?: string;
|
|
27
28
|
horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
28
29
|
errors?: TFieldErrors;
|
|
30
|
+
warnings?: TFieldWarnings;
|
|
29
31
|
renderError?: TErrorRenderer;
|
|
32
|
+
renderWarning?: (key: string, warning?: boolean) => ReactNode;
|
|
30
33
|
isRequired?: boolean;
|
|
31
34
|
touched?: TTouched;
|
|
32
35
|
isTouched?: unknown;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/money-field",
|
|
3
3
|
"description": "A controlled input component for money values with validation states and a label.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "18.0.0",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/runtime": "^7.20.13",
|
|
23
23
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
24
|
-
"@commercetools-uikit/constraints": "
|
|
25
|
-
"@commercetools-uikit/design-system": "
|
|
26
|
-
"@commercetools-uikit/field-errors": "
|
|
27
|
-
"@commercetools-uikit/field-label": "
|
|
28
|
-
"@commercetools-uikit/
|
|
29
|
-
"@commercetools-uikit/
|
|
30
|
-
"@commercetools-uikit/
|
|
24
|
+
"@commercetools-uikit/constraints": "18.0.0",
|
|
25
|
+
"@commercetools-uikit/design-system": "18.0.0",
|
|
26
|
+
"@commercetools-uikit/field-errors": "18.0.0",
|
|
27
|
+
"@commercetools-uikit/field-label": "18.0.0",
|
|
28
|
+
"@commercetools-uikit/field-warnings": "18.0.0",
|
|
29
|
+
"@commercetools-uikit/money-input": "18.0.0",
|
|
30
|
+
"@commercetools-uikit/spacings": "18.0.0",
|
|
31
|
+
"@commercetools-uikit/utils": "18.0.0",
|
|
31
32
|
"@emotion/react": "^11.10.5",
|
|
32
33
|
"@emotion/styled": "^11.10.5",
|
|
33
34
|
"lodash": "4.17.21",
|