@commercetools-uikit/text-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-text-field.cjs.d.ts +1 -1
- package/dist/commercetools-uikit-text-field.cjs.dev.js +23 -8
- package/dist/commercetools-uikit-text-field.cjs.prod.js +21 -8
- package/dist/commercetools-uikit-text-field.esm.js +22 -8
- package/dist/declarations/src/text-field.d.ts +3 -0
- package/package.json +9 -8
- package/dist/commercetools-uikit-text-field.cjs.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -46,7 +46,9 @@ export default Example;
|
|
|
46
46
|
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
47
47
|
| `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. |
|
|
48
48
|
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br/>
Unknown errors will be forwarded to renderError. |
|
|
49
|
+
| `warnings` | `Record` | | | A map of warnings. Warning messages for known warnings are rendered automatically.
<br/>
Unknown warnings will be forwarded to renderWarning. |
|
|
49
50
|
| `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error. |
|
|
51
|
+
| `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. |
|
|
50
52
|
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
51
53
|
| `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
52
54
|
| `autoComplete` | `string` | | | Used as HTML autocomplete property |
|
|
@@ -74,6 +76,12 @@ export default Example;
|
|
|
74
76
|
(key: string, error?: boolean) => ReactNode;
|
|
75
77
|
```
|
|
76
78
|
|
|
79
|
+
### Signature `renderWarning`
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
(key: string, warning?: boolean) => ReactNode;
|
|
83
|
+
```
|
|
84
|
+
|
|
77
85
|
### Signature `onInfoButtonClick`
|
|
78
86
|
|
|
79
87
|
```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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC10ZXh0LWZpZWxkLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -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 FieldLabel = require('@commercetools-uikit/field-label');
|
|
|
27
27
|
var TextInput = require('@commercetools-uikit/text-input');
|
|
28
28
|
var utils = require('@commercetools-uikit/utils');
|
|
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,29 +49,34 @@ var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
|
48
49
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
49
50
|
var TextInput__default = /*#__PURE__*/_interopDefault(TextInput);
|
|
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('text-field-');
|
|
57
59
|
const sequentialErrorsId = utils.createSequentialId('text-field-error-')();
|
|
60
|
+
const sequentialWarningsId = utils.createSequentialId('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
|
|
|
63
70
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
64
71
|
let TextField = /*#__PURE__*/function (_Component) {
|
|
65
72
|
_inherits(TextField, _Component);
|
|
66
|
-
var _super = _createSuper(TextField);
|
|
67
73
|
function TextField() {
|
|
68
74
|
var _this;
|
|
69
75
|
_classCallCheck(this, TextField);
|
|
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, TextField, [...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.
|
|
@@ -88,6 +94,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
88
94
|
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(this.props.hint), 'TextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
89
95
|
}
|
|
90
96
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
97
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
91
98
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
92
99
|
max: this.props.horizontalConstraint,
|
|
93
100
|
children: jsxRuntime.jsxs(Stack__default["default"], {
|
|
@@ -112,6 +119,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
112
119
|
isAutofocussed: this.props.isAutofocussed,
|
|
113
120
|
isDisabled: this.props.isDisabled,
|
|
114
121
|
isReadOnly: this.props.isReadOnly,
|
|
122
|
+
hasWarning: hasWarning,
|
|
115
123
|
hasError: hasError,
|
|
116
124
|
placeholder: this.props.placeholder,
|
|
117
125
|
horizontalConstraint: "scale"
|
|
@@ -124,6 +132,11 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
124
132
|
errors: this.props.errors,
|
|
125
133
|
isVisible: hasError,
|
|
126
134
|
renderError: this.props.renderError
|
|
135
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
136
|
+
id: sequentialWarningsId,
|
|
137
|
+
warnings: this.props.warnings,
|
|
138
|
+
isVisible: hasWarning,
|
|
139
|
+
renderWarning: this.props.renderWarning
|
|
127
140
|
})]
|
|
128
141
|
})
|
|
129
142
|
});
|
|
@@ -153,7 +166,9 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
153
166
|
id: _pt__default["default"].string,
|
|
154
167
|
horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
155
168
|
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
169
|
+
warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
156
170
|
renderError: _pt__default["default"].func,
|
|
171
|
+
renderWarning: _pt__default["default"].func,
|
|
157
172
|
isRequired: _pt__default["default"].bool,
|
|
158
173
|
touched: _pt__default["default"].bool,
|
|
159
174
|
autoComplete: _pt__default["default"].string,
|
|
@@ -176,7 +191,7 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
176
191
|
var TextField$1 = TextField;
|
|
177
192
|
|
|
178
193
|
// NOTE: This string will be replaced on build time with the package version.
|
|
179
|
-
var version = "17.
|
|
194
|
+
var version = "17.1.0";
|
|
180
195
|
|
|
181
196
|
exports["default"] = TextField$1;
|
|
182
197
|
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 FieldLabel = require('@commercetools-uikit/field-label');
|
|
|
27
27
|
var TextInput = require('@commercetools-uikit/text-input');
|
|
28
28
|
var utils = require('@commercetools-uikit/utils');
|
|
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,29 +48,34 @@ var Stack__default = /*#__PURE__*/_interopDefault(Stack);
|
|
|
47
48
|
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
48
49
|
var TextInput__default = /*#__PURE__*/_interopDefault(TextInput);
|
|
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('text-field-');
|
|
56
58
|
const sequentialErrorsId = utils.createSequentialId('text-field-error-')();
|
|
59
|
+
const sequentialWarningsId = utils.createSequentialId('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
|
|
|
62
69
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
63
70
|
let TextField = /*#__PURE__*/function (_Component) {
|
|
64
71
|
_inherits(TextField, _Component);
|
|
65
|
-
var _super = _createSuper(TextField);
|
|
66
72
|
function TextField() {
|
|
67
73
|
var _this;
|
|
68
74
|
_classCallCheck(this, TextField);
|
|
69
75
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
70
76
|
args[_key] = arguments[_key];
|
|
71
77
|
}
|
|
72
|
-
_this =
|
|
78
|
+
_this = _callSuper(this, TextField, [...args]);
|
|
73
79
|
_this.state = {
|
|
74
80
|
// We generate an id in case no id is provided by the parent to attach the
|
|
75
81
|
// label to the input component.
|
|
@@ -83,6 +89,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
83
89
|
if (!this.props.isReadOnly) ;
|
|
84
90
|
if (this.props.hintIcon) ;
|
|
85
91
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
92
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
86
93
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
87
94
|
max: this.props.horizontalConstraint,
|
|
88
95
|
children: jsxRuntime.jsxs(Stack__default["default"], {
|
|
@@ -107,6 +114,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
107
114
|
isAutofocussed: this.props.isAutofocussed,
|
|
108
115
|
isDisabled: this.props.isDisabled,
|
|
109
116
|
isReadOnly: this.props.isReadOnly,
|
|
117
|
+
hasWarning: hasWarning,
|
|
110
118
|
hasError: hasError,
|
|
111
119
|
placeholder: this.props.placeholder,
|
|
112
120
|
horizontalConstraint: "scale"
|
|
@@ -119,6 +127,11 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
119
127
|
errors: this.props.errors,
|
|
120
128
|
isVisible: hasError,
|
|
121
129
|
renderError: this.props.renderError
|
|
130
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
131
|
+
id: sequentialWarningsId,
|
|
132
|
+
warnings: this.props.warnings,
|
|
133
|
+
isVisible: hasWarning,
|
|
134
|
+
renderWarning: this.props.renderWarning
|
|
122
135
|
})]
|
|
123
136
|
})
|
|
124
137
|
});
|
|
@@ -148,7 +161,7 @@ TextField.propTypes = {};
|
|
|
148
161
|
var TextField$1 = TextField;
|
|
149
162
|
|
|
150
163
|
// NOTE: This string will be replaced on build time with the package version.
|
|
151
|
-
var version = "17.
|
|
164
|
+
var version = "17.1.0";
|
|
152
165
|
|
|
153
166
|
exports["default"] = TextField$1;
|
|
154
167
|
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,30 +23,35 @@ import FieldLabel from '@commercetools-uikit/field-label';
|
|
|
23
23
|
import TextInput from '@commercetools-uikit/text-input';
|
|
24
24
|
import { createSequentialId, warning, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
|
|
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('text-field-');
|
|
33
34
|
const sequentialErrorsId = createSequentialId('text-field-error-')();
|
|
35
|
+
const sequentialWarningsId = createSequentialId('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
|
|
|
39
45
|
// Similar shape of `FormikErrors` but values are `TFieldErrors` objects.
|
|
40
46
|
let TextField = /*#__PURE__*/function (_Component) {
|
|
41
47
|
_inherits(TextField, _Component);
|
|
42
|
-
var _super = _createSuper(TextField);
|
|
43
48
|
function TextField() {
|
|
44
49
|
var _this;
|
|
45
50
|
_classCallCheck(this, TextField);
|
|
46
51
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
47
52
|
args[_key] = arguments[_key];
|
|
48
53
|
}
|
|
49
|
-
_this =
|
|
54
|
+
_this = _callSuper(this, TextField, [...args]);
|
|
50
55
|
_this.state = {
|
|
51
56
|
// We generate an id in case no id is provided by the parent to attach the
|
|
52
57
|
// label to the input component.
|
|
@@ -64,6 +69,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
64
69
|
process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(this.props.hint), 'TextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
65
70
|
}
|
|
66
71
|
const hasError = this.props.touched && hasErrors(this.props.errors);
|
|
72
|
+
const hasWarning = this.props.touched && hasWarnings(this.props.warnings);
|
|
67
73
|
return jsx(Constraints.Horizontal, {
|
|
68
74
|
max: this.props.horizontalConstraint,
|
|
69
75
|
children: jsxs(Stack, {
|
|
@@ -88,6 +94,7 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
88
94
|
isAutofocussed: this.props.isAutofocussed,
|
|
89
95
|
isDisabled: this.props.isDisabled,
|
|
90
96
|
isReadOnly: this.props.isReadOnly,
|
|
97
|
+
hasWarning: hasWarning,
|
|
91
98
|
hasError: hasError,
|
|
92
99
|
placeholder: this.props.placeholder,
|
|
93
100
|
horizontalConstraint: "scale"
|
|
@@ -100,6 +107,11 @@ let TextField = /*#__PURE__*/function (_Component) {
|
|
|
100
107
|
errors: this.props.errors,
|
|
101
108
|
isVisible: hasError,
|
|
102
109
|
renderError: this.props.renderError
|
|
110
|
+
}), jsx(FieldWarnings, {
|
|
111
|
+
id: sequentialWarningsId,
|
|
112
|
+
warnings: this.props.warnings,
|
|
113
|
+
isVisible: hasWarning,
|
|
114
|
+
renderWarning: this.props.renderWarning
|
|
103
115
|
})]
|
|
104
116
|
})
|
|
105
117
|
});
|
|
@@ -129,7 +141,9 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
129
141
|
id: _pt.string,
|
|
130
142
|
horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
131
143
|
errors: _pt.objectOf(_pt.bool),
|
|
144
|
+
warnings: _pt.objectOf(_pt.bool),
|
|
132
145
|
renderError: _pt.func,
|
|
146
|
+
renderWarning: _pt.func,
|
|
133
147
|
isRequired: _pt.bool,
|
|
134
148
|
touched: _pt.bool,
|
|
135
149
|
autoComplete: _pt.string,
|
|
@@ -152,6 +166,6 @@ TextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
152
166
|
var TextField$1 = TextField;
|
|
153
167
|
|
|
154
168
|
// NOTE: This string will be replaced on build time with the package version.
|
|
155
|
-
var version = "17.
|
|
169
|
+
var version = "17.1.0";
|
|
156
170
|
|
|
157
171
|
export { TextField$1 as default, version };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, type ChangeEventHandler, type FocusEventHandler, 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;
|
|
@@ -8,7 +9,9 @@ export type TTextFieldProps = {
|
|
|
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
|
autoComplete?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/text-field",
|
|
3
3
|
"description": "A controlled text input component for single-line strings with validation states.",
|
|
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/spacings-stack": "17.1.0",
|
|
30
|
+
"@commercetools-uikit/text-input": "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-text-field.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|