@commercetools-uikit/date-range-field 12.2.8 → 13.0.2
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 +54 -23
- package/dist/commercetools-uikit-date-range-field.cjs.d.ts +2 -0
- package/dist/commercetools-uikit-date-range-field.cjs.dev.js +34 -136
- package/dist/commercetools-uikit-date-range-field.cjs.prod.js +9 -5
- package/dist/commercetools-uikit-date-range-field.esm.js +35 -136
- package/dist/declarations/src/date-range-field.d.ts +46 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -45,29 +45,60 @@ export default Example;
|
|
|
45
45
|
|
|
46
46
|
## Properties
|
|
47
47
|
|
|
48
|
-
| Props | Type
|
|
49
|
-
| ---------------------- |
|
|
50
|
-
| `id` | `string`
|
|
51
|
-
| `horizontalConstraint` | `
|
|
52
|
-
| `errors` | `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
|
|
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.
<br />
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` | `Array: string[]` | ✅ | | The selected date range. Must either be an empty array or an array of two strings holding dates formatted as "YYYY-MM-DD". |
|
|
58
|
+
| `onChange` | `Function`<br/>[See signature.](#signature-onChange) | ✅ | | Called when the date range changes, with an event containing either an empty array (no value) or an array holding two string in this format: "YYYY-MM-DD".
<br/>
Required when input is not read only. |
|
|
59
|
+
| `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Called when input is blurred |
|
|
60
|
+
| `onFocus` | `Function`<br/>[See signature.](#signature-onFocus) | | | 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
|
+
| `title` | `union`<br/>Possible values:<br/>`string , ReactNode` | ✅ | | Title of the label |
|
|
65
|
+
| `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`. |
|
|
66
|
+
| `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
|
|
67
|
+
| `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.
<br />
Info button will only be visible when this prop is passed. |
|
|
68
|
+
| `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.
<br />
Will only get rendered when `hint` is passed as well. |
|
|
69
|
+
| `badge` | `ReactNode` | | | Badge to be displayed beside the label.
<br />
Might be used to display additional information about the content of the field (E.g verified email) |
|
|
70
|
+
|
|
71
|
+
## Signatures
|
|
72
|
+
|
|
73
|
+
### Signature `renderError`
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
(key: string, error?: boolean) => ReactNode;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Signature `onChange`
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
(event: TEvent) => void
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Signature `onBlur`
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
(event: TEvent) => void
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Signature `onFocus`
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
(event: TEvent) => void
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Signature `onInfoButtonClick`
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
() => void
|
|
101
|
+
```
|
|
71
102
|
|
|
72
103
|
## `data-*` props
|
|
73
104
|
|
|
@@ -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 DateRangeInput__default = /*#__PURE__*/_interopDefault(DateRangeInput);
|
|
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);
|
|
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]
|
|
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 DateRangeField = /*#__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', 'DateRangeField: `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(this.props.hint), 'DateRangeField: `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, {
|
|
@@ -147,140 +154,31 @@ DateRangeField.getDerivedStateFromProps = function (props, state) {
|
|
|
147
154
|
};
|
|
148
155
|
|
|
149
156
|
DateRangeField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 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.
|
|
173
|
-
* <br />
|
|
174
|
-
* Signature: `(key, error) => React.node`
|
|
175
|
-
*/
|
|
176
|
-
renderError: PropTypes__default["default"].func,
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
180
|
-
*/
|
|
181
|
-
isRequired: PropTypes__default["default"].bool,
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
185
|
-
*/
|
|
186
|
-
touched: PropTypes__default["default"].bool,
|
|
187
|
-
// DateRangeInput
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Used as HTML name of the input component.
|
|
191
|
-
*/
|
|
192
|
-
name: PropTypes__default["default"].string,
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* The selected date range. Must either be an empty array or an array of two strings holding dates formatted as "YYYY-MM-DD".
|
|
196
|
-
*/
|
|
197
|
-
value: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string).isRequired,
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Called when the date range changes, with an event containing either an empty array (no value) or an array holding two string in this format: "YYYY-MM-DD".
|
|
201
|
-
* <br/>
|
|
202
|
-
* Required when input is not read only.
|
|
203
|
-
* <br />
|
|
204
|
-
* Signature: `(event) => void`
|
|
205
|
-
*/
|
|
206
|
-
onChange: requiredIf__default["default"](PropTypes__default["default"].func, function (props) {
|
|
207
|
-
return !props.isReadOnly;
|
|
208
|
-
}),
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Called when input is blurred
|
|
212
|
-
* <br/>
|
|
213
|
-
* Signature: `(event) => void`
|
|
214
|
-
*/
|
|
215
|
-
onBlur: PropTypes__default["default"].func,
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Called when input is focused
|
|
219
|
-
* <br/>
|
|
220
|
-
* Signature: `(event) => void`
|
|
221
|
-
*/
|
|
222
|
-
onFocus: PropTypes__default["default"].func,
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
|
|
226
|
-
*/
|
|
227
|
-
isDisabled: PropTypes__default["default"].bool,
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Indicates that the field is displaying read-only content
|
|
231
|
-
*/
|
|
232
|
-
isReadOnly: PropTypes__default["default"].bool,
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Placeholder text for the input
|
|
236
|
-
*/
|
|
237
|
-
placeholder: PropTypes__default["default"].string,
|
|
238
|
-
// LabelField
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Title of the label
|
|
242
|
-
*/
|
|
243
|
-
title: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]).isRequired,
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* 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`.
|
|
247
|
-
*/
|
|
248
|
-
hint: requiredIf__default["default"](PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]), function (props) {
|
|
249
|
-
return props.hintIcon;
|
|
250
|
-
}),
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Provides a description for the title.
|
|
254
|
-
*/
|
|
255
|
-
description: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]),
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Function called when info button is pressed.
|
|
259
|
-
* <br />
|
|
260
|
-
* Info button will only be visible when this prop is passed.
|
|
261
|
-
* <br />
|
|
262
|
-
* Signature: `(event) => void`
|
|
263
|
-
*/
|
|
264
|
-
onInfoButtonClick: PropTypes__default["default"].func,
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Icon to be displayed beside the hint text.
|
|
268
|
-
* <br />
|
|
269
|
-
* Will only get rendered when `hint` is passed as well.
|
|
270
|
-
*/
|
|
271
|
-
hintIcon: PropTypes__default["default"].node,
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Badge to be displayed beside the label.
|
|
275
|
-
* <br />
|
|
276
|
-
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
277
|
-
*/
|
|
278
|
-
badge: PropTypes__default["default"].node
|
|
157
|
+
id: _pt__default["default"].string,
|
|
158
|
+
horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
159
|
+
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
160
|
+
renderError: _pt__default["default"].func,
|
|
161
|
+
isRequired: _pt__default["default"].bool,
|
|
162
|
+
touched: _pt__default["default"].bool,
|
|
163
|
+
name: _pt__default["default"].string,
|
|
164
|
+
value: _pt__default["default"].arrayOf(_pt__default["default"].string).isRequired,
|
|
165
|
+
onChange: _pt__default["default"].func.isRequired,
|
|
166
|
+
onBlur: _pt__default["default"].func,
|
|
167
|
+
onFocus: _pt__default["default"].func,
|
|
168
|
+
isDisabled: _pt__default["default"].bool,
|
|
169
|
+
isReadOnly: _pt__default["default"].bool,
|
|
170
|
+
placeholder: _pt__default["default"].string,
|
|
171
|
+
title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
|
|
172
|
+
hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
173
|
+
description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
174
|
+
onInfoButtonClick: _pt__default["default"].func,
|
|
175
|
+
hintIcon: _pt__default["default"].element,
|
|
176
|
+
badge: _pt__default["default"].node
|
|
279
177
|
} : {};
|
|
280
178
|
var DateRangeField$1 = DateRangeField;
|
|
281
179
|
|
|
282
180
|
// NOTE: This string will be replaced on build time with the package version.
|
|
283
|
-
var version = "
|
|
181
|
+
var version = "13.0.2";
|
|
284
182
|
|
|
285
183
|
exports["default"] = DateRangeField$1;
|
|
286
184
|
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 DateRangeInput__default = /*#__PURE__*/_interopDefault(DateRangeInput);
|
|
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);
|
|
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]
|
|
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 DateRangeField = /*#__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, {
|
|
@@ -148,7 +152,7 @@ DateRangeField.propTypes = {};
|
|
|
148
152
|
var DateRangeField$1 = DateRangeField;
|
|
149
153
|
|
|
150
154
|
// NOTE: This string will be replaced on build time with the package version.
|
|
151
|
-
var version = "
|
|
155
|
+
var version = "13.0.2";
|
|
152
156
|
|
|
153
157
|
exports["default"] = DateRangeField$1;
|
|
154
158
|
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
|
|
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 DateRangeInput from '@commercetools-uikit/date-range-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);
|
|
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]
|
|
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 DateRangeField = /*#__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', 'DateRangeField: `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(this.props.hint), 'DateRangeField: `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, {
|
|
@@ -121,139 +129,30 @@ DateRangeField.getDerivedStateFromProps = function (props, state) {
|
|
|
121
129
|
};
|
|
122
130
|
|
|
123
131
|
DateRangeField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 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.
|
|
147
|
-
* <br />
|
|
148
|
-
* Signature: `(key, error) => React.node`
|
|
149
|
-
*/
|
|
150
|
-
renderError: PropTypes.func,
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
154
|
-
*/
|
|
155
|
-
isRequired: PropTypes.bool,
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
159
|
-
*/
|
|
160
|
-
touched: PropTypes.bool,
|
|
161
|
-
// DateRangeInput
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Used as HTML name of the input component.
|
|
165
|
-
*/
|
|
166
|
-
name: PropTypes.string,
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* The selected date range. Must either be an empty array or an array of two strings holding dates formatted as "YYYY-MM-DD".
|
|
170
|
-
*/
|
|
171
|
-
value: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Called when the date range changes, with an event containing either an empty array (no value) or an array holding two string in this format: "YYYY-MM-DD".
|
|
175
|
-
* <br/>
|
|
176
|
-
* Required when input is not read only.
|
|
177
|
-
* <br />
|
|
178
|
-
* Signature: `(event) => void`
|
|
179
|
-
*/
|
|
180
|
-
onChange: requiredIf(PropTypes.func, function (props) {
|
|
181
|
-
return !props.isReadOnly;
|
|
182
|
-
}),
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Called when input is blurred
|
|
186
|
-
* <br/>
|
|
187
|
-
* Signature: `(event) => void`
|
|
188
|
-
*/
|
|
189
|
-
onBlur: PropTypes.func,
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Called when input is focused
|
|
193
|
-
* <br/>
|
|
194
|
-
* Signature: `(event) => void`
|
|
195
|
-
*/
|
|
196
|
-
onFocus: PropTypes.func,
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
|
|
200
|
-
*/
|
|
201
|
-
isDisabled: PropTypes.bool,
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Indicates that the field is displaying read-only content
|
|
205
|
-
*/
|
|
206
|
-
isReadOnly: PropTypes.bool,
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Placeholder text for the input
|
|
210
|
-
*/
|
|
211
|
-
placeholder: PropTypes.string,
|
|
212
|
-
// LabelField
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Title of the label
|
|
216
|
-
*/
|
|
217
|
-
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 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`.
|
|
221
|
-
*/
|
|
222
|
-
hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
|
|
223
|
-
return props.hintIcon;
|
|
224
|
-
}),
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Provides a description for the title.
|
|
228
|
-
*/
|
|
229
|
-
description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Function called when info button is pressed.
|
|
233
|
-
* <br />
|
|
234
|
-
* Info button will only be visible when this prop is passed.
|
|
235
|
-
* <br />
|
|
236
|
-
* Signature: `(event) => void`
|
|
237
|
-
*/
|
|
238
|
-
onInfoButtonClick: PropTypes.func,
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Icon to be displayed beside the hint text.
|
|
242
|
-
* <br />
|
|
243
|
-
* Will only get rendered when `hint` is passed as well.
|
|
244
|
-
*/
|
|
245
|
-
hintIcon: PropTypes.node,
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Badge to be displayed beside the label.
|
|
249
|
-
* <br />
|
|
250
|
-
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
251
|
-
*/
|
|
252
|
-
badge: PropTypes.node
|
|
132
|
+
id: _pt.string,
|
|
133
|
+
horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
134
|
+
errors: _pt.objectOf(_pt.bool),
|
|
135
|
+
renderError: _pt.func,
|
|
136
|
+
isRequired: _pt.bool,
|
|
137
|
+
touched: _pt.bool,
|
|
138
|
+
name: _pt.string,
|
|
139
|
+
value: _pt.arrayOf(_pt.string).isRequired,
|
|
140
|
+
onChange: _pt.func.isRequired,
|
|
141
|
+
onBlur: _pt.func,
|
|
142
|
+
onFocus: _pt.func,
|
|
143
|
+
isDisabled: _pt.bool,
|
|
144
|
+
isReadOnly: _pt.bool,
|
|
145
|
+
placeholder: _pt.string,
|
|
146
|
+
title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
|
|
147
|
+
hint: _pt.oneOfType([_pt.string, _pt.node]),
|
|
148
|
+
description: _pt.oneOfType([_pt.string, _pt.node]),
|
|
149
|
+
onInfoButtonClick: _pt.func,
|
|
150
|
+
hintIcon: _pt.element,
|
|
151
|
+
badge: _pt.node
|
|
253
152
|
} : {};
|
|
254
153
|
var DateRangeField$1 = DateRangeField;
|
|
255
154
|
|
|
256
155
|
// NOTE: This string will be replaced on build time with the package version.
|
|
257
|
-
var version = "
|
|
156
|
+
var version = "13.0.2";
|
|
258
157
|
|
|
259
158
|
export { DateRangeField$1 as default, version };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Component, type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { MomentInput } from 'moment';
|
|
3
|
+
declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
4
|
+
declare type TFieldErrors = Record<string, boolean>;
|
|
5
|
+
declare type TEvent = {
|
|
6
|
+
target: {
|
|
7
|
+
id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
value?: MomentInput[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare type TDateRangeFieldProps = {
|
|
13
|
+
id?: string;
|
|
14
|
+
horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
15
|
+
errors?: TFieldErrors;
|
|
16
|
+
renderError?: TErrorRenderer;
|
|
17
|
+
isRequired?: boolean;
|
|
18
|
+
touched?: boolean;
|
|
19
|
+
name?: string;
|
|
20
|
+
value: string[];
|
|
21
|
+
onChange: (event: TEvent) => void;
|
|
22
|
+
onBlur?: (event: TEvent) => void;
|
|
23
|
+
onFocus?: (event: TEvent) => void;
|
|
24
|
+
isDisabled?: boolean;
|
|
25
|
+
isReadOnly?: boolean;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
title: string | ReactNode;
|
|
28
|
+
hint?: string | ReactNode;
|
|
29
|
+
description?: string | ReactNode;
|
|
30
|
+
onInfoButtonClick?: () => void;
|
|
31
|
+
hintIcon?: ReactElement;
|
|
32
|
+
badge?: ReactNode;
|
|
33
|
+
};
|
|
34
|
+
declare type TDateRangeFieldState = Pick<TDateRangeFieldProps, 'id'>;
|
|
35
|
+
declare class DateRangeField extends Component<TDateRangeFieldProps, TDateRangeFieldState> {
|
|
36
|
+
static displayName: string;
|
|
37
|
+
static defaultProps: Pick<TDateRangeFieldProps, 'horizontalConstraint'>;
|
|
38
|
+
state: {
|
|
39
|
+
id: string | undefined;
|
|
40
|
+
};
|
|
41
|
+
static getDerivedStateFromProps: (props: TDateRangeFieldProps, state: TDateRangeFieldState) => {
|
|
42
|
+
id: string;
|
|
43
|
+
};
|
|
44
|
+
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
45
|
+
}
|
|
46
|
+
export default DateRangeField;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/date-range-field",
|
|
3
3
|
"description": "A controlled date input component for a date range, with validation states and a label.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "13.0.2",
|
|
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-range-field.esm.js",
|
|
20
20
|
"files": ["dist"],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/runtime": "7.
|
|
23
|
-
"@babel/runtime-corejs3": "7.
|
|
24
|
-
"@commercetools-uikit/constraints": "
|
|
25
|
-
"@commercetools-uikit/date-range-input": "
|
|
26
|
-
"@commercetools-uikit/design-system": "
|
|
27
|
-
"@commercetools-uikit/field-errors": "
|
|
28
|
-
"@commercetools-uikit/field-label": "
|
|
29
|
-
"@commercetools-uikit/spacings": "
|
|
30
|
-
"@commercetools-uikit/utils": "
|
|
22
|
+
"@babel/runtime": "7.17.2",
|
|
23
|
+
"@babel/runtime-corejs3": "7.17.2",
|
|
24
|
+
"@commercetools-uikit/constraints": "13.0.2",
|
|
25
|
+
"@commercetools-uikit/date-range-input": "13.0.2",
|
|
26
|
+
"@commercetools-uikit/design-system": "13.0.0",
|
|
27
|
+
"@commercetools-uikit/field-errors": "13.0.2",
|
|
28
|
+
"@commercetools-uikit/field-label": "13.0.2",
|
|
29
|
+
"@commercetools-uikit/spacings": "13.0.2",
|
|
30
|
+
"@commercetools-uikit/utils": "13.0.2",
|
|
31
31
|
"@emotion/react": "^11.4.0",
|
|
32
32
|
"@emotion/styled": "^11.3.0",
|
|
33
|
-
"prop-types": "15.
|
|
33
|
+
"prop-types": "15.8.1",
|
|
34
34
|
"react-required-if": "1.0.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|