@commercetools-uikit/date-field 12.2.6 → 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
@@ -45,31 +45,56 @@ export default Example;
45
45
 
46
46
  ## Properties
47
47
 
48
- | Props | Type | Required | Default | Description |
49
- | ---------------------- | ----------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
- | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
51
- | `horizontalConstraint` | `enum`<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. |
52
- | `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
53
- | `errors.missing` | `bool` | | | |
54
- | `renderError` | `func` | | | 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.&#xA;<br />&#xA;Signature: `(key, error) => React.node` |
55
- | `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
56
- | `touched` | `bool` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
57
- | `name` | `string` | | | Used as HTML name of the input component. |
58
- | `value` | `string` | ✅ | | Value of the input |
59
- | `onChange` | `custom` | | | Called with an event containing the new value.&#xA;This is always called with either an empty string or a valid date in the format of `YYYY-MM-DD`.&#xA;<br/> Parent should pass it back as `value`.&#xA;<br/>&#xA;Signature: `(event) => void` |
60
- | `onBlur` | `func` | | | Called when input is blurred&#xA;<br/>&#xA;Signature: `(event) => void` |
61
- | `onFocus` | `func` | | | Called when input is focused&#xA;<br/>&#xA;Signature: `(event) => void` |
62
- | `isDisabled` | `bool` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
63
- | `isReadOnly` | `bool` | | | Indicates that the field is displaying read-only content |
64
- | `placeholder` | `string` | | | Placeholder text for the input |
65
- | `minValue` | `string` | | | A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
66
- | `maxValue` | `string` | | | A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
67
- | `title` | `<string, node>` | ✅ | | Title of the label |
68
- | `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`. |
69
- | `description` | `<string, node>` | | | Provides a description for the title. |
70
- | `onInfoButtonClick` | `func` | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.&#xA;<br />&#xA;Signature: `(event) => void` |
71
- | `hintIcon` | `node` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
72
- | `badge` | `node` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
48
+ | Props | Type | Required | Default | Description |
49
+ | ---------------------- | -------------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
+ | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
51
+ | `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. |
52
+ | `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
53
+ | `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. |
54
+ | `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
55
+ | `touched` | `boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
56
+ | `name` | `string` | | | Used as HTML name of the input component. |
57
+ | `value` | `string` | ✅ | | Value of the input |
58
+ | `onChange` | `Function`<br/>[See signature.](#signature-onChange) | ✅ | | Called with an event containing the new value.&#xA;This is always called with either an empty string or a valid date in the format of `YYYY-MM-DD`.&#xA;<br/> Parent should pass it back as `value`. |
59
+ | `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Called when input is blurred |
60
+ | `onFocus` | `FocusEventHandler` | | | Called when input is focused |
61
+ | `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
62
+ | `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
63
+ | `placeholder` | `string` | | | Placeholder text for the input |
64
+ | `minValue` | `string` | | | A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
65
+ | `maxValue` | `string` | | | A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
66
+ | `title` | `union`<br/>Possible values:<br/>`string , ReactNode` | ✅ | | Title of the label |
67
+ | `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`. |
68
+ | `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
69
+ | `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed. |
70
+ | `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
71
+ | `badge` | `ReactNode` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
72
+
73
+ ## Signatures
74
+
75
+ ### Signature `renderError`
76
+
77
+ ```ts
78
+ (key: string, error?: boolean) => ReactNode;
79
+ ```
80
+
81
+ ### Signature `onChange`
82
+
83
+ ```ts
84
+ (event: TEvent) => void
85
+ ```
86
+
87
+ ### Signature `onBlur`
88
+
89
+ ```ts
90
+ (event: TEvent) => void
91
+ ```
92
+
93
+ ### Signature `onInfoButtonClick`
94
+
95
+ ```ts
96
+ () => void
97
+ ```
73
98
 
74
99
  ## `data-*` props
75
100
 
@@ -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 utils = require('@commercetools-uikit/utils');
27
26
  var Constraints = require('@commercetools-uikit/constraints');
28
27
  var Spacings = require('@commercetools-uikit/spacings');
@@ -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 Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
52
50
  var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
53
51
  var DateInput__default = /*#__PURE__*/_interopDefault(DateInput);
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
 
@@ -97,6 +95,15 @@ var DateField = /*#__PURE__*/function (_Component) {
97
95
  key: "render",
98
96
  value: function render() {
99
97
  var hasError = this.props.touched && hasErrors(this.props.errors);
98
+
99
+ if (!this.props.isReadOnly) {
100
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'DateField: `onChange` is required when field is not read only.') : void 0;
101
+ }
102
+
103
+ if (this.props.hintIcon) {
104
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(typeof this.props.hint), 'DateField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
105
+ }
106
+
100
107
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
101
108
  max: this.props.horizontalConstraint,
102
109
  children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
@@ -149,150 +156,33 @@ DateField.getDerivedStateFromProps = function (props, state) {
149
156
  };
150
157
 
151
158
  DateField.propTypes = process.env.NODE_ENV !== "production" ? {
152
- // DateField
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([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
- * 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.
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
- // DateInput
190
-
191
- /**
192
- * Used as HTML name of the input component.
193
- */
194
- name: PropTypes__default["default"].string,
195
-
196
- /**
197
- * Value of the input
198
- */
199
- value: PropTypes__default["default"].string.isRequired,
200
-
201
- /**
202
- * Called with an event containing the new value.
203
- * This is always called with either an empty string or a valid date in the format of `YYYY-MM-DD`.
204
- * <br/> Parent should pass it back as `value`.
205
- * <br/>
206
- * Signature: `(event) => void`
207
- */
208
- onChange: requiredIf__default["default"](PropTypes__default["default"].func, function (props) {
209
- return !props.isReadOnly;
210
- }),
211
-
212
- /**
213
- * Called when input is blurred
214
- * <br/>
215
- * Signature: `(event) => void`
216
- */
217
- onBlur: PropTypes__default["default"].func,
218
-
219
- /**
220
- * Called when input is focused
221
- * <br/>
222
- * Signature: `(event) => void`
223
- */
224
- onFocus: PropTypes__default["default"].func,
225
-
226
- /**
227
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
228
- */
229
- isDisabled: PropTypes__default["default"].bool,
230
-
231
- /**
232
- * Indicates that the field is displaying read-only content
233
- */
234
- isReadOnly: PropTypes__default["default"].bool,
235
-
236
- /**
237
- * Placeholder text for the input
238
- */
239
- placeholder: PropTypes__default["default"].string,
240
-
241
- /**
242
- * A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
243
- */
244
- minValue: PropTypes__default["default"].string,
245
-
246
- /**
247
- * A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
248
- */
249
- maxValue: PropTypes__default["default"].string,
250
- // LabelField
251
-
252
- /**
253
- * Title of the label
254
- */
255
- title: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]).isRequired,
256
-
257
- /**
258
- * 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`.
259
- */
260
- hint: requiredIf__default["default"](PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]), function (props) {
261
- return props.hintIcon;
262
- }),
263
-
264
- /**
265
- * Provides a description for the title.
266
- */
267
- description: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]),
268
-
269
- /**
270
- * Function called when info button is pressed.
271
- * <br />
272
- * Info button will only be visible when this prop is passed.
273
- * <br />
274
- * Signature: `(event) => void`
275
- */
276
- onInfoButtonClick: PropTypes__default["default"].func,
277
-
278
- /**
279
- * Icon to be displayed beside the hint text.
280
- * <br />
281
- * Will only get rendered when `hint` is passed as well.
282
- */
283
- hintIcon: PropTypes__default["default"].node,
284
-
285
- /**
286
- * Badge to be displayed beside the label.
287
- * <br />
288
- * Might be used to display additional information about the content of the field (E.g verified email)
289
- */
290
- badge: PropTypes__default["default"].node
159
+ id: _pt__default["default"].string,
160
+ horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
161
+ errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
162
+ renderError: _pt__default["default"].func,
163
+ isRequired: _pt__default["default"].bool,
164
+ touched: _pt__default["default"].bool,
165
+ name: _pt__default["default"].string,
166
+ value: _pt__default["default"].string.isRequired,
167
+ onChange: _pt__default["default"].func.isRequired,
168
+ onBlur: _pt__default["default"].func,
169
+ onFocus: _pt__default["default"].func,
170
+ isDisabled: _pt__default["default"].bool,
171
+ isReadOnly: _pt__default["default"].bool,
172
+ placeholder: _pt__default["default"].string,
173
+ minValue: _pt__default["default"].string,
174
+ maxValue: _pt__default["default"].string,
175
+ title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
176
+ hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
177
+ description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
178
+ onInfoButtonClick: _pt__default["default"].func,
179
+ hintIcon: _pt__default["default"].element,
180
+ badge: _pt__default["default"].node
291
181
  } : {};
