@commercetools-uikit/text-field 12.2.5 → 13.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
@@ -41,31 +41,44 @@ export default Example;
41
41
 
42
42
  ## Properties
43
43
 
44
- | Props | Type | Required | Default | Description |
45
- | ---------------------- | -------------------------------------------------------------------------------------------------- | :------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
46
- | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
47
- | `horizontalConstraint` | `enum`<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
- | `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br/>&#xA;Unknown errors will be forwarded to renderError. |
49
- | `errors.missing` | `bool` | | | |
50
- | `renderError` | `func` | | | This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.&#xA;<br />&#xA;Signature: `(key, error) => React.node` |
51
- | `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
52
- | `touched` | `bool` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
53
- | `autoComplete` | `string` | | | Used as HTML autocomplete property |
54
- | `name` | `string` | | | Used as HTML name of the input component. property |
55
- | `value` | `string` | ✅ | | Value of the input component. |
56
- | `onChange` | `custom` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.&#xA;<br />&#xA;Signature: `(event) => void` |
57
- | `onBlur` | `func` | | | Called when input is blurred&#xA;Signature: `(event) => void` |
58
- | `onFocus` | `func` | | | Called when input is focused&#xA;Signature: `(event) => void` |
59
- | `isAutofocussed` | `bool` | | | Focus the input on initial render |
60
- | `isDisabled` | `bool` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
61
- | `isReadOnly` | `bool` | | | Indicates that the field is displaying read-only content |
62
- | `placeholder` | `string` | | | Placeholder text for the input |
63
- | `title` | `<string, node>` | ✅ | | Title of the label |
64
- | `hint` | `custom` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas description can describe it in more depth. Can also receive a hintIcon. |
65
- | `description` | `<string, node>` | | | Provides a description for the title. |
66
- | `onInfoButtonClick` | `func` | | | Function called when info button is pressed. Info button will only be visible when this prop is passed. |
67
- | `hintIcon` | `node` | | | Icon to be displayed beside the hint text. Will only get rendered when hint is passed as well. |
68
- | `badge` | `node` | | | Badge to be displayed beside the label. Might be used to display additional information about the content of the field (E.g verified email) |
44
+ | Props | Type | Required | Default | Description |
45
+ | ---------------------- | ----------------------------------------------------------------------------------------------------- | :------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
46
+ | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
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
+ | `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br/>&#xA;Unknown errors will be forwarded to renderError. |
49
+ | `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.&#xA;<br /> |
50
+ | `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
51
+ | `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
52
+ | `autoComplete` | `string` | | | Used as HTML autocomplete property |
53
+ | `name` | `string` | | | Used as HTML name of the input component. property |
54
+ | `value` | `string` | ✅ | | Value of the input component. |
55
+ | `onChange` | `ChangeEventHandler` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.&#xA;<br /> |
56
+ | `onBlur` | `FocusEventHandler` | | | Called when input is blurred |
57
+ | `onFocus` | `FocusEventHandler` | | | Called when input is focused |
58
+ | `isAutofocussed` | `boolean` | | | Focus the input on initial render |
59
+ | `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
60
+ | `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
61
+ | `placeholder` | `string` | | | Placeholder text for the input |
62
+ | `title` | `union`<br/>Possible values:<br/>`string , ReactNode` | ✅ | | Title of the label |
63
+ | `hint` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas description can describe it in more depth. Can also receive a hintIcon. |
64
+ | `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
65
+ | `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed. Info button will only be visible when this prop is passed. |
66
+ | `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text. Will only get rendered when hint is passed as well. |
67
+ | `badge` | `ReactNode` | | | Badge to be displayed beside the label. Might be used to display additional information about the content of the field (E.g verified email) |
68
+
69
+ ## Signatures
70
+
71
+ ### Signature `renderError`
72
+
73
+ ```ts
74
+ (key: string, error?: boolean) => ReactNode;
75
+ ```
76
+
77
+ ### Signature `onInfoButtonClick`
78
+
79
+ ```ts
80
+ () => void
81
+ ```
69
82
 
70
83
  ## `data-*` props
71
84
 
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index";
2
+ export { default } from "./declarations/src/index";
@@ -17,12 +17,11 @@ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
17
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
18
  var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
19
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ var _pt = require('prop-types');
20
21
  var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
22
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
23
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
24
  var react = require('react');
24
- var PropTypes = require('prop-types');
25
- var requiredIf = require('react-required-if');
26
25
  var Constraints = require('@commercetools-uikit/constraints');
27
26
  var Stack = require('@commercetools-uikit/spacings-stack');
28
27
  var FieldLabel = require('@commercetools-uikit/field-label');
@@ -42,20 +41,19 @@ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachIns
42
41
  var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
43
42
  var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
44
43
  var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
44
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
45
45
  var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
46
46
  var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
47
47
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
48
- var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
49
- var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
50
48
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
51
49
  var Stack__default = /*#__PURE__*/_interopDefault(Stack);
52
50
  var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
53
51
  var TextInput__default = /*#__PURE__*/_interopDefault(TextInput);
54
52
  var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
55
53
 
56
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
54
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
57
55
 
58
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
56
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
59
57
 
60
58
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
61
59
 
@@ -96,6 +94,14 @@ var TextField = /*#__PURE__*/function (_Component) {
96
94
  _createClass(TextField, [{
97
95
  key: "render",
98
96
  value: function render() {
97
+ if (!this.props.isReadOnly) {
98
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when is not read only.') : void 0;
99
+ }
100
+
101
+ if (this.props.hintIcon) {
102
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(typeof this.props.hint), 'TextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
103
+ }
104
+
99
105
  var hasError = this.props.touched && hasErrors(this.props.errors);
100
106
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
101
107
  max: this.props.horizontalConstraint,
@@ -149,138 +155,33 @@ TextField.getDerivedStateFromProps = function (props, state) {
149
155
  };
150
156
 
151
157
  TextField.propTypes = process.env.NODE_ENV !== "production" ? {
152
- // TextField
153
-
154
- /**
155
- * Used as HTML id property. An id is auto-generated when it is not specified.
156
- */
157
- id: PropTypes__default["default"].string,
158
-
159
- /**
160
- * Horizontal size limit of the input fields.
161
- */
162
- horizontalConstraint: PropTypes__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
163
-
164
- /**
165
- * A map of errors. Error messages for known errors are rendered automatically.
166
- * <br/>
167
- * Unknown errors will be forwarded to renderError.
168
- */
169
- errors: PropTypes__default["default"].shape({
170
- missing: PropTypes__default["default"].bool
171
- }),
172
-
173
- /**
174
- * This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
175
- * <br />
176
- * Signature: `(key, error) => React.node`
177
- */
178
- renderError: PropTypes__default["default"].func,
179
-
180
- /**
181
- * Indicates if the value is required. Shows an the "required asterisk" if so.
182
- */
183
- isRequired: PropTypes__default["default"].bool,
184
-
185
- /**
186
- * Indicates whether the field was touched. Errors will only be shown when the field was touched.
187
- */
188
- touched: PropTypes__default["default"].bool,
189
- // TextInput
190
-
191
- /**
192
- * Used as HTML autocomplete property
193
- */
194
- autoComplete: PropTypes__default["default"].string,
195
-
196
- /**
197
- * Used as HTML name of the input component. property
198
- */
199
- name: PropTypes__default["default"].string,
200
-
201
- /**
202
- * Value of the input component.
203
- */
204
- value: PropTypes__default["default"].string.isRequired,
205
-
206
- /**
207
- * Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
208
- * <br />
209
- * Signature: `(event) => void`
210
- */
211
- onChange: requiredIf__default["default"](PropTypes__default["default"].func, function (props) {
212
- return !props.isReadOnly;
213
- }),
214
-
215
- /**
216
- * Called when input is blurred
217
- * Signature: `(event) => void`
218
- */
219
- onBlur: PropTypes__default["default"].func,
220
-
221
- /**
222
- * Called when input is focused
223
- * Signature: `(event) => void`
224
- */
225
- onFocus: PropTypes__default["default"].func,
226
-
227
- /**
228
- * Focus the input on initial render
229
- */
230
- isAutofocussed: PropTypes__default["default"].bool,
231
-
232
- /**
233
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
234
- */
235
- isDisabled: PropTypes__default["default"].bool,
236
-
237
- /**
238
- * Indicates that the field is displaying read-only content
239
- */
240
- isReadOnly: PropTypes__default["default"].bool,
241
-
242
- /**
243
- * Placeholder text for the input
244
- */
245
- placeholder: PropTypes__default["default"].string,
246
- // LabelField
247
-
248
- /**
249
- * Title of the label
250
- */
251
- title: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]).isRequired,
252
-
253
- /**
254
- * Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas description can describe it in more depth. Can also receive a hintIcon.
255
- */
256
- hint: requiredIf__default["default"](PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]), function (props) {
257
- return props.hintIcon;
258
- }),
259
-
260
- /**
261
- * Provides a description for the title.
262
- */
263
- description: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]),
264
-
265
- /**
266
- * Function called when info button is pressed. Info button will only be visible when this prop is passed.
267
- */
268
- onInfoButtonClick: PropTypes__default["default"].func,
269
-
270
- /**
271
- * Icon to be displayed beside the hint text. Will only get rendered when hint is passed as well.
272
- */
273
- hintIcon: PropTypes__default["default"].node,
274
-
275
- /**
276
- * Badge to be displayed beside the label. Might be used to display additional information about the content of the field (E.g verified email)
277
- */
278
- badge: PropTypes__default["default"].node
158
+ id: _pt__default["default"].string,
159
+ horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
160
+ errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
161
+ renderError: _pt__default["default"].func,
162
+ isRequired: _pt__default["default"].bool,
163
+ touched: _pt__default["default"].bool,
164
+ autoComplete: _pt__default["default"].string,
165
+ name: _pt__default["default"].string,
166
+ value: _pt__default["default"].string.isRequired,
167
+ onChange: _pt__default["default"].func,
168
+ onBlur: _pt__default["default"].func,
169
+ onFocus: _pt__default["default"].func,
170
+ isAutofocussed: _pt__default["default"].bool,
171
+ isDisabled: _pt__default["default"].bool,
172
+ isReadOnly: _pt__default["default"].bool,
173
+ placeholder: _pt__default["default"].string,
174
+ title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
175
+ hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
176
+ description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
177
+ onInfoButtonClick: _pt__default["default"].func,
178
+ hintIcon: _pt__default["default"].element,
179
+ badge: _pt__default["default"].node
279
180
  } : {};
280
181
  var TextField$1 = TextField;
281
182
 
282
183
  // NOTE: This string will be replaced on build time with the package version.
283
- var version = "12.2.5";
184
+ var version = "13.0.0";
284
185
 
285
186
  exports["default"] = TextField$1;
286
187
  exports.version = version;
@@ -17,12 +17,11 @@ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
17
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
18
  var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
19
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ require('prop-types');
20
21
  var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
22
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
23
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
24
  var react = require('react');
24
- require('prop-types');
25
- require('react-required-if');
26
25
  var Constraints = require('@commercetools-uikit/constraints');
27
26
  var Stack = require('@commercetools-uikit/spacings-stack');
28
27
  var FieldLabel = require('@commercetools-uikit/field-label');
@@ -51,9 +50,9 @@ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
51
50
  var TextInput__default = /*#__PURE__*/_interopDefault(TextInput);
52
51
  var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
53
52
 
54
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
53
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
55
54
 
56
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
55
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
57
56
 
58
57
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
59
58
 
@@ -94,6 +93,10 @@ var TextField = /*#__PURE__*/function (_Component) {
94
93
  _createClass(TextField, [{
95
94
  key: "render",
96
95
  value: function render() {
96
+ if (!this.props.isReadOnly) ;
97
+
98
+ if (this.props.hintIcon) ;
99
+
97
100
  var hasError = this.props.touched && hasErrors(this.props.errors);
98
101
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
99
102
  max: this.props.horizontalConstraint,
@@ -150,7 +153,7 @@ TextField.propTypes = {};
150
153
  var TextField$1 = TextField;
151
154
 
152
155
  // NOTE: This string will be replaced on build time with the package version.
153
- var version = "12.2.5";
156
+ var version = "13.0.0";
154
157
 
155
158
  exports["default"] = TextField$1;
156
159
  exports.version = version;
@@ -13,23 +13,22 @@ import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
13
13
  import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
14
14
  import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
15
15
  import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
16
+ import _pt from 'prop-types';
16
17
  import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
17
18
  import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
18
19
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
19
- import { Component } from 'react';
20
- import PropTypes from 'prop-types';
21
- import requiredIf from 'react-required-if';
20
+ import { isValidElement, Component } from 'react';
22
21
  import Constraints from '@commercetools-uikit/constraints';
23
22
  import Stack from '@commercetools-uikit/spacings-stack';
24
23
  import FieldLabel from '@commercetools-uikit/field-label';
25
24
  import TextInput from '@commercetools-uikit/text-input';
26
- import { createSequentialId, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
25
+ import { createSequentialId, warning, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
27
26
  import FieldErrors from '@commercetools-uikit/field-errors';
28
27
  import { jsx, jsxs } from '@emotion/react/jsx-runtime';
29
28
 
30
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
29
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
30
 
32
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
31
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
33
32
 
34
33
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
35
34
 
@@ -70,6 +69,14 @@ var TextField = /*#__PURE__*/function (_Component) {
70
69
  _createClass(TextField, [{
71
70
  key: "render",
72
71
  value: function render() {
72
+ if (!this.props.isReadOnly) {
73
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'TextField: `onChange` is required when is not read only.') : void 0;
74
+ }
75
+
76
+ if (this.props.hintIcon) {
77
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(typeof this.props.hint), 'TextField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
78
+ }
79
+
73
80
  var hasError = this.props.touched && hasErrors(this.props.errors);
74
81
  return jsx(Constraints.Horizontal, {
75
82
  max: this.props.horizontalConstraint,
@@ -123,137 +130,32 @@ TextField.getDerivedStateFromProps = function (props, state) {
123
130
  };
124
131
 
125
132
  TextField.propTypes = process.env.NODE_ENV !== "production" ? {
126
- // TextField
127
-
128
- /**
129
- * Used as HTML id property. An id is auto-generated when it is not specified.
130
- */
131
- id: PropTypes.string,
132
-
133
- /**
134
- * Horizontal size limit of the input fields.
135
- */
136
- horizontalConstraint: PropTypes.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
137
-
138
- /**
139
- * A map of errors. Error messages for known errors are rendered automatically.
140
- * <br/>
141
- * Unknown errors will be forwarded to renderError.
142
- */
143
- errors: PropTypes.shape({
144
- missing: PropTypes.bool
145
- }),
146
-
147
- /**
148
- * This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
149
- * <br />
150
- * Signature: `(key, error) => React.node`
151
- */
152
- renderError: PropTypes.func,
153
-
154
- /**
155
- * Indicates if the value is required. Shows an the "required asterisk" if so.
156
- */
157
- isRequired: PropTypes.bool,
158
-
159
- /**
160
- * Indicates whether the field was touched. Errors will only be shown when the field was touched.
161
- */
162
- touched: PropTypes.bool,
163
- // TextInput
164
-
165
- /**
166
- * Used as HTML autocomplete property
167
- */
168
- autoComplete: PropTypes.string,
169
-
170
- /**
171
- * Used as HTML name of the input component. property
172
- */
173
- name: PropTypes.string,
174
-
175
- /**
176
- * Value of the input component.
177
- */
178
- value: PropTypes.string.isRequired,
179
-
180
- /**
181
- * Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
182
- * <br />
183
- * Signature: `(event) => void`
184
- */
185
- onChange: requiredIf(PropTypes.func, function (props) {
186
- return !props.isReadOnly;
187
- }),
188
-
189
- /**
190
- * Called when input is blurred
191
- * Signature: `(event) => void`
192
- */
193
- onBlur: PropTypes.func,
194
-
195
- /**
196
- * Called when input is focused
197
- * Signature: `(event) => void`
198
- */
199
- onFocus: PropTypes.func,
200
-
201
- /**
202
- * Focus the input on initial render
203
- */
204
- isAutofocussed: PropTypes.bool,
205
-
206
- /**
207
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
208
- */
209
- isDisabled: PropTypes.bool,
210
-
211
- /**
212
- * Indicates that the field is displaying read-only content
213
- */
214
- isReadOnly: PropTypes.bool,
215
-
216
- /**
217
- * Placeholder text for the input
218
- */
219
- placeholder: PropTypes.string,
220
- // LabelField
221
-
222
- /**
223
- * Title of the label
224
- */
225
- title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
226
-
227
- /**
228
- * Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas description can describe it in more depth. Can also receive a hintIcon.
229
- */
230
- hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
231
- return props.hintIcon;
232
- }),
233
-
234
- /**
235
- * Provides a description for the title.
236
- */
237
- description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
238
-
239
- /**
240
- * Function called when info button is pressed. Info button will only be visible when this prop is passed.
241
- */
242
- onInfoButtonClick: PropTypes.func,
243
-
244
- /**
245
- * Icon to be displayed beside the hint text. Will only get rendered when hint is passed as well.
246
- */
247
- hintIcon: PropTypes.node,
248
-
249
- /**
250
- * Badge to be displayed beside the label. Might be used to display additional information about the content of the field (E.g verified email)
251
- */
252
- badge: PropTypes.node
133
+ id: _pt.string,
134
+ horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
135
+ errors: _pt.objectOf(_pt.bool),
136
+ renderError: _pt.func,
137
+ isRequired: _pt.bool,
138
+ touched: _pt.bool,
139
+ autoComplete: _pt.string,
140
+ name: _pt.string,
141
+ value: _pt.string.isRequired,
142
+ onChange: _pt.func,
143
+ onBlur: _pt.func,
144
+ onFocus: _pt.func,
145
+ isAutofocussed: _pt.bool,
146
+ isDisabled: _pt.bool,
147
+ isReadOnly: _pt.bool,
148
+ placeholder: _pt.string,
149
+ title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
150
+ hint: _pt.oneOfType([_pt.string, _pt.node]),
151
+ description: _pt.oneOfType([_pt.string, _pt.node]),
152
+ onInfoButtonClick: _pt.func,
153
+ hintIcon: _pt.element,
154
+ badge: _pt.node
253
155
  } : {};
254
156
  var TextField$1 = TextField;
255
157
 
256
158
  // NOTE: This string will be replaced on build time with the package version.
257
- var version = "12.2.5";
159
+ var version = "13.0.0";
258
160
 
259
161
  export { TextField$1 as default, version };
@@ -0,0 +1,2 @@
1
+ export { default } from './text-field';
2
+ export { default as version } from './version';
@@ -0,0 +1,40 @@
1
+ import { Component, type ChangeEventHandler, type FocusEventHandler, type ReactElement, type ReactNode } from 'react';
2
+ declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
3
+ declare type TFieldErrors = Record<string, boolean>;
4
+ declare type TTextFieldProps = {
5
+ id?: string;
6
+ horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
7
+ errors?: TFieldErrors;
8
+ renderError?: TErrorRenderer;
9
+ isRequired?: boolean;
10
+ touched?: boolean;
11
+ autoComplete?: string;
12
+ name?: string;
13
+ value: string;
14
+ onChange?: ChangeEventHandler;
15
+ onBlur?: FocusEventHandler;
16
+ onFocus?: FocusEventHandler;
17
+ isAutofocussed?: boolean;
18
+ isDisabled?: boolean;
19
+ isReadOnly?: boolean;
20
+ placeholder?: string;
21
+ title: string | ReactNode;
22
+ hint?: string | ReactNode;
23
+ description?: string | ReactNode;
24
+ onInfoButtonClick?: () => void;
25
+ hintIcon?: ReactElement;
26
+ badge?: ReactNode;
27
+ };
28
+ declare type TTextFieldState = Pick<TTextFieldProps, 'id'>;
29
+ declare class TextField extends Component<TTextFieldProps, TTextFieldState> {
30
+ static displayName: string;
31
+ static defaultProps: Pick<TTextFieldProps, 'horizontalConstraint'>;
32
+ state: {
33
+ id: string | undefined;
34
+ };
35
+ static getDerivedStateFromProps: (props: TTextFieldProps, state: TTextFieldState) => {
36
+ id: string;
37
+ };
38
+ render(): import("@emotion/react/jsx-runtime").JSX.Element;
39
+ }
40
+ export default TextField;
@@ -0,0 +1,2 @@
1
+ declare const _default: "__@UI_KIT_PACKAGE/VERSION_OF_RELEASE__";
2
+ export default _default;
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": "12.2.5",
4
+ "version": "13.0.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,12 +9,7 @@
9
9
  "directory": "packages/components/fields/text-field"
10
10
  },
11
11
  "homepage": "https://uikit.commercetools.com",
12
- "keywords": [
13
- "javascript",
14
- "design system",
15
- "react",
16
- "uikit"
17
- ],
12
+ "keywords": ["javascript", "design system", "react", "uikit"],
18
13
  "license": "MIT",
19
14
  "publishConfig": {
20
15
  "access": "public"
@@ -22,22 +17,20 @@
22
17
  "sideEffects": false,
23
18
  "main": "dist/commercetools-uikit-text-field.cjs.js",
24
19
  "module": "dist/commercetools-uikit-text-field.esm.js",
25
- "files": [
26
- "dist"
27
- ],
20
+ "files": ["dist"],
28
21
  "dependencies": {
29
- "@babel/runtime": "7.16.3",
30
- "@babel/runtime-corejs3": "7.16.3",
31
- "@commercetools-uikit/constraints": "12.2.5",
32
- "@commercetools-uikit/design-system": "12.2.5",
33
- "@commercetools-uikit/field-errors": "12.2.5",
34
- "@commercetools-uikit/field-label": "12.2.5",
35
- "@commercetools-uikit/spacings-stack": "12.2.5",
36
- "@commercetools-uikit/text-input": "12.2.5",
37
- "@commercetools-uikit/utils": "12.2.5",
22
+ "@babel/runtime": "7.17.2",
23
+ "@babel/runtime-corejs3": "7.17.2",
24
+ "@commercetools-uikit/constraints": "13.0.0",
25
+ "@commercetools-uikit/design-system": "13.0.0",
26
+ "@commercetools-uikit/field-errors": "13.0.0",
27
+ "@commercetools-uikit/field-label": "13.0.0",
28
+ "@commercetools-uikit/spacings-stack": "13.0.0",
29
+ "@commercetools-uikit/text-input": "13.0.0",
30
+ "@commercetools-uikit/utils": "12.2.9",
38
31
  "@emotion/react": "^11.4.0",
39
32
  "@emotion/styled": "^11.3.0",
40
- "prop-types": "15.7.2",
33
+ "prop-types": "15.8.1",
41
34
  "react-required-if": "1.0.3"
42
35
  },
43
36
  "devDependencies": {