@commercetools-uikit/date-range-field 13.0.0 → 13.0.4
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 +39 -136
- package/dist/commercetools-uikit-date-range-field.cjs.prod.js +14 -5
- package/dist/commercetools-uikit-date-range-field.esm.js +40 -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 +8 -8
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,11 +41,10 @@ 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);
|
|
@@ -61,6 +59,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
61
59
|
|
|
62
60
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
63
61
|
var sequentialId = utils.createSequentialId('date-range-field-');
|
|
62
|
+
var sequentialErrorsId = utils.createSequentialId('date-range-field-error-')();
|
|
64
63
|
|
|
65
64
|
var hasErrors = function hasErrors(errors) {
|
|
66
65
|
var _context;
|
|
@@ -97,6 +96,15 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
97
96
|
key: "render",
|
|
98
97
|
value: function render() {
|
|
99
98
|
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
99
|
+
|
|
100
|
+
if (!this.props.isReadOnly) {
|
|
101
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'DateRangeField: `onChange` is required when field is not read only.') : void 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.props.hintIcon) {
|
|
105
|
+
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;
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
101
109
|
max: this.props.horizontalConstraint,
|
|
102
110
|
children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
|
|
@@ -110,7 +118,7 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
110
118
|
badge: this.props.badge,
|
|
111
119
|
hasRequiredIndicator: this.props.isRequired,
|
|
112
120
|
htmlFor: this.state.id
|
|
113
|
-
}), jsxRuntime.jsx(DateRangeInput__default["default"], _objectSpread({
|
|
121
|
+
}), jsxRuntime.jsx(DateRangeInput__default["default"], _objectSpread(_objectSpread({
|
|
114
122
|
id: this.state.id,
|
|
115
123
|
name: this.props.name,
|
|
116
124
|
value: this.props.value,
|
|
@@ -122,7 +130,11 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
122
130
|
hasError: hasError,
|
|
123
131
|
placeholder: this.props.placeholder,
|
|
124
132
|
horizontalConstraint: "scale"
|
|
125
|
-
}, utils.filterDataAttributes(this.props))
|
|
133
|
+
}, utils.filterDataAttributes(this.props)), {}, {
|
|
134
|
+
"aria-invalid": hasError,
|
|
135
|
+
"aria-errormessage": sequentialErrorsId
|
|
136
|
+
})), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
137
|
+
id: sequentialErrorsId,
|
|
126
138
|
errors: this.props.errors,
|
|
127
139
|
isVisible: hasError,
|
|
128
140
|
renderError: this.props.renderError
|
|
@@ -147,140 +159,31 @@ DateRangeField.getDerivedStateFromProps = function (props, state) {
|
|
|
147
159
|
};
|
|
148
160
|
|
|
149
161
|
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
|
|
162
|
+
id: _pt__default["default"].string,
|
|
163
|
+
horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
164
|
+
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
165
|
+
renderError: _pt__default["default"].func,
|
|
166
|
+
isRequired: _pt__default["default"].bool,
|
|
167
|
+
touched: _pt__default["default"].bool,
|
|
168
|
+
name: _pt__default["default"].string,
|
|
169
|
+
value: _pt__default["default"].arrayOf(_pt__default["default"].string).isRequired,
|
|
170
|
+
onChange: _pt__default["default"].func.isRequired,
|
|
171
|
+
onBlur: _pt__default["default"].func,
|
|
172
|
+
onFocus: _pt__default["default"].func,
|
|
173
|
+
isDisabled: _pt__default["default"].bool,
|
|
174
|
+
isReadOnly: _pt__default["default"].bool,
|
|
175
|
+
placeholder: _pt__default["default"].string,
|
|
176
|
+
title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
|
|
177
|
+
hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
178
|
+
description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
179
|
+
onInfoButtonClick: _pt__default["default"].func,
|
|
180
|
+
hintIcon: _pt__default["default"].element,
|
|
181
|
+
badge: _pt__default["default"].node
|
|
279
182
|
} : {};
|
|
280
183
|
var DateRangeField$1 = DateRangeField;
|
|
281
184
|
|
|
282
185
|
// NOTE: This string will be replaced on build time with the package version.
|
|
283
|
-
var version = "13.0.
|
|
186
|
+
var version = "13.0.4";
|
|
284
187
|
|
|
285
188
|
exports["default"] = DateRangeField$1;
|
|
286
189
|
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');
|
|
@@ -59,6 +58,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
59
58
|
|
|
60
59
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
60
|
var sequentialId = utils.createSequentialId('date-range-field-');
|
|
61
|
+
var sequentialErrorsId = utils.createSequentialId('date-range-field-error-')();
|
|
62
62
|
|
|
63
63
|
var hasErrors = function hasErrors(errors) {
|
|
64
64
|
var _context;
|
|
@@ -95,6 +95,11 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
95
95
|
key: "render",
|
|
96
96
|
value: function render() {
|
|
97
97
|
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
98
|
+
|
|
99
|
+
if (!this.props.isReadOnly) ;
|
|
100
|
+
|
|
101
|
+
if (this.props.hintIcon) ;
|
|
102
|
+
|
|
98
103
|
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
99
104
|
max: this.props.horizontalConstraint,
|
|
100
105
|
children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
|
|
@@ -108,7 +113,7 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
108
113
|
badge: this.props.badge,
|
|
109
114
|
hasRequiredIndicator: this.props.isRequired,
|
|
110
115
|
htmlFor: this.state.id
|
|
111
|
-
}), jsxRuntime.jsx(DateRangeInput__default["default"], _objectSpread({
|
|
116
|
+
}), jsxRuntime.jsx(DateRangeInput__default["default"], _objectSpread(_objectSpread({
|
|
112
117
|
id: this.state.id,
|
|
113
118
|
name: this.props.name,
|
|
114
119
|
value: this.props.value,
|
|
@@ -120,7 +125,11 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
120
125
|
hasError: hasError,
|
|
121
126
|
placeholder: this.props.placeholder,
|
|
122
127
|
horizontalConstraint: "scale"
|
|
123
|
-
}, utils.filterDataAttributes(this.props))
|
|
128
|
+
}, utils.filterDataAttributes(this.props)), {}, {
|
|
129
|
+
"aria-invalid": hasError,
|
|
130
|
+
"aria-errormessage": sequentialErrorsId
|
|
131
|
+
})), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
132
|
+
id: sequentialErrorsId,
|
|
124
133
|
errors: this.props.errors,
|
|
125
134
|
isVisible: hasError,
|
|
126
135
|
renderError: this.props.renderError
|
|
@@ -148,7 +157,7 @@ DateRangeField.propTypes = {};
|
|
|
148
157
|
var DateRangeField$1 = DateRangeField;
|
|
149
158
|
|
|
150
159
|
// NOTE: This string will be replaced on build time with the package version.
|
|
151
|
-
var version = "13.0.
|
|
160
|
+
var version = "13.0.4";
|
|
152
161
|
|
|
153
162
|
exports["default"] = DateRangeField$1;
|
|
154
163
|
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';
|
|
@@ -35,6 +34,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
35
34
|
|
|
36
35
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
37
36
|
var sequentialId = createSequentialId('date-range-field-');
|
|
37
|
+
var sequentialErrorsId = createSequentialId('date-range-field-error-')();
|
|
38
38
|
|
|
39
39
|
var hasErrors = function hasErrors(errors) {
|
|
40
40
|
var _context;
|
|
@@ -71,6 +71,15 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
71
71
|
key: "render",
|
|
72
72
|
value: function render() {
|
|
73
73
|
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
74
|
+
|
|
75
|
+
if (!this.props.isReadOnly) {
|
|
76
|
+
process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'DateRangeField: `onChange` is required when field is not read only.') : void 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (this.props.hintIcon) {
|
|
80
|
+
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;
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
return jsx(Constraints.Horizontal, {
|
|
75
84
|
max: this.props.horizontalConstraint,
|
|
76
85
|
children: jsxs(Spacings.Stack, {
|
|
@@ -84,7 +93,7 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
84
93
|
badge: this.props.badge,
|
|
85
94
|
hasRequiredIndicator: this.props.isRequired,
|
|
86
95
|
htmlFor: this.state.id
|
|
87
|
-
}), jsx(DateRangeInput, _objectSpread({
|
|
96
|
+
}), jsx(DateRangeInput, _objectSpread(_objectSpread({
|
|
88
97
|
id: this.state.id,
|
|
89
98
|
name: this.props.name,
|
|
90
99
|
value: this.props.value,
|
|
@@ -96,7 +105,11 @@ var DateRangeField = /*#__PURE__*/function (_Component) {
|
|
|
96
105
|
hasError: hasError,
|
|
97
106
|
placeholder: this.props.placeholder,
|
|
98
107
|
horizontalConstraint: "scale"
|
|
99
|
-
}, filterDataAttributes(this.props))
|
|
108
|
+
}, filterDataAttributes(this.props)), {}, {
|
|
109
|
+
"aria-invalid": hasError,
|
|
110
|
+
"aria-errormessage": sequentialErrorsId
|
|
111
|
+
})), jsx(FieldErrors, {
|
|
112
|
+
id: sequentialErrorsId,
|
|
100
113
|
errors: this.props.errors,
|
|
101
114
|
isVisible: hasError,
|
|
102
115
|
renderError: this.props.renderError
|
|
@@ -121,139 +134,30 @@ DateRangeField.getDerivedStateFromProps = function (props, state) {
|
|
|
121
134
|
};
|
|
122
135
|
|
|
123
136
|
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
|
|
137
|
+
id: _pt.string,
|
|
138
|
+
horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
139
|
+
errors: _pt.objectOf(_pt.bool),
|
|
140
|
+
renderError: _pt.func,
|
|
141
|
+
isRequired: _pt.bool,
|
|
142
|
+
touched: _pt.bool,
|
|
143
|
+
name: _pt.string,
|
|
144
|
+
value: _pt.arrayOf(_pt.string).isRequired,
|
|
145
|
+
onChange: _pt.func.isRequired,
|
|
146
|
+
onBlur: _pt.func,
|
|
147
|
+
onFocus: _pt.func,
|
|
148
|
+
isDisabled: _pt.bool,
|
|
149
|
+
isReadOnly: _pt.bool,
|
|
150
|
+
placeholder: _pt.string,
|
|
151
|
+
title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
|
|
152
|
+
hint: _pt.oneOfType([_pt.string, _pt.node]),
|
|
153
|
+
description: _pt.oneOfType([_pt.string, _pt.node]),
|
|
154
|
+
onInfoButtonClick: _pt.func,
|
|
155
|
+
hintIcon: _pt.element,
|
|
156
|
+
badge: _pt.node
|
|
253
157
|
} : {};
|
|
254
158
|
var DateRangeField$1 = DateRangeField;
|
|
255
159
|
|
|
256
160
|
// NOTE: This string will be replaced on build time with the package version.
|
|
257
|
-
var version = "13.0.
|
|
161
|
+
var version = "13.0.4";
|
|
258
162
|
|
|
259
163
|
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": "13.0.
|
|
4
|
+
"version": "13.0.4",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/runtime": "7.17.2",
|
|
23
23
|
"@babel/runtime-corejs3": "7.17.2",
|
|
24
|
-
"@commercetools-uikit/constraints": "13.0.
|
|
25
|
-
"@commercetools-uikit/date-range-input": "13.0.
|
|
24
|
+
"@commercetools-uikit/constraints": "13.0.2",
|
|
25
|
+
"@commercetools-uikit/date-range-input": "13.0.4",
|
|
26
26
|
"@commercetools-uikit/design-system": "13.0.0",
|
|
27
|
-
"@commercetools-uikit/field-errors": "13.0.
|
|
28
|
-
"@commercetools-uikit/field-label": "13.0.
|
|
29
|
-
"@commercetools-uikit/spacings": "13.0.
|
|
30
|
-
"@commercetools-uikit/utils": "
|
|
27
|
+
"@commercetools-uikit/field-errors": "13.0.4",
|
|
28
|
+
"@commercetools-uikit/field-label": "13.0.4",
|
|
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
33
|
"prop-types": "15.8.1",
|
|
34
|
-
"react-
|
|
34
|
+
"react-intl": "^5.24.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"react": "17.0.2"
|