292
182
  var DateField$1 = DateField;
293
183
 
294
184
  // NOTE: This string will be replaced on build time with the package version.
295
- var version = "12.2.6";
185
+ var version = "13.0.0";
296
186
 
297
187
  exports["default"] = DateField$1;
298
188
  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 utils = require('@commercetools-uikit/utils');
27
26
  var Constraints = require('@commercetools-uikit/constraints');
28
27
  var Spacings = require('@commercetools-uikit/spacings');
@@ -51,9 +50,9 @@ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
51
50
  var DateInput__default = /*#__PURE__*/_interopDefault(DateInput);
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
 
@@ -95,6 +94,11 @@ var DateField = /*#__PURE__*/function (_Component) {
95
94
  key: "render",
96
95
  value: function render() {
97
96
  var hasError = this.props.touched && hasErrors(this.props.errors);
97
+
98
+ if (!this.props.isReadOnly) ;
99
+
100
+ if (this.props.hintIcon) ;
101
+
98
102
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
99
103
  max: this.props.horizontalConstraint,
100
104
  children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
@@ -150,7 +154,7 @@ DateField.propTypes = {};
150
154
  var DateField$1 = DateField;
151
155
 
152
156
  // NOTE: This string will be replaced on build time with the package version.
153
- var version = "12.2.6";
157
+ var version = "13.0.0";
154
158
 
155
159
  exports["default"] = DateField$1;
156
160
  exports.version = version;
@@ -13,13 +13,12 @@ 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';
22
- import { createSequentialId, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
20
+ import { isValidElement, Component } from 'react';
21
+ import { createSequentialId, warning, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
23
22
  import Constraints from '@commercetools-uikit/constraints';
24
23
  import Spacings from '@commercetools-uikit/spacings';
25
24
  import FieldLabel from '@commercetools-uikit/field-label';
@@ -27,9 +26,9 @@ import DateInput from '@commercetools-uikit/date-input';
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
 
@@ -71,6 +70,15 @@ var DateField = /*#__PURE__*/function (_Component) {
71
70
  key: "render",
72
71
  value: function render() {
73
72
  var hasError = this.props.touched && hasErrors(this.props.errors);
73
+
74
+ if (!this.props.isReadOnly) {
75
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'DateField: `onChange` is required when field is not read only.') : void 0;
76
+ }
77
+
78
+ if (this.props.hintIcon) {
79
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(typeof this.props.hint), 'DateField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
80
+ }
81
+
74
82
  return jsx(Constraints.Horizontal, {
75
83
  max: this.props.horizontalConstraint,
76
84
  children: jsxs(Spacings.Stack, {
@@ -123,149 +131,32 @@ DateField.getDerivedStateFromProps = function (props, state) {
123
131
  };
124
132
 
125
133
  DateField.propTypes = process.env.NODE_ENV !== "production" ? {
126
- // DateField
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([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
- * 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.
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
- // DateInput
164
-
165
- /**
166
- * Used as HTML name of the input component.
167
- */
168
- name: PropTypes.string,
169
-
170
- /**
171
- * Value of the input
172
- */
173
- value: PropTypes.string.isRequired,
174
-
175
- /**
176
- * Called with an event containing the new value.
177
- * This is always called with either an empty string or a valid date in the format of `YYYY-MM-DD`.
178
- * <br/> Parent should pass it back as `value`.
179
- * <br/>
180
- * Signature: `(event) => void`
181
- */
182
- onChange: requiredIf(PropTypes.func, function (props) {
183
- return !props.isReadOnly;
184
- }),
185
-
186
- /**
187
- * Called when input is blurred
188
- * <br/>
189
- * Signature: `(event) => void`
190
- */
191
- onBlur: PropTypes.func,
192
-
193
- /**
194
- * Called when input is focused
195
- * <br/>
196
- * Signature: `(event) => void`
197
- */
198
- onFocus: PropTypes.func,
199
-
200
- /**
201
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
202
- */
203
- isDisabled: PropTypes.bool,
204
-
205
- /**
206
- * Indicates that the field is displaying read-only content
207
- */
208
- isReadOnly: PropTypes.bool,
209
-
210
- /**
211
- * Placeholder text for the input
212
- */
213
- placeholder: PropTypes.string,
214
-
215
- /**
216
- * A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
217
- */
218
- minValue: PropTypes.string,
219
-
220
- /**
221
- * A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
222
- */
223
- maxValue: PropTypes.string,
224
- // LabelField
225
-
226
- /**
227
- * Title of the label
228
- */
229
- title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
230
-
231
- /**
232
- * 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`.
233
- */
234
- hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
235
- return props.hintIcon;
236
- }),
237
-
238
- /**
239
- * Provides a description for the title.
240
- */
241
- description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
242
-
243
- /**
244
- * Function called when info button is pressed.
245
- * <br />
246
- * Info button will only be visible when this prop is passed.
247
- * <br />
248
- * Signature: `(event) => void`
249
- */
250
- onInfoButtonClick: PropTypes.func,
251
-
252
- /**
253
- * Icon to be displayed beside the hint text.
254
- * <br />
255
- * Will only get rendered when `hint` is passed as well.
256
- */
257
- hintIcon: PropTypes.node,
258
-
259
- /**
260
- * Badge to be displayed beside the label.
261
- * <br />
262
- * Might be used to display additional information about the content of the field (E.g verified email)
263
- */
264
- badge: PropTypes.node
134
+ id: _pt.string,
135
+ horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
136
+ errors: _pt.objectOf(_pt.bool),
137
+ renderError: _pt.func,
138
+ isRequired: _pt.bool,
139
+ touched: _pt.bool,
140
+ name: _pt.string,
141
+ value: _pt.string.isRequired,
142
+ onChange: _pt.func.isRequired,
143
+ onBlur: _pt.func,
144
+ onFocus: _pt.func,
145
+ isDisabled: _pt.bool,
146
+ isReadOnly: _pt.bool,
147
+ placeholder: _pt.string,
148
+ minValue: _pt.string,
149
+ maxValue: _pt.string,
150
+ title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
151
+ hint: _pt.oneOfType([_pt.string, _pt.node]),
152
+ description: _pt.oneOfType([_pt.string, _pt.node]),
153
+ onInfoButtonClick: _pt.func,
154
+ hintIcon: _pt.element,
155
+ badge: _pt.node
265
156
  } : {};
266
157
  var DateField$1 = DateField;
267
158
 
268
159
  // NOTE: This string will be replaced on build time with the package version.
269
- var version = "12.2.6";
160
+ var version = "13.0.0";
270
161
 
271
162
  export { DateField$1 as default, version };
@@ -0,0 +1,49 @@
1
+ import { Component, 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 TEvent = {
5
+ target: {
6
+ id?: string;
7
+ name?: string;
8
+ value?: string;
9
+ };
10
+ };
11
+ declare type TDateFieldProps = {
12
+ id?: string;
13
+ horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
14
+ errors?: TFieldErrors;
15
+ renderError?: TErrorRenderer;
16
+ isRequired?: boolean;
17
+ touched?: boolean;
18
+ name?: string;
19
+ value: string;
20
+ onChange: (event: TEvent) => void;
21
+ onBlur?: (event: TEvent) => void;
22
+ onFocus?: FocusEventHandler;
23
+ isDisabled?: boolean;
24
+ isReadOnly?: boolean;
25
+ placeholder?: string;
26
+ minValue?: string;
27
+ maxValue?: string;
28
+ title: string | ReactNode;
29
+ hint?: string | ReactNode;
30
+ description?: string | ReactNode;
31
+ onInfoButtonClick?: () => void;
32
+ hintIcon?: ReactElement;
33
+ badge?: ReactNode;
34
+ };
35
+ declare type TDateFieldState = Pick<TDateFieldProps, 'id'>;
36
+ declare class DateField extends Component<TDateFieldProps, TDateFieldState> {
37
+ static displayName: string;
38
+ static defaultProps: {
39
+ horizontalConstraint: string;
40
+ };
41
+ state: {
42
+ id: string | undefined;
43
+ };
44
+ static getDerivedStateFromProps: (props: TDateFieldProps, state: TDateFieldState) => {
45
+ id: string;
46
+ };
47
+ render(): import("@emotion/react/jsx-runtime").JSX.Element;
48
+ }
49
+ export default DateField;
@@ -0,0 +1,2 @@
1
+ export { default } from './date-field';
2
+ export { default as version } from './version';
@@ -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/date-field",
3
3
  "description": "A controlled date input component for single date, with validation states and a label.",
4
- "version": "12.2.6",
4
+ "version": "13.0.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -19,18 +19,18 @@
19
19
  "module": "dist/commercetools-uikit-date-field.esm.js",
20
20
  "files": ["dist"],
21
21
  "dependencies": {
22
- "@babel/runtime": "7.16.3",
23
- "@babel/runtime-corejs3": "7.16.3",
24
- "@commercetools-uikit/constraints": "12.2.5",
25
- "@commercetools-uikit/date-input": "12.2.6",
26
- "@commercetools-uikit/design-system": "12.2.5",
27
- "@commercetools-uikit/field-errors": "12.2.5",
28
- "@commercetools-uikit/field-label": "12.2.6",
29
- "@commercetools-uikit/spacings": "12.2.5",
30
- "@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/date-input": "13.0.0",
26
+ "@commercetools-uikit/design-system": "13.0.0",
27
+ "@commercetools-uikit/field-errors": "13.0.0",
28
+ "@commercetools-uikit/field-label": "13.0.0",
29
+ "@commercetools-uikit/spacings": "13.0.0",
30
+ "@commercetools-uikit/utils": "12.2.9",
31
31
  "@emotion/react": "^11.4.0",
32
32
  "@emotion/styled": "^11.3.0",
33
- "prop-types": "15.7.2",
33
+ "prop-types": "15.8.1",
34
34
  "react-required-if": "1.0.3"
35
35
  },
36
36
  "devDependencies": {