@commercetools-uikit/localized-text-field 17.0.1 → 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-localized-text-field.cjs.dev.js +24 -11
- package/dist/commercetools-uikit-localized-text-field.cjs.prod.js +21 -8
- package/dist/commercetools-uikit-localized-text-field.esm.js +23 -11
- package/dist/declarations/src/localized-text-field.d.ts +3 -0
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ export default Example;
|
|
|
55
55
|
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
56
56
|
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
57
57
|
| `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. |
|
|
58
|
+
| `warnings` | `Record` | | | A map of warnings. Warning messages for known warnings are rendered automatically.
<br/>
Unknown warnings will be forwarded to renderWarning. |
|
|
59
|
+
| `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. |
|
|
58
60
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
59
61
|
| `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
60
62
|
| `autoComplete` | `string` | | | Used as HTML `autocomplete` of the input component. property |
|
|
@@ -86,6 +88,12 @@ export default Example;
|
|
|
86
88
|
(key: string, error?: boolean) => ReactNode;
|
|
87
89
|
```
|
|
88
90
|
|
|
91
|
+
### Signature `renderWarning`
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
(key: string, warning?: boolean) => ReactNode;
|
|
95
|
+
```
|
|
96
|
+
|
|
89
97
|
### Signature `onInfoButtonClick`
|
|
90
98
|
|
|
91
99
|
```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');
|
|
@@ -27,6 +27,7 @@ var Spacings = require('@commercetools-uikit/spacings');
|
|
|
27
27
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
28
28
|
var LocalizedTextInput = require('@commercetools-uikit/localized-text-input');
|
|
29
29
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
30
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
30
31
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
31
32
|
|
|
32
33
|
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 LocalizedTextInput__default = /*#__PURE__*/_interopDefault(LocalizedTextInput);
|
|
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('localized-text-field-');
|
|
57
59
|
const sequentialErrorsId = utils.createSequentialId('localized-text-field-error-')();
|
|
60
|
+
const sequentialWarningsId = utils.createSequentialId('localized-text-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 LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
63
70
|
_inherits(LocalizedTextField, _Component);
|
|
64
|
-
var _super = _createSuper(LocalizedTextField);
|
|
65
71
|
function LocalizedTextField() {
|
|
66
72
|
var _this;
|
|
67
73
|
_classCallCheck(this, LocalizedTextField);
|
|
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, LocalizedTextField, [...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.
|
|
@@ -80,6 +86,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
80
86
|
key: "render",
|
|
81
87
|
value: function render() {
|
|
82
88
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
89
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
83
90
|
if (this.props.hintIcon) {
|
|
84
91
|
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(this.props.hint), 'LocalizedTextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
85
92
|
}
|
|
@@ -115,6 +122,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
115
122
|
isReadOnly: this.props.isReadOnly,
|
|
116
123
|
errors: this.props.errorsByLanguage,
|
|
117
124
|
hasError: hasError,
|
|
125
|
+
hasWarning: hasWarning,
|
|
118
126
|
placeholder: this.props.placeholder,
|
|
119
127
|
horizontalConstraint: "scale"
|
|
120
128
|
}, utils.filterDataAttributes(this.props)), {}, {
|
|
@@ -125,6 +133,11 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
125
133
|
errors: this.props.errors,
|
|
126
134
|
isVisible: hasError,
|
|
127
135
|
renderError: this.props.renderError
|
|
136
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
137
|
+
id: sequentialWarningsId,
|
|
138
|
+
warnings: this.props.warnings,
|
|
139
|
+
isVisible: hasWarning,
|
|
140
|
+
renderWarning: this.props.renderWarning
|
|
128
141
|
})]
|
|
129
142
|
})
|
|
130
143
|
});
|
|
@@ -155,6 +168,8 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
155
168
|
horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
156
169
|
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
157
170
|
renderError: _pt__default["default"].func,
|
|
171
|
+
warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
172
|
+
renderWarning: _pt__default["default"].func,
|
|
158
173
|
isRequired: _pt__default["default"].bool,
|
|
159
174
|
touched: _pt__default["default"].bool,
|
|
160
175
|
autoComplete: _pt__default["default"].string,
|
|
@@ -173,14 +188,12 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
173
188
|
errorsByLanguage: _pt__default["default"].objectOf(_pt__default["default"].string),
|
|
174
189
|
title: _pt__default["default"].node.isRequired,
|
|
175
190
|
hint: _pt__default["default"].node,
|
|
176
|
-
description: _pt__default["default"].node
|
|
177
|
-
onInfoButtonClick: _pt__default["default"].func,
|
|
178
|
-
hintIcon: _pt__default["default"].element
|
|
191
|
+
description: _pt__default["default"].node
|
|
179
192
|
} : {};
|
|
180
193
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
181
194
|
|
|
182
195
|
// NOTE: This string will be replaced on build time with the package version.
|
|
183
|
-
var version = "17.0
|
|
196
|
+
var version = "17.1.0";
|
|
184
197
|
|
|
185
198
|
exports["default"] = LocalizedTextField$1;
|
|
186
199
|
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');
|
|
@@ -27,6 +27,7 @@ var Spacings = require('@commercetools-uikit/spacings');
|
|
|
27
27
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
28
28
|
var LocalizedTextInput = require('@commercetools-uikit/localized-text-input');
|
|
29
29
|
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
30
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
30
31
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
31
32
|
|
|
32
33
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -47,27 +48,32 @@ var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
|
47
48
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
48
49
|
var LocalizedTextInput__default = /*#__PURE__*/_interopDefault(LocalizedTextInput);
|
|
49
50
|
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
51
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
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('localized-text-field-');
|
|
56
58
|
const sequentialErrorsId = utils.createSequentialId('localized-text-field-error-')();
|
|
59
|
+
const sequentialWarningsId = utils.createSequentialId('localized-text-field-warning-')();
|
|
57
60
|
const hasErrors = errors => {
|
|
58
61
|
var _context;
|
|
59
62
|
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
60
63
|
};
|
|
64
|
+
const hasWarnings = warnings => {
|
|
65
|
+
var _context2;
|
|
66
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
67
|
+
};
|
|
61
68
|
let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
62
69
|
_inherits(LocalizedTextField, _Component);
|
|
63
|
-
var _super = _createSuper(LocalizedTextField);
|
|
64
70
|
function LocalizedTextField() {
|
|
65
71
|
var _this;
|
|
66
72
|
_classCallCheck(this, LocalizedTextField);
|
|
67
73
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
68
74
|
args[_key] = arguments[_key];
|
|
69
75
|
}
|
|
70
|
-
_this =
|
|
76
|
+
_this = _callSuper(this, LocalizedTextField, [...args]);
|
|
71
77
|
_this.state = {
|
|
72
78
|
// We generate an id in case no id is provided by the parent to attach the
|
|
73
79
|
// label to the input component.
|
|
@@ -79,6 +85,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
79
85
|
key: "render",
|
|
80
86
|
value: function render() {
|
|
81
87
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
88
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
82
89
|
if (this.props.hintIcon) ;
|
|
83
90
|
if (this.props.hideLanguageExpansionControls) ;
|
|
84
91
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
@@ -110,6 +117,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
110
117
|
isReadOnly: this.props.isReadOnly,
|
|
111
118
|
errors: this.props.errorsByLanguage,
|
|
112
119
|
hasError: hasError,
|
|
120
|
+
hasWarning: hasWarning,
|
|
113
121
|
placeholder: this.props.placeholder,
|
|
114
122
|
horizontalConstraint: "scale"
|
|
115
123
|
}, utils.filterDataAttributes(this.props)), {}, {
|
|
@@ -120,6 +128,11 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
120
128
|
errors: this.props.errors,
|
|
121
129
|
isVisible: hasError,
|
|
122
130
|
renderError: this.props.renderError
|
|
131
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
132
|
+
id: sequentialWarningsId,
|
|
133
|
+
warnings: this.props.warnings,
|
|
134
|
+
isVisible: hasWarning,
|
|
135
|
+
renderWarning: this.props.renderWarning
|
|
123
136
|
})]
|
|
124
137
|
})
|
|
125
138
|
});
|
|
@@ -149,7 +162,7 @@ LocalizedTextField.propTypes = {};
|
|
|
149
162
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
150
163
|
|
|
151
164
|
// NOTE: This string will be replaced on build time with the package version.
|
|
152
|
-
var version = "17.0
|
|
165
|
+
var version = "17.1.0";
|
|
153
166
|
|
|
154
167
|
exports["default"] = LocalizedTextField$1;
|
|
155
168
|
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';
|
|
@@ -23,28 +23,33 @@ import Spacings from '@commercetools-uikit/spacings';
|
|
|
23
23
|
import FieldLabel from '@commercetools-uikit/field-label';
|
|
24
24
|
import LocalizedTextInput from '@commercetools-uikit/localized-text-input';
|
|
25
25
|
import FieldErrors from '@commercetools-uikit/field-errors';
|
|
26
|
+
import FieldWarnings from '@commercetools-uikit/field-warnings';
|
|
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('localized-text-field-');
|
|
33
34
|
const sequentialErrorsId = createSequentialId('localized-text-field-error-')();
|
|
35
|
+
const sequentialWarningsId = createSequentialId('localized-text-field-warning-')();
|
|
34
36
|
const hasErrors = errors => {
|
|
35
37
|
var _context;
|
|
36
38
|
return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
|
|
37
39
|
};
|
|
40
|
+
const hasWarnings = warnings => {
|
|
41
|
+
var _context2;
|
|
42
|
+
return warnings && _someInstanceProperty(_context2 = _Object$values(warnings)).call(_context2, Boolean);
|
|
43
|
+
};
|
|
38
44
|
let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
39
45
|
_inherits(LocalizedTextField, _Component);
|
|
40
|
-
var _super = _createSuper(LocalizedTextField);
|
|
41
46
|
function LocalizedTextField() {
|
|
42
47
|
var _this;
|
|
43
48
|
_classCallCheck(this, LocalizedTextField);
|
|
44
49
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
50
|
args[_key] = arguments[_key];
|
|
46
51
|
}
|
|
47
|
-
_this =
|
|
52
|
+
_this = _callSuper(this, LocalizedTextField, [...args]);
|
|
48
53
|
_this.state = {
|
|
49
54
|
// We generate an id in case no id is provided by the parent to attach the
|
|
50
55
|
// label to the input component.
|
|
@@ -56,6 +61,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
56
61
|
key: "render",
|
|
57
62
|
value: function render() {
|
|
58
63
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
64
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
59
65
|
if (this.props.hintIcon) {
|
|
60
66
|
process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(this.props.hint), 'LocalizedTextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
61
67
|
}
|
|
@@ -91,6 +97,7 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
91
97
|
isReadOnly: this.props.isReadOnly,
|
|
92
98
|
errors: this.props.errorsByLanguage,
|
|
93
99
|
hasError: hasError,
|
|
100
|
+
hasWarning: hasWarning,
|
|
94
101
|
placeholder: this.props.placeholder,
|
|
95
102
|
horizontalConstraint: "scale"
|
|
96
103
|
}, filterDataAttributes(this.props)), {}, {
|
|
@@ -101,6 +108,11 @@ let LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
|
101
108
|
errors: this.props.errors,
|
|
102
109
|
isVisible: hasError,
|
|
103
110
|
renderError: this.props.renderError
|
|
111
|
+
}), jsx(FieldWarnings, {
|
|
112
|
+
id: sequentialWarningsId,
|
|
113
|
+
warnings: this.props.warnings,
|
|
114
|
+
isVisible: hasWarning,
|
|
115
|
+
renderWarning: this.props.renderWarning
|
|
104
116
|
})]
|
|
105
117
|
})
|
|
106
118
|
});
|
|
@@ -131,6 +143,8 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
131
143
|
horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
132
144
|
errors: _pt.objectOf(_pt.bool),
|
|
133
145
|
renderError: _pt.func,
|
|
146
|
+
warnings: _pt.objectOf(_pt.bool),
|
|
147
|
+
renderWarning: _pt.func,
|
|
134
148
|
isRequired: _pt.bool,
|
|
135
149
|
touched: _pt.bool,
|
|
136
150
|
autoComplete: _pt.string,
|
|
@@ -149,13 +163,11 @@ LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
149
163
|
errorsByLanguage: _pt.objectOf(_pt.string),
|
|
150
164
|
title: _pt.node.isRequired,
|
|
151
165
|
hint: _pt.node,
|
|
152
|
-
description: _pt.node
|
|
153
|
-
onInfoButtonClick: _pt.func,
|
|
154
|
-
hintIcon: _pt.element
|
|
166
|
+
description: _pt.node
|
|
155
167
|
} : {};
|
|
156
168
|
var LocalizedTextField$1 = LocalizedTextField;
|
|
157
169
|
|
|
158
170
|
// NOTE: This string will be replaced on build time with the package version.
|
|
159
|
-
var version = "17.0
|
|
171
|
+
var version = "17.1.0";
|
|
160
172
|
|
|
161
173
|
export { LocalizedTextField$1 as default, version };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, type ChangeEventHandler, type FocusEventHandler, type KeyboardEvent, type MouseEvent, type ReactElement, type ReactNode } 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;
|
|
@@ -12,6 +13,8 @@ export type TLocalizedTextFieldProps = {
|
|
|
12
13
|
horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
13
14
|
errors?: TFieldErrors;
|
|
14
15
|
renderError?: TErrorRenderer;
|
|
16
|
+
warnings?: TFieldWarnings;
|
|
17
|
+
renderWarning?: (key: string, warning?: boolean) => ReactNode;
|
|
15
18
|
isRequired?: boolean;
|
|
16
19
|
touched?: boolean;
|
|
17
20
|
autoComplete?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/localized-text-field",
|
|
3
3
|
"description": "A controlled text input component for localized single-line strings with validation states.",
|
|
4
|
-
"version": "17.0
|
|
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.0
|
|
25
|
-
"@commercetools-uikit/design-system": "17.0
|
|
26
|
-
"@commercetools-uikit/field-errors": "17.0
|
|
27
|
-
"@commercetools-uikit/field-label": "17.0
|
|
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/localized-text-input": "17.1.0",
|
|
30
|
+
"@commercetools-uikit/spacings": "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",
|