@commercetools-uikit/date-range-input 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # DateRangeInput
5
+
6
+ ## Description
7
+
8
+ The `DateRangeInput` component allows the user to select a date range.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/date-range-input
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/date-range-input
18
+ ```
19
+
20
+ Additionally install the peer dependencies (if not present)
21
+
22
+ ```
23
+ yarn add moment react react-intl
24
+ ```
25
+
26
+ ```
27
+ npm --save install moment react react-intl
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```jsx
33
+ import DateRangeInput from '@commercetools-uikit/date-range-input';
34
+
35
+ const Example = () => (
36
+ <DateRangeInput
37
+ placeholder="Select a date..."
38
+ value={['2017-01-11', '2017-01-14']}
39
+ onChange={() => {}}
40
+ />
41
+ );
42
+
43
+ export default Example;
44
+ ```
45
+
46
+ ## Properties
47
+
48
+ | Props | Type | Required | Default | Description |
49
+ | ---------------------- | -------------------------------------------------------------------------------------------- | :------: | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
+ | `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | | Horizontal size limit of the input field. |
51
+ | `value` | `Array: MomentInput[]` | ✅ | | The selected date range, must either be an empty array or an array of two strings holding dates formatted as "YYYY-MM-DD". |
52
+ | `aria-invalid` | `boolean` | | | Indicate if the value entered in the input is invalid. |
53
+ | `aria-errormessage` | `string` | | | HTML ID of an element containing an error message related to the input. |
54
+ | `onChange` | `Function`<br/>[See signature.](#signature-onchange) | | | Called when the date range changes. Called with an event containing either an empty array (no value) or an array holding two string in this format: "YYYY-MM-DD". |
55
+ | `isClearable` | `boolean` | | `true` | Allows the range to be cleared |
56
+ | `onFocus` | `Function`<br/>[See signature.](#signature-onfocus) | | | Called when the date input gains focus. |
57
+ | `onBlur` | `Function`<br/>[See signature.](#signature-onblur) | | | Called when the date input loses focus. |
58
+ | `id` | `string` | | | Used as the HTML `id` attribute. |
59
+ | `name` | `string` | | | Used as the HTML `name` attribute. |
60
+ | `placeholder` | `string` | | | Placeholder value to show in the input field |
61
+ | `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
62
+ | `isDisabled` | `boolean` | | | Disables the date picker |
63
+ | `isReadOnly` | `boolean` | | | Disables the date picker menu and makes input field read-only |
64
+ | `hasError` | `boolean` | | | Indicates the input field has an error |
65
+ | `hasWarning` | `boolean` | | | Indicates the input field has warning |
66
+
67
+ ## Signatures
68
+
69
+ ### Signature `onChange`
70
+
71
+ ```ts
72
+ (event: TCustomEvent) => void
73
+ ```
74
+
75
+ ### Signature `onFocus`
76
+
77
+ ```ts
78
+ (event: TCustomEvent) => void
79
+ ```
80
+
81
+ ### Signature `onBlur`
82
+
83
+ ```ts
84
+ (event: TCustomEvent) => void
85
+ ```
86
+
87
+ ## `data-*` props
88
+
89
+ The component further forwards all `data-` attributes to the underlying `input` component.
90
+
91
+ ## Static methods
92
+
93
+ ### `DateRangeInput.isEmpty`
94
+
95
+ Returns `true` when the value is considered empty, which is when the value is an empty array.
96
+
97
+ ```js
98
+ TextInput.isEmpty([]); // -> true
99
+ TextInput.isEmpty(['2018-09-20', '2018-09-24']); // -> false
100
+ ```
@@ -0,0 +1,3 @@
1
+ export * from "./declarations/src/index.js";
2
+ export { default } from "./declarations/src/index.js";
3
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1kYXRlLXJhbmdlLWlucHV0LmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,459 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
6
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
7
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
8
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
9
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
10
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
11
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
12
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
13
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
15
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
16
+ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
17
+ var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
18
+ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
19
+ var _pt = require('prop-types');
20
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
21
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
22
+ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
23
+ var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
24
+ var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
25
+ var react = require('react');
26
+ var Downshift = require('downshift');
27
+ var reactIntl = require('react-intl');
28
+ var Constraints = require('@commercetools-uikit/constraints');
29
+ var utils = require('@commercetools-uikit/utils');
30
+ var calendarUtils = require('@commercetools-uikit/calendar-utils');
31
+ var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
32
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
33
+
34
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
35
+
36
+ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
37
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
38
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
39
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
40
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
41
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
42
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
43
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
44
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
45
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
46
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
47
+ var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
48
+ var _sortInstanceProperty__default = /*#__PURE__*/_interopDefault(_sortInstanceProperty);
49
+ var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
50
+ var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
51
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
52
+
53
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
54
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
55
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
56
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
57
+ const preventDownshiftDefault = event => {
58
+ event.nativeEvent.preventDownshiftDefault = true;
59
+ };
60
+ const parseRangeText = (text, locale) => {
61
+ var _context, _context2;
62
+ const parts = _filterInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = text.split(' - ')).call(_context2, part => {
63
+ const parsedDate = calendarUtils.parseInputToDate(_trimInstanceProperty__default["default"](part).call(part), locale);
64
+ return parsedDate === '' ? null : parsedDate;
65
+ })).call(_context, Boolean);
66
+ return parts;
67
+ };
68
+ const isSameRange = (a, b) => {
69
+ if (a.length !== b.length) return false;
70
+ if (a.length === 0) return true;
71
+ if (a[0] === b[0] && a[1] === b[1]) return true;
72
+ return false;
73
+ };
74
+ const getRange = _ref => {
75
+ let item = _ref.item,
76
+ value = _ref.value,
77
+ startDate = _ref.startDate,
78
+ highlightedItem = _ref.highlightedItem;
79
+ const isRangeSelectionInProgress = startDate;
80
+ const hasSelection = value.length === 2;
81
+ const isStartDate = calendarUtils.isSameDay(item, startDate);
82
+ const isBetween = highlightedItem && calendarUtils.isBetween(item, startDate, highlightedItem);
83
+ let isRangeStart = false;
84
+ if (isRangeSelectionInProgress) {
85
+ isRangeStart = isStartDate;
86
+ } else if (hasSelection) {
87
+ isRangeStart = value[0] === item;
88
+ }
89
+ let isRangeBetween = false;
90
+ if (isRangeSelectionInProgress) {
91
+ isRangeBetween = isBetween;
92
+ } else if (hasSelection) {
93
+ isRangeBetween = calendarUtils.isBetween(item, value[0], value[1]);
94
+ }
95
+ let isRangeEnd = false;
96
+ if (isRangeSelectionInProgress) {
97
+ isRangeEnd = item === highlightedItem;
98
+ } else if (hasSelection) {
99
+ isRangeEnd = value[1] === item;
100
+ }
101
+ return {
102
+ isRangeStart,
103
+ isRangeBetween,
104
+ isRangeEnd
105
+ };
106
+ };
107
+ let DateRangeInput = /*#__PURE__*/function (_Component) {
108
+ function DateRangeInput() {
109
+ var _this;
110
+ _classCallCheck(this, DateRangeInput);
111
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
112
+ args[_key] = arguments[_key];
113
+ }
114
+ _this = _callSuper(this, DateRangeInput, [...args]);
115
+ _this.inputRef = /*#__PURE__*/react.createRef();
116
+ _this.state = {
117
+ calendarDate: _this.props.value.length === 2 ? _this.props.value[0] : calendarUtils.getToday(),
118
+ suggestedItems: [],
119
+ startDate: null,
120
+ highlightedIndex: null,
121
+ isOpen: false,
122
+ inputValue: calendarUtils.formatRange(_this.props.value, _this.props.intl.locale),
123
+ prevValue: _this.props.value,
124
+ prevLocale: _this.props.intl.locale
125
+ };
126
+ _this.jumpMonth = function (amount) {
127
+ let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
128
+ _this.setState(prevState => {
129
+ const nextDate = calendarUtils.changeMonth(prevState.calendarDate, amount);
130
+ return {
131
+ calendarDate: nextDate,
132
+ highlightedIndex: dayToHighlight
133
+ };
134
+ });
135
+ };
136
+ _this.showToday = () => {
137
+ const today = calendarUtils.getToday();
138
+ _this.setState(prevState => ({
139
+ calendarDate: today,
140
+ highlightedIndex: prevState.suggestedItems.length + calendarUtils.getDateInMonth(today) - 1
141
+ }), () => _this.inputRef.current?.focus());
142
+ };
143
+ _this.handleBlur = () => {
144
+ if (_this.props.onBlur) _this.props.onBlur({
145
+ target: {
146
+ id: _this.props.id,
147
+ name: _this.props.name
148
+ }
149
+ });
150
+ };
151
+ _this.emit = unsortedRange => {
152
+ _this.props.onChange?.({
153
+ target: {
154
+ id: _this.props.id,
155
+ name: _this.props.name,
156
+ value: _sortInstanceProperty__default["default"](unsortedRange).call(unsortedRange)
157
+ }
158
+ });
159
+ };
160
+ return _this;
161
+ }
162
+ _inherits(DateRangeInput, _Component);
163
+ return _createClass(DateRangeInput, [{
164
+ key: "render",
165
+ value: function render() {
166
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
167
+ max: this.props.horizontalConstraint,
168
+ children: jsxRuntime.jsx(Downshift__default["default"], {
169
+ inputId: this.props.id,
170
+ itemToString: calendarUtils.createItemRangeToString(this.props.intl.locale),
171
+ inputValue: this.state.inputValue,
172
+ selectedItem: null,
173
+ highlightedIndex: this.state.highlightedIndex,
174
+ onInputValueChange: (inputValue, changes) => {
175
+ // only attempt to parse input when the user typed into the input
176
+ // field
177
+ // @ts-ignore
178
+ if (changes.type !== Downshift__default["default"].stateChangeTypes.changeInput) return;
179
+ this.setState(() => {
180
+ const parsedRange = parseRangeText(inputValue, this.props.intl.locale);
181
+ if (parsedRange.length === 0) return {
182
+ suggestedItems: [],
183
+ highlightedIndex: null,
184
+ inputValue,
185
+ startDate: null
186
+ };
187
+ if (parsedRange.length === 1) {
188
+ const calendarDate = parsedRange[0];
189
+ return {
190
+ suggestedItems: [],
191
+ highlightedIndex: calendarUtils.getDateInMonth(calendarDate) - 1,
192
+ inputValue,
193
+ startDate: parsedRange[0],
194
+ calendarDate
195
+ };
196
+ }
197
+ if (parsedRange.length === 2) {
198
+ const calendarDate = parsedRange[1];
199
+ return {
200
+ suggestedItems: [],
201
+ highlightedIndex: calendarUtils.getDateInMonth(calendarDate) - 1,
202
+ inputValue,
203
+ startDate: parsedRange[0],
204
+ calendarDate
205
+ };
206
+ }
207
+ return null;
208
+ });
209
+ },
210
+ onStateChange: changes => {
211
+ this.setState(prevState => {
212
+ if (changes.type === Downshift__default["default"].stateChangeTypes.mouseUp || changes.type === Downshift__default["default"].stateChangeTypes.blurInput) {
213
+ return {
214
+ highlightedIndex: null,
215
+ isOpen: false,
216
+ inputValue: calendarUtils.formatRange(this.props.value, this.props.intl.locale)
217
+ };
218
+ }
219
+ if (changes.hasOwnProperty('selectedItem')) {
220
+ const hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
221
+ const hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
222
+ return {
223
+ highlightedIndex: prevState.highlightedIndex,
224
+ startDate: prevState.startDate ? null : changes.selectedItem,
225
+ calendarDate: changes.selectedItem,
226
+ isOpen: !hasFinishedRangeSelection,
227
+ inputValue: (() => {
228
+ if (hasFinishedRangeSelection) {
229
+ return calendarUtils.formatRange([prevState.startDate, changes.selectedItem], this.props.intl.locale);
230
+ }
231
+ if (hasStartedRangeSelection) {
232
+ return calendarUtils.formatRange([changes.selectedItem], this.props.intl.locale);
233
+ }
234
+ return '';
235
+ })()
236
+ };
237
+ }
238
+ if (changes.hasOwnProperty('isOpen')) {
239
+ return {
240
+ isOpen: changes.isOpen,
241
+ highlightedIndex: changes.highlightedIndex || null,
242
+ inputValue: changes.inputValue || prevState.inputValue,
243
+ // Reset range selection progress when menu opens/closes
244
+ startDate: null,
245
+ // Ensure calendar opens on selected date.
246
+ // Open on the current day as a fallback.
247
+ calendarDate: this.props.value.length === 2 ? this.props.value[0] : calendarUtils.getToday()
248
+ };
249
+ }
250
+ if (changes.hasOwnProperty('highlightedIndex')) {
251
+ return {
252
+ highlightedIndex: changes.highlightedIndex
253
+ };
254
+ }
255
+ return null;
256
+ });
257
+ },
258
+ onChange: selectedItem => {
259
+ if (this.state.startDate && selectedItem) {
260
+ this.emit([this.state.startDate, selectedItem]);
261
+ } else {
262
+ this.emit([]);
263
+ }
264
+ },
265
+ isOpen: this.state.isOpen,
266
+ children: _ref2 => {
267
+ var _context3;
268
+ let getInputProps = _ref2.getInputProps,
269
+ getMenuProps = _ref2.getMenuProps,
270
+ getItemProps = _ref2.getItemProps,
271
+ getToggleButtonProps = _ref2.getToggleButtonProps,
272
+ clearSelection = _ref2.clearSelection,
273
+ highlightedIndex = _ref2.highlightedIndex,
274
+ openMenu = _ref2.openMenu,
275
+ setHighlightedIndex = _ref2.setHighlightedIndex,
276
+ isOpen = _ref2.isOpen,
277
+ inputValue = _ref2.inputValue;
278
+ const calendarItems = calendarUtils.createCalendarItems(this.state.calendarDate);
279
+ const allItems = [...this.state.suggestedItems, ...calendarItems];
280
+ const paddingDayCount = calendarUtils.getPaddingDayCount(this.state.calendarDate, this.props.intl.locale);
281
+ const paddingDays = _fillInstanceProperty__default["default"](_context3 = Array(paddingDayCount)).call(_context3, undefined);
282
+ const weekdays = calendarUtils.getWeekdayNames(this.props.intl.locale);
283
+ const today = calendarUtils.getToday();
284
+ return jsxRuntime.jsxs("div", {
285
+ onFocus: this.props.onFocus,
286
+ onBlur: this.handleBlur,
287
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
288
+ inputRef: this.inputRef,
289
+ inputProps: getInputProps(_objectSpread({
290
+ /* ARIA */
291
+ 'aria-invalid': this.props['aria-invalid'],
292
+ 'aria-errormessage': this.props['aria-errormessage'],
293
+ // Unset the aria-labelledby as it interfers with the link
294
+ // between the <label for> and the <input id>.
295
+ 'aria-labelledby': undefined,
296
+ name: this.props.name,
297
+ placeholder: typeof this.props.placeholder === 'string' ? this.props.placeholder : `${calendarTimeUtils.getLocalizedDateTimeFormatPattern(this.props.intl.locale)} - ${calendarTimeUtils.getLocalizedDateTimeFormatPattern(this.props.intl.locale)}`,
298
+ onMouseEnter: () => {
299
+ // we remove the highlight so that the user can use the
300
+ // arrow keys to move the cursor when hovering
301
+ // @ts-ignore
302
+ if (isOpen) setHighlightedIndex(null);
303
+ },
304
+ onKeyDown: event => {
305
+ if (this.props.isReadOnly) {
306
+ preventDownshiftDefault(event);
307
+ return;
308
+ }
309
+ if (event.key === 'Enter' && inputValue?.trim() === '' &&
310
+ // do not clear value when user presses Enter to
311
+ // select the end date (so only clear when there is no
312
+ // startDate)
313
+ !this.state.startDate && this.props.isClearable) {
314
+ clearSelection();
315
+ this.emit([]);
316
+ }
317
+ // ArrowDown
318
+ if (event.key === 'ArrowDown') {
319
+ if (highlightedIndex + 1 >= calendarItems.length) {
320
+ // if it's the end of the month
321
+ // then bypass normal arrow navigation
322
+ preventDownshiftDefault(event);
323
+ // then jump to start of next month
324
+ this.jumpMonth(1, 0);
325
+ }
326
+ }
327
+ // ArrowUp
328
+ if (event.key === 'ArrowUp') {
329
+ const previousDay = calendarUtils.getPreviousDay(calendarItems[highlightedIndex]);
330
+ if (highlightedIndex <= 0) {
331
+ // if it's the start of the month
332
+ // then bypass normal arrow navigation
333
+ preventDownshiftDefault(event);
334
+ const numberOfDaysOfPrevMonth = calendarUtils.getDaysInMonth(previousDay);
335
+ // then jump to the last day of the previous month
336
+ this.jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
337
+ }
338
+ }
339
+ },
340
+ // we only do this for readOnly because the input
341
+ // doesn't ignore these events, unlike when its disabled
342
+ onClick: this.props.isReadOnly ? undefined : openMenu
343
+ }, utils.filterDataAttributes(this.props))),
344
+ hasSelection: this.props.value.length === 2,
345
+ isClearable: this.props.isClearable,
346
+ onClear: () => {
347
+ this.setState({
348
+ startDate: null
349
+ });
350
+ this.emit([]);
351
+ clearSelection();
352
+ },
353
+ isOpen: isOpen,
354
+ isDisabled: this.props.isDisabled,
355
+ isReadOnly: this.props.isReadOnly,
356
+ isCondensed: this.props.isCondensed,
357
+ toggleButtonProps: getToggleButtonProps(),
358
+ hasError: this.props.hasError,
359
+ hasWarning: this.props.hasWarning
360
+ }), isOpen && !this.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
361
+ hasError: this.props.hasError,
362
+ hasWarning: this.props.hasWarning,
363
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
364
+ monthLabel: calendarUtils.getMonthCalendarLabel(this.state.calendarDate, this.props.intl.locale),
365
+ yearLabel: calendarUtils.getYearCalendarLabel(this.state.calendarDate, this.props.intl.locale),
366
+ onPrevMonthClick: () => this.jumpMonth(-1),
367
+ onTodayClick: this.showToday,
368
+ onNextMonthClick: () => this.jumpMonth(1),
369
+ onPrevYearClick: () => this.jumpMonth(-12),
370
+ onNextYearClick: () => this.jumpMonth(12)
371
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
372
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, weekday => jsxRuntime.jsx(calendarUtils.CalendarDay, {
373
+ type: "heading",
374
+ children: weekday
375
+ }, weekday)), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, (_, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, {
376
+ type: "spacing"
377
+ }, index)), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, (item, index) => {
378
+ const isHighlighted = this.state.suggestedItems.length + index === highlightedIndex;
379
+ const _getRange = getRange({
380
+ item,
381
+ value: this.props.value,
382
+ startDate: this.state.startDate,
383
+ highlightedItem: allItems[this.state.highlightedIndex || 0]
384
+ }),
385
+ isRangeStart = _getRange.isRangeStart,
386
+ isRangeBetween = _getRange.isRangeBetween,
387
+ isRangeEnd = _getRange.isRangeEnd;
388
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
389
+ isToday: calendarUtils.isSameDay(today, item)
390
+ }, getItemProps({
391
+ disabled: this.props.isDisabled,
392
+ item,
393
+ onMouseOut: () => {
394
+ // @ts-ignore
395
+ setHighlightedIndex(null);
396
+ }
397
+ })), {}, {
398
+ isHighlighted: isHighlighted,
399
+ isRangeStart: isRangeStart,
400
+ isRangeBetween: isRangeBetween,
401
+ isRangeEnd: isRangeEnd,
402
+ children: calendarUtils.getCalendarDayLabel(item)
403
+ }), item);
404
+ })]
405
+ })]
406
+ }))]
407
+ });
408
+ }
409
+ }, this.props.intl.locale)
410
+ });
411
+ }
412
+ }], [{
413
+ key: "getDerivedStateFromProps",
414
+ value: function getDerivedStateFromProps(props, state) {
415
+ // We need to update the input value string in case so that is is formatted
416
+ // according to the locale and holds the current value in case the value
417
+ // changes or when the locale changes
418
+ const shouldUpdateInputValue = !isSameRange(props.value, state.prevValue) || props.intl.locale !== state.prevLocale;
419
+ if (!shouldUpdateInputValue) return null;
420
+ return {
421
+ prevLocale: props.intl.locale,
422
+ // This is not the input value but the actual value passed to
423
+ // DateRangeInput
424
+ prevValue: props.value,
425
+ inputValue: calendarUtils.formatRange(props.value, props.intl.locale)
426
+ };
427
+ }
428
+ }]);
429
+ }(react.Component);
430
+ DateRangeInput.displayName = 'DateRangeInput';
431
+ DateRangeInput.defaultProps = {
432
+ isClearable: true
433
+ };
434
+ DateRangeInput.isEmpty = range => range.length === 0;
435
+ DateRangeInput.propTypes = process.env.NODE_ENV !== "production" ? {
436
+ horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
437
+ value: _pt__default["default"].arrayOf(_pt__default["default"].any).isRequired,
438
+ 'aria-invalid': _pt__default["default"].bool,
439
+ 'aria-errormessage': _pt__default["default"].string,
440
+ onChange: _pt__default["default"].func,
441
+ isClearable: _pt__default["default"].bool,
442
+ onFocus: _pt__default["default"].func,
443
+ onBlur: _pt__default["default"].func,
444
+ id: _pt__default["default"].string,
445
+ name: _pt__default["default"].string,
446
+ placeholder: _pt__default["default"].string,
447
+ isCondensed: _pt__default["default"].bool,
448
+ isDisabled: _pt__default["default"].bool,
449
+ isReadOnly: _pt__default["default"].bool,
450
+ hasError: _pt__default["default"].bool,
451
+ hasWarning: _pt__default["default"].bool
452
+ } : {};
453
+ var dateRangeInput = reactIntl.injectIntl(DateRangeInput);
454
+
455
+ // NOTE: This string will be replaced on build time with the package version.
456
+ var version = "19.25.1";
457
+
458
+ exports["default"] = dateRangeInput;
459
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-uikit-date-range-input.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-date-range-input.cjs.dev.js");
7
+ }