@commercetools-uikit/number-field 17.0.0 → 17.1.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 +8 -0
- package/dist/commercetools-uikit-number-field.cjs.d.ts +1 -1
- package/dist/commercetools-uikit-number-field.cjs.dev.js +24 -11
- package/dist/commercetools-uikit-number-field.cjs.prod.js +21 -8
- package/dist/commercetools-uikit-number-field.esm.js +23 -11
- package/dist/declarations/src/number-field.d.ts +3 -0
- package/package.json +9 -8
- package/dist/commercetools-uikit-number-field.cjs.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -50,7 +50,9 @@ export default Example;
|
|
|
50
50
|
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
51
51
|
| `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. |
|
|
52
52
|
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
53
|
+
| `warnings` | `Record` | | | A map of warnings. Warning messages for known warnings are rendered automatically.
<br/>
Unknown warnings will be forwarded to renderWarning. |
|
|
53
54
|
| `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. |
|
|
55
|
+
| `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. |
|
|
54
56
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
55
57
|
| `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
56
58
|
| `name` | `string` | | | Used as HTML name of the input component. property |
|
|
@@ -81,6 +83,12 @@ export default Example;
|
|
|
81
83
|
(key: string, error?: boolean) => ReactNode;
|
|
82
84
|
```
|
|
83
85
|
|
|
86
|
+
### Signature `renderWarning`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
(key: string, warning?: boolean) => ReactNode;
|
|
90
|
+
```
|
|
91
|
+
|
|
84
92
|
### Signature `onInfoButtonClick`
|
|
85
93
|
|
|
86
94
|
```ts
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
2
|
export { default } from "./declarations/src/index";
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1udW1iZXItZmllbGQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -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');
|
|
@@ -26,6 +26,7 @@ var Constraints = require('@commercetools-uikit/constraints');
|
|
|
26
26
|
var Stack = require('@commercetools-uikit/spacings-stack');
|
|
27
27
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
28
28
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
29
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
29
30
|
var NumberInput = require('@commercetools-uikit/number-input');
|
|
30
31
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
31
32
|
|
|
@@ -47,14 +48,16 @@ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
|
47
48
|
var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
48
49
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
49
50
|
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
51
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
50
52
|
var NumberInput__default = /*#__PURE__*/_interopDefault(NumberInput);
|
|
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('number-field-');
|
|
57
59
|
const sequentialErrorsId = utils.createSequentialId('number-field-error-')();
|
|
60
|
+
const sequentialWarningsId = utils.createSequentialId('number-field-warning-')();
|
|
58
61
|
|
|
59
62
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
60
63
|
|
|
@@ -62,16 +65,19 @@ const hasErrors = errors => {
|
|
|
62
65
|
var _context;
|
|
63
66
|
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
64
67
|
};
|
|
68
|
+
const hasWarnings = warnings => {
|
|
69
|
+
var _context2;
|
|
70
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
71
|
+
};
|
|
65
72
|
let NumberField = /*#__PURE__*/function (_Component) {
|
|
66
73
|
_inherits(NumberField, _Component);
|
|
67
|
-
var _super = _createSuper(NumberField);
|
|
68
74
|
function NumberField() {
|
|
69
75
|
var _this;
|
|
70
76
|
_classCallCheck(this, NumberField);
|
|
71
77
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
72
78
|
args[_key] = arguments[_key];
|
|
73
79
|
}
|
|
74
|
-
_this =
|
|
80
|
+
_this = _callSuper(this, NumberField, [...args]);
|
|
75
81
|
_this.state = {
|
|
76
82
|
// We generate an id in case no id is provided by the parent to attach the
|
|
77
83
|
// label to the input component.
|
|
@@ -89,6 +95,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
89
95
|
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(this.props.hint), 'NumberField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
90
96
|
}
|
|
91
97
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
98
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
92
99
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
93
100
|
max: this.props.horizontalConstraint,
|
|
94
101
|
children: jsxRuntime.jsxs(Stack__default["default"], {
|
|
@@ -114,6 +121,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
114
121
|
isDisabled: this.props.isDisabled,
|
|
115
122
|
isReadOnly: this.props.isReadOnly,
|
|
116
123
|
hasError: hasError,
|
|
124
|
+
hasWarning: hasWarning,
|
|
117
125
|
placeholder: this.props.placeholder,
|
|
118
126
|
horizontalConstraint: "scale",
|
|
119
127
|
min: this.props.min,
|
|
@@ -128,6 +136,11 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
128
136
|
errors: this.props.errors,
|
|
129
137
|
isVisible: hasError,
|
|
130
138
|
renderError: this.props.renderError
|
|
139
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
140
|
+
id: sequentialWarningsId,
|
|
141
|
+
warnings: this.props.warnings,
|
|
142
|
+
isVisible: hasWarning,
|
|
143
|
+
renderWarning: this.props.renderWarning
|
|
131
144
|
})]
|
|
132
145
|
})
|
|
133
146
|
});
|
|
@@ -157,7 +170,9 @@ NumberField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
157
170
|
id: _pt__default["default"].string,
|
|
158
171
|
horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
159
172
|
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
173
|
+
warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
160
174
|
renderError: _pt__default["default"].func,
|
|
175
|
+
renderWarning: _pt__default["default"].func,
|
|
161
176
|
isRequired: _pt__default["default"].bool,
|
|
162
177
|
touched: _pt__default["default"].bool,
|
|
163
178
|
name: _pt__default["default"].string,
|
|
@@ -176,14 +191,12 @@ NumberField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
176
191
|
title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
|
|
177
192
|
hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
178
193
|
description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
179
|
-
onInfoButtonClick: _pt__default["default"].func
|
|
180
|
-
hintIcon: _pt__default["default"].element,
|
|
181
|
-
badge: _pt__default["default"].node
|
|
194
|
+
onInfoButtonClick: _pt__default["default"].func
|
|
182
195
|
} : {};
|
|
183
196
|
var NumberField$1 = NumberField;
|
|
184
197
|
|
|
185
198
|
// NOTE: This string will be replaced on build time with the package version.
|
|
186
|
-
var version = "17.
|
|
199
|
+
var version = "17.1.0";
|
|
187
200
|
|
|
188
201
|
exports["default"] = NumberField$1;
|
|
189
202
|
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');
|
|
@@ -26,6 +26,7 @@ var Constraints = require('@commercetools-uikit/constraints');
|
|
|
26
26
|
var Stack = require('@commercetools-uikit/spacings-stack');
|
|
27
27
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
28
28
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
29
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
29
30
|
var NumberInput = require('@commercetools-uikit/number-input');
|
|
30
31
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
31
32
|
|
|
@@ -46,14 +47,16 @@ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
|
46
47
|
var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
47
48
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
48
49
|
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
50
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
49
51
|
var NumberInput__default = /*#__PURE__*/_interopDefault(NumberInput);
|
|
50
52
|
|
|
51
|
-
function ownKeys(
|
|
52
|
-
function _objectSpread(
|
|
53
|
-
function
|
|
54
|
-
function _isNativeReflectConstruct() {
|
|
53
|
+
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; }
|
|
54
|
+
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; }
|
|
55
|
+
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)); }
|
|
56
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
55
57
|
const sequentialId = utils.createSequentialId('number-field-');
|
|
56
58
|
const sequentialErrorsId = utils.createSequentialId('number-field-error-')();
|
|
59
|
+
const sequentialWarningsId = utils.createSequentialId('number-field-warning-')();
|
|
57
60
|
|
|
58
61
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
59
62
|
|
|
@@ -61,16 +64,19 @@ 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 NumberField = /*#__PURE__*/function (_Component) {
|
|
65
72
|
_inherits(NumberField, _Component);
|
|
66
|
-
var _super = _createSuper(NumberField);
|
|
67
73
|
function NumberField() {
|
|
68
74
|
var _this;
|
|
69
75
|
_classCallCheck(this, NumberField);
|
|
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, NumberField, [...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.
|
|
@@ -84,6 +90,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
84
90
|
if (!this.props.isReadOnly) ;
|
|
85
91
|
if (this.props.hintIcon) ;
|
|
86
92
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
93
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
87
94
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
88
95
|
max: this.props.horizontalConstraint,
|
|
89
96
|
children: jsxRuntime.jsxs(Stack__default["default"], {
|
|
@@ -109,6 +116,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
109
116
|
isDisabled: this.props.isDisabled,
|
|
110
117
|
isReadOnly: this.props.isReadOnly,
|
|
111
118
|
hasError: hasError,
|
|
119
|
+
hasWarning: hasWarning,
|
|
112
120
|
placeholder: this.props.placeholder,
|
|
113
121
|
horizontalConstraint: "scale",
|
|
114
122
|
min: this.props.min,
|
|
@@ -123,6 +131,11 @@ let NumberField = /*#__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 @@ NumberField.propTypes = {};
|
|
|
152
165
|
var NumberField$1 = NumberField;
|
|
153
166
|
|
|
154
167
|
// NOTE: This string will be replaced on build time with the package version.
|
|
155
|
-
var version = "17.
|
|
168
|
+
var version = "17.1.0";
|
|
156
169
|
|
|
157
170
|
exports["default"] = NumberField$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';
|
|
@@ -22,15 +22,17 @@ import Constraints from '@commercetools-uikit/constraints';
|
|
|
22
22
|
import Stack from '@commercetools-uikit/spacings-stack';
|
|
23
23
|
import FieldLabel from '@commercetools-uikit/field-label';
|
|
24
24
|
import FieldErrors from '@commercetools-uikit/field-errors';
|
|
25
|
+
import FieldWarnings from '@commercetools-uikit/field-warnings';
|
|
25
26
|
import NumberInput from '@commercetools-uikit/number-input';
|
|
26
27
|
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
27
28
|
|
|
28
|
-
function ownKeys(
|
|
29
|
-
function _objectSpread(
|
|
30
|
-
function
|
|
31
|
-
function _isNativeReflectConstruct() {
|
|
29
|
+
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; }
|
|
30
|
+
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; }
|
|
31
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
32
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
32
33
|
const sequentialId = createSequentialId('number-field-');
|
|
33
34
|
const sequentialErrorsId = createSequentialId('number-field-error-')();
|
|
35
|
+
const sequentialWarningsId = createSequentialId('number-field-warning-')();
|
|
34
36
|
|
|
35
37
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
36
38
|
|
|
@@ -38,16 +40,19 @@ const hasErrors = errors => {
|
|
|
38
40
|
var _context;
|
|
39
41
|
return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
|
|
40
42
|
};
|
|
43
|
+
const hasWarnings = warnings => {
|
|
44
|
+
var _context2;
|
|
45
|
+
return warnings && _someInstanceProperty(_context2 = _Object$values(warnings)).call(_context2, Boolean);
|
|
46
|
+
};
|
|
41
47
|
let NumberField = /*#__PURE__*/function (_Component) {
|
|
42
48
|
_inherits(NumberField, _Component);
|
|
43
|
-
var _super = _createSuper(NumberField);
|
|
44
49
|
function NumberField() {
|
|
45
50
|
var _this;
|
|
46
51
|
_classCallCheck(this, NumberField);
|
|
47
52
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
48
53
|
args[_key] = arguments[_key];
|
|
49
54
|
}
|
|
50
|
-
_this =
|
|
55
|
+
_this = _callSuper(this, NumberField, [...args]);
|
|
51
56
|
_this.state = {
|
|
52
57
|
// We generate an id in case no id is provided by the parent to attach the
|
|
53
58
|
// label to the input component.
|
|
@@ -65,6 +70,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
65
70
|
process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(this.props.hint), 'NumberField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
66
71
|
}
|
|
67
72
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
73
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
68
74
|
return jsx(Constraints.Horizontal, {
|
|
69
75
|
max: this.props.horizontalConstraint,
|
|
70
76
|
children: jsxs(Stack, {
|
|
@@ -90,6 +96,7 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
90
96
|
isDisabled: this.props.isDisabled,
|
|
91
97
|
isReadOnly: this.props.isReadOnly,
|
|
92
98
|
hasError: hasError,
|
|
99
|
+
hasWarning: hasWarning,
|
|
93
100
|
placeholder: this.props.placeholder,
|
|
94
101
|
horizontalConstraint: "scale",
|
|
95
102
|
min: this.props.min,
|
|
@@ -104,6 +111,11 @@ let NumberField = /*#__PURE__*/function (_Component) {
|
|
|
104
111
|
errors: this.props.errors,
|
|
105
112
|
isVisible: hasError,
|
|
106
113
|
renderError: this.props.renderError
|
|
114
|
+
}), jsx(FieldWarnings, {
|
|
115
|
+
id: sequentialWarningsId,
|
|
116
|
+
warnings: this.props.warnings,
|
|
117
|
+
isVisible: hasWarning,
|
|
118
|
+
renderWarning: this.props.renderWarning
|
|
107
119
|
})]
|
|
108
120
|
})
|
|
109
121
|
});
|
|
@@ -133,7 +145,9 @@ NumberField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
133
145
|
id: _pt.string,
|
|
134
146
|
horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
135
147
|
errors: _pt.objectOf(_pt.bool),
|
|
148
|
+
warnings: _pt.objectOf(_pt.bool),
|
|
136
149
|
renderError: _pt.func,
|
|
150
|
+
renderWarning: _pt.func,
|
|
137
151
|
isRequired: _pt.bool,
|
|
138
152
|
touched: _pt.bool,
|
|
139
153
|
name: _pt.string,
|
|
@@ -152,13 +166,11 @@ NumberField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
152
166
|
title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
|
|
153
167
|
hint: _pt.oneOfType([_pt.string, _pt.node]),
|
|
154
168
|
description: _pt.oneOfType([_pt.string, _pt.node]),
|
|
155
|
-
onInfoButtonClick: _pt.func
|
|
156
|
-
hintIcon: _pt.element,
|
|
157
|
-
badge: _pt.node
|
|
169
|
+
onInfoButtonClick: _pt.func
|
|
158
170
|
} : {};
|
|
159
171
|
var NumberField$1 = NumberField;
|
|
160
172
|
|
|
161
173
|
// NOTE: This string will be replaced on build time with the package version.
|
|
162
|
-
var version = "17.
|
|
174
|
+
var version = "17.1.0";
|
|
163
175
|
|
|
164
176
|
export { NumberField$1 as default, version };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, type ChangeEventHandler, type FocusEventHandler, type ReactElement, type ReactNode, type MouseEvent, type KeyboardEvent } from 'react';
|
|
2
2
|
type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
3
|
+
type TFieldWarnings = Record<string, boolean>;
|
|
3
4
|
type TFieldErrors = Record<string, boolean>;
|
|
4
5
|
type TCustomFormErrors<Values> = {
|
|
5
6
|
[K in keyof Values]?: TFieldErrors;
|
|
@@ -8,7 +9,9 @@ export type TNumberFieldProps = {
|
|
|
8
9
|
id?: string;
|
|
9
10
|
horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
10
11
|
errors?: TFieldErrors;
|
|
12
|
+
warnings?: TFieldWarnings;
|
|
11
13
|
renderError?: TErrorRenderer;
|
|
14
|
+
renderWarning?: (key: string, warning?: boolean) => ReactNode;
|
|
12
15
|
isRequired?: boolean;
|
|
13
16
|
touched?: boolean;
|
|
14
17
|
name?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/number-field",
|
|
3
3
|
"description": "A controlled input component for numbers with validation states and a label.",
|
|
4
|
-
"version": "17.
|
|
4
|
+
"version": "17.1.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": "17.
|
|
25
|
-
"@commercetools-uikit/design-system": "17.
|
|
26
|
-
"@commercetools-uikit/field-errors": "17.
|
|
27
|
-
"@commercetools-uikit/field-label": "17.
|
|
28
|
-
"@commercetools-uikit/
|
|
29
|
-
"@commercetools-uikit/
|
|
30
|
-
"@commercetools-uikit/
|
|
24
|
+
"@commercetools-uikit/constraints": "17.1.0",
|
|
25
|
+
"@commercetools-uikit/design-system": "17.1.0",
|
|
26
|
+
"@commercetools-uikit/field-errors": "17.1.0",
|
|
27
|
+
"@commercetools-uikit/field-label": "17.1.0",
|
|
28
|
+
"@commercetools-uikit/field-warnings": "17.1.0",
|
|
29
|
+
"@commercetools-uikit/number-input": "17.1.0",
|
|
30
|
+
"@commercetools-uikit/spacings-stack": "17.1.0",
|
|
31
|
+
"@commercetools-uikit/utils": "17.1.0",
|
|
31
32
|
"@emotion/react": "^11.10.5",
|
|
32
33
|
"@emotion/styled": "^11.10.5",
|
|
33
34
|
"prop-types": "15.8.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commercetools-uikit-number-field.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|