@commercetools-uikit/date-range-input 12.2.2 → 12.2.6
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.
|
@@ -6,7 +6,6 @@ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/inst
|
|
|
6
6
|
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
7
7
|
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
8
8
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
9
|
-
import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
|
|
10
9
|
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
11
10
|
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
12
11
|
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
@@ -20,14 +19,14 @@ import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instanc
|
|
|
20
19
|
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
21
20
|
import _sortInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/sort';
|
|
22
21
|
import _fillInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/fill';
|
|
23
|
-
import
|
|
22
|
+
import { createRef, Component } from 'react';
|
|
24
23
|
import PropTypes from 'prop-types';
|
|
25
24
|
import Downshift from 'downshift';
|
|
26
25
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
27
26
|
import Constraints from '@commercetools-uikit/constraints';
|
|
28
27
|
import { filterDataAttributes } from '@commercetools-uikit/utils';
|
|
29
28
|
import { getToday, formatRange, changeMonth, getDateInMonth, createItemRangeToString, createCalendarItems, getPaddingDayCount, getWeekdayNames, CalendarBody, getPreviousDay, getDaysInMonth, CalendarMenu, CalendarHeader, getMonthCalendarLabel, getYearCalendarLabel, CalendarContent, CalendarDay, isSameDay, getCalendarDayLabel, parseInputToDate, isBetween } from '@commercetools-uikit/calendar-utils';
|
|
30
|
-
import { jsx } from '@emotion/react';
|
|
29
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
31
30
|
|
|
32
31
|
var messages = defineMessages({
|
|
33
32
|
placeholder: {
|
|
@@ -108,8 +107,8 @@ var getRange = function getRange(_ref) {
|
|
|
108
107
|
};
|
|
109
108
|
};
|
|
110
109
|
|
|
111
|
-
var DateRangeCalendar = /*#__PURE__*/function (
|
|
112
|
-
_inherits(DateRangeCalendar,
|
|
110
|
+
var DateRangeCalendar = /*#__PURE__*/function (_Component) {
|
|
111
|
+
_inherits(DateRangeCalendar, _Component);
|
|
113
112
|
|
|
114
113
|
var _super = _createSuper(DateRangeCalendar);
|
|
115
114
|
|
|
@@ -125,7 +124,7 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
_this = _super.call.apply(_super, _concatInstanceProperty(_context3 = [this]).call(_context3, args));
|
|
128
|
-
_this.inputRef = /*#__PURE__*/
|
|
127
|
+
_this.inputRef = /*#__PURE__*/createRef();
|
|
129
128
|
_this.state = {
|
|
130
129
|
calendarDate: _this.props.value.length === 2 ? _this.props.value[0] : getToday(),
|
|
131
130
|
suggestedItems: [],
|
|
@@ -190,278 +189,282 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
190
189
|
var _this2 = this;
|
|
191
190
|
|
|
192
191
|
return jsx(Constraints.Horizontal, {
|
|
193
|
-
max: this.props.horizontalConstraint
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (parsedRange.length === 0) return {
|
|
209
|
-
suggestedItems: [],
|
|
210
|
-
highlightedIndex: null,
|
|
211
|
-
inputValue: inputValue,
|
|
212
|
-
startDate: null
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
if (parsedRange.length === 1) {
|
|
216
|
-
var calendarDate = parsedRange[0];
|
|
217
|
-
return {
|
|
192
|
+
max: this.props.horizontalConstraint,
|
|
193
|
+
children: jsx(Downshift, {
|
|
194
|
+
inputId: this.props.id,
|
|
195
|
+
itemToString: createItemRangeToString(this.props.intl.locale),
|
|
196
|
+
inputValue: this.state.inputValue,
|
|
197
|
+
selectedItem: null,
|
|
198
|
+
highlightedIndex: this.state.highlightedIndex,
|
|
199
|
+
onInputValueChange: function onInputValueChange(inputValue, changes) {
|
|
200
|
+
// only attempt to parse input when the user typed into the input
|
|
201
|
+
// field
|
|
202
|
+
if (changes.type !== Downshift.stateChangeTypes.changeInput) return;
|
|
203
|
+
|
|
204
|
+
_this2.setState(function () {
|
|
205
|
+
var parsedRange = parseRangeText(inputValue, _this2.props.intl.locale);
|
|
206
|
+
if (parsedRange.length === 0) return {
|
|
218
207
|
suggestedItems: [],
|
|
219
|
-
highlightedIndex: getDateInMonth(calendarDate) - 1,
|
|
220
|
-
inputValue: inputValue,
|
|
221
|
-
startDate: parsedRange[0],
|
|
222
|
-
calendarDate: calendarDate
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (parsedRange.length === 2) {
|
|
227
|
-
var _calendarDate = parsedRange[1];
|
|
228
|
-
return {
|
|
229
|
-
suggestedItems: [],
|
|
230
|
-
highlightedIndex: getDateInMonth(_calendarDate) - 1,
|
|
231
|
-
inputValue: inputValue,
|
|
232
|
-
startDate: parsedRange[0],
|
|
233
|
-
calendarDate: _calendarDate
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return null;
|
|
238
|
-
});
|
|
239
|
-
},
|
|
240
|
-
onStateChange: function onStateChange(changes) {
|
|
241
|
-
/* eslint-disable no-prototype-builtins */
|
|
242
|
-
_this2.setState(function (prevState) {
|
|
243
|
-
// ensure input value matches prop value when menu is closed
|
|
244
|
-
if (changes.type === Downshift.stateChangeTypes.mouseUp || changes.type === Downshift.stateChangeTypes.blurInput) {
|
|
245
|
-
return {
|
|
246
208
|
highlightedIndex: null,
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (changes.hasOwnProperty('selectedItem')) {
|
|
253
|
-
var hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
|
|
254
|
-
var hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
|
|
255
|
-
return {
|
|
256
|
-
highlightedIndex: prevState.highlightedIndex,
|
|
257
|
-
startDate: prevState.startDate ? null : changes.selectedItem,
|
|
258
|
-
calendarDate: changes.selectedItem,
|
|
259
|
-
isOpen: !hasFinishedRangeSelection,
|
|
260
|
-
inputValue: function () {
|
|
261
|
-
if (hasFinishedRangeSelection) {
|
|
262
|
-
return formatRange([prevState.startDate, changes.selectedItem], _this2.props.intl.locale);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (hasStartedRangeSelection) {
|
|
266
|
-
return formatRange([changes.selectedItem], _this2.props.intl.locale);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return '';
|
|
270
|
-
}()
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (changes.hasOwnProperty('isOpen')) {
|
|
275
|
-
return {
|
|
276
|
-
isOpen: changes.isOpen,
|
|
277
|
-
highlightedIndex: changes.highlightedIndex || null,
|
|
278
|
-
inputValue: changes.inputValue || prevState.inputValue,
|
|
279
|
-
// Reset range selection progress when menu opens/closes
|
|
280
|
-
startDate: null,
|
|
281
|
-
// Ensure calendar opens on selected date.
|
|
282
|
-
// Open on the current day as a fallback.
|
|
283
|
-
calendarDate: _this2.props.value.length === 2 ? _this2.props.value[0] : getToday()
|
|
209
|
+
inputValue: inputValue,
|
|
210
|
+
startDate: null
|
|
284
211
|
};
|
|
285
|
-
}
|
|
286
212
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
onChange: function onChange(selectedItem) {
|
|
299
|
-
if (_this2.state.startDate && selectedItem) {
|
|
300
|
-
_this2.emit([_this2.state.startDate, selectedItem]);
|
|
301
|
-
} else {
|
|
302
|
-
_this2.emit([]);
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
isOpen: this.state.isOpen
|
|
306
|
-
}, function (_ref2) {
|
|
307
|
-
var _context4, _context5;
|
|
308
|
-
|
|
309
|
-
var getInputProps = _ref2.getInputProps,
|
|
310
|
-
getMenuProps = _ref2.getMenuProps,
|
|
311
|
-
getItemProps = _ref2.getItemProps,
|
|
312
|
-
getToggleButtonProps = _ref2.getToggleButtonProps,
|
|
313
|
-
clearSelection = _ref2.clearSelection,
|
|
314
|
-
highlightedIndex = _ref2.highlightedIndex,
|
|
315
|
-
openMenu = _ref2.openMenu,
|
|
316
|
-
setHighlightedIndex = _ref2.setHighlightedIndex,
|
|
317
|
-
isOpen = _ref2.isOpen,
|
|
318
|
-
inputValue = _ref2.inputValue;
|
|
319
|
-
var calendarItems = createCalendarItems(_this2.state.calendarDate, _this2.props.intl);
|
|
320
|
-
|
|
321
|
-
var allItems = _concatInstanceProperty(_context4 = []).call(_context4, _toConsumableArray(_this2.state.suggestedItems), _toConsumableArray(calendarItems));
|
|
322
|
-
|
|
323
|
-
var paddingDayCount = getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale);
|
|
324
|
-
|
|
325
|
-
var paddingDays = _fillInstanceProperty(_context5 = Array(paddingDayCount)).call(_context5);
|
|
326
|
-
|
|
327
|
-
var weekdays = getWeekdayNames(_this2.props.intl.locale);
|
|
328
|
-
var today = getToday();
|
|
329
|
-
return jsx("div", {
|
|
330
|
-
onFocus: _this2.props.onFocus,
|
|
331
|
-
onBlur: _this2.handleBlur
|
|
332
|
-
}, jsx(CalendarBody, {
|
|
333
|
-
inputRef: _this2.inputRef,
|
|
334
|
-
inputProps: getInputProps(_objectSpread({
|
|
335
|
-
// Unset the aria-labelledby as it interfers with the link
|
|
336
|
-
// between the <label for> and the <input id>.
|
|
337
|
-
'aria-labelledby': undefined,
|
|
338
|
-
name: _this2.props.name,
|
|
339
|
-
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
340
|
-
onMouseEnter: function onMouseEnter() {
|
|
341
|
-
// we remove the highlight so that the user can use the
|
|
342
|
-
// arrow keys to move the cursor when hovering
|
|
343
|
-
if (isOpen) setHighlightedIndex(null);
|
|
344
|
-
},
|
|
345
|
-
onKeyDown: function onKeyDown(event) {
|
|
346
|
-
if (_this2.props.isReadOnly) {
|
|
347
|
-
preventDownshiftDefault(event);
|
|
348
|
-
return;
|
|
213
|
+
if (parsedRange.length === 1) {
|
|
214
|
+
var calendarDate = parsedRange[0];
|
|
215
|
+
return {
|
|
216
|
+
suggestedItems: [],
|
|
217
|
+
highlightedIndex: getDateInMonth(calendarDate) - 1,
|
|
218
|
+
inputValue: inputValue,
|
|
219
|
+
startDate: parsedRange[0],
|
|
220
|
+
calendarDate: calendarDate
|
|
221
|
+
};
|
|
349
222
|
}
|
|
350
223
|
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (event.keyCode === 40) {
|
|
362
|
-
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
363
|
-
// if it's the end of the month
|
|
364
|
-
// then bypass normal arrow navigation
|
|
365
|
-
preventDownshiftDefault(event); // then jump to start of next month
|
|
366
|
-
|
|
367
|
-
_this2.jumpMonth(1, 0);
|
|
368
|
-
}
|
|
369
|
-
} // ArrowUp
|
|
224
|
+
if (parsedRange.length === 2) {
|
|
225
|
+
var _calendarDate = parsedRange[1];
|
|
226
|
+
return {
|
|
227
|
+
suggestedItems: [],
|
|
228
|
+
highlightedIndex: getDateInMonth(_calendarDate) - 1,
|
|
229
|
+
inputValue: inputValue,
|
|
230
|
+
startDate: parsedRange[0],
|
|
231
|
+
calendarDate: _calendarDate
|
|
232
|
+
};
|
|
233
|
+
}
|
|
370
234
|
|
|
235
|
+
return null;
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
onStateChange: function onStateChange(changes) {
|
|
239
|
+
/* eslint-disable no-prototype-builtins */
|
|
240
|
+
_this2.setState(function (prevState) {
|
|
241
|
+
// ensure input value matches prop value when menu is closed
|
|
242
|
+
if (changes.type === Downshift.stateChangeTypes.mouseUp || changes.type === Downshift.stateChangeTypes.blurInput) {
|
|
243
|
+
return {
|
|
244
|
+
highlightedIndex: null,
|
|
245
|
+
isOpen: false,
|
|
246
|
+
inputValue: formatRange(_this2.props.value, _this2.props.intl.locale)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
371
249
|
|
|
372
|
-
if (
|
|
373
|
-
var
|
|
250
|
+
if (changes.hasOwnProperty('selectedItem')) {
|
|
251
|
+
var hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
|
|
252
|
+
var hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
|
|
253
|
+
return {
|
|
254
|
+
highlightedIndex: prevState.highlightedIndex,
|
|
255
|
+
startDate: prevState.startDate ? null : changes.selectedItem,
|
|
256
|
+
calendarDate: changes.selectedItem,
|
|
257
|
+
isOpen: !hasFinishedRangeSelection,
|
|
258
|
+
inputValue: function () {
|
|
259
|
+
if (hasFinishedRangeSelection) {
|
|
260
|
+
return formatRange([prevState.startDate, changes.selectedItem], _this2.props.intl.locale);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (hasStartedRangeSelection) {
|
|
264
|
+
return formatRange([changes.selectedItem], _this2.props.intl.locale);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return '';
|
|
268
|
+
}()
|
|
269
|
+
};
|
|
270
|
+
}
|
|
374
271
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
272
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
273
|
+
return {
|
|
274
|
+
isOpen: changes.isOpen,
|
|
275
|
+
highlightedIndex: changes.highlightedIndex || null,
|
|
276
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
277
|
+
// Reset range selection progress when menu opens/closes
|
|
278
|
+
startDate: null,
|
|
279
|
+
// Ensure calendar opens on selected date.
|
|
280
|
+
// Open on the current day as a fallback.
|
|
281
|
+
calendarDate: _this2.props.value.length === 2 ? _this2.props.value[0] : getToday()
|
|
282
|
+
};
|
|
283
|
+
}
|
|
380
284
|
|
|
381
|
-
|
|
382
|
-
|
|
285
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
286
|
+
return {
|
|
287
|
+
highlightedIndex: changes.highlightedIndex
|
|
288
|
+
};
|
|
383
289
|
}
|
|
384
|
-
},
|
|
385
|
-
// we only do this for readOnly because the input
|
|
386
|
-
// doesn't ignore these events, unlike when its disabled
|
|
387
|
-
onClick: _this2.props.isReadOnly ? undefined : openMenu
|
|
388
|
-
}, filterDataAttributes(_this2.props))),
|
|
389
|
-
hasSelection: _this2.props.value.length === 2,
|
|
390
|
-
isClearable: _this2.props.isClearable,
|
|
391
|
-
onClear: function onClear() {
|
|
392
|
-
_this2.setState({
|
|
393
|
-
startDate: null
|
|
394
|
-
});
|
|
395
290
|
|
|
396
|
-
|
|
291
|
+
return null;
|
|
292
|
+
});
|
|
293
|
+
/* eslint-enable no-prototype-builtins */
|
|
397
294
|
|
|
398
|
-
clearSelection();
|
|
399
|
-
},
|
|
400
|
-
isOpen: isOpen,
|
|
401
|
-
isDisabled: _this2.props.isDisabled,
|
|
402
|
-
isReadOnly: _this2.props.isReadOnly,
|
|
403
|
-
toggleButtonProps: getToggleButtonProps(),
|
|
404
|
-
hasError: _this2.props.hasError,
|
|
405
|
-
hasWarning: _this2.props.hasWarning
|
|
406
|
-
}), isOpen && !_this2.props.isDisabled && jsx(CalendarMenu, _extends({}, getMenuProps(), {
|
|
407
|
-
hasError: _this2.props.hasError,
|
|
408
|
-
hasWarning: _this2.props.hasWarning
|
|
409
|
-
}), jsx(CalendarHeader, {
|
|
410
|
-
monthLabel: getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
411
|
-
yearLabel: getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
412
|
-
onPrevMonthClick: function onPrevMonthClick() {
|
|
413
|
-
return _this2.jumpMonth(-1);
|
|
414
|
-
},
|
|
415
|
-
onTodayClick: _this2.showToday,
|
|
416
|
-
onNextMonthClick: function onNextMonthClick() {
|
|
417
|
-
return _this2.jumpMonth(1);
|
|
418
295
|
},
|
|
419
|
-
|
|
420
|
-
|
|
296
|
+
onChange: function onChange(selectedItem) {
|
|
297
|
+
if (_this2.state.startDate && selectedItem) {
|
|
298
|
+
_this2.emit([_this2.state.startDate, selectedItem]);
|
|
299
|
+
} else {
|
|
300
|
+
_this2.emit([]);
|
|
301
|
+
}
|
|
421
302
|
},
|
|
422
|
-
|
|
423
|
-
|
|
303
|
+
isOpen: this.state.isOpen,
|
|
304
|
+
children: function children(_ref2) {
|
|
305
|
+
var _context4, _context5;
|
|
306
|
+
|
|
307
|
+
var getInputProps = _ref2.getInputProps,
|
|
308
|
+
getMenuProps = _ref2.getMenuProps,
|
|
309
|
+
getItemProps = _ref2.getItemProps,
|
|
310
|
+
getToggleButtonProps = _ref2.getToggleButtonProps,
|
|
311
|
+
clearSelection = _ref2.clearSelection,
|
|
312
|
+
highlightedIndex = _ref2.highlightedIndex,
|
|
313
|
+
openMenu = _ref2.openMenu,
|
|
314
|
+
setHighlightedIndex = _ref2.setHighlightedIndex,
|
|
315
|
+
isOpen = _ref2.isOpen,
|
|
316
|
+
inputValue = _ref2.inputValue;
|
|
317
|
+
var calendarItems = createCalendarItems(_this2.state.calendarDate, _this2.props.intl);
|
|
318
|
+
|
|
319
|
+
var allItems = _concatInstanceProperty(_context4 = []).call(_context4, _toConsumableArray(_this2.state.suggestedItems), _toConsumableArray(calendarItems));
|
|
320
|
+
|
|
321
|
+
var paddingDayCount = getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale);
|
|
322
|
+
|
|
323
|
+
var paddingDays = _fillInstanceProperty(_context5 = Array(paddingDayCount)).call(_context5);
|
|
324
|
+
|
|
325
|
+
var weekdays = getWeekdayNames(_this2.props.intl.locale);
|
|
326
|
+
var today = getToday();
|
|
327
|
+
return jsxs("div", {
|
|
328
|
+
onFocus: _this2.props.onFocus,
|
|
329
|
+
onBlur: _this2.handleBlur,
|
|
330
|
+
children: [jsx(CalendarBody, {
|
|
331
|
+
inputRef: _this2.inputRef,
|
|
332
|
+
inputProps: getInputProps(_objectSpread({
|
|
333
|
+
// Unset the aria-labelledby as it interfers with the link
|
|
334
|
+
// between the <label for> and the <input id>.
|
|
335
|
+
'aria-labelledby': undefined,
|
|
336
|
+
name: _this2.props.name,
|
|
337
|
+
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
338
|
+
onMouseEnter: function onMouseEnter() {
|
|
339
|
+
// we remove the highlight so that the user can use the
|
|
340
|
+
// arrow keys to move the cursor when hovering
|
|
341
|
+
if (isOpen) setHighlightedIndex(null);
|
|
342
|
+
},
|
|
343
|
+
onKeyDown: function onKeyDown(event) {
|
|
344
|
+
if (_this2.props.isReadOnly) {
|
|
345
|
+
preventDownshiftDefault(event);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (event.key === 'Enter' && _trimInstanceProperty(inputValue).call(inputValue) === '' && // do not clear value when user presses Enter to
|
|
350
|
+
// select the end date (so only clear when there is no
|
|
351
|
+
// startDate)
|
|
352
|
+
!_this2.state.startDate && _this2.props.isClearable) {
|
|
353
|
+
clearSelection();
|
|
354
|
+
|
|
355
|
+
_this2.emit([]);
|
|
356
|
+
} // ArrowDown
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
if (event.keyCode === 40) {
|
|
360
|
+
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
361
|
+
// if it's the end of the month
|
|
362
|
+
// then bypass normal arrow navigation
|
|
363
|
+
preventDownshiftDefault(event); // then jump to start of next month
|
|
364
|
+
|
|
365
|
+
_this2.jumpMonth(1, 0);
|
|
366
|
+
}
|
|
367
|
+
} // ArrowUp
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
if (event.keyCode === 38) {
|
|
371
|
+
var previousDay = getPreviousDay(calendarItems[highlightedIndex]);
|
|
372
|
+
|
|
373
|
+
if (highlightedIndex <= 0) {
|
|
374
|
+
// if it's the start of the month
|
|
375
|
+
// then bypass normal arrow navigation
|
|
376
|
+
preventDownshiftDefault(event);
|
|
377
|
+
var numberOfDaysOfPrevMonth = getDaysInMonth(previousDay); // then jump to the last day of the previous month
|
|
378
|
+
|
|
379
|
+
_this2.jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
// we only do this for readOnly because the input
|
|
384
|
+
// doesn't ignore these events, unlike when its disabled
|
|
385
|
+
onClick: _this2.props.isReadOnly ? undefined : openMenu
|
|
386
|
+
}, filterDataAttributes(_this2.props))),
|
|
387
|
+
hasSelection: _this2.props.value.length === 2,
|
|
388
|
+
isClearable: _this2.props.isClearable,
|
|
389
|
+
onClear: function onClear() {
|
|
390
|
+
_this2.setState({
|
|
391
|
+
startDate: null
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
_this2.emit([]);
|
|
395
|
+
|
|
396
|
+
clearSelection();
|
|
397
|
+
},
|
|
398
|
+
isOpen: isOpen,
|
|
399
|
+
isDisabled: _this2.props.isDisabled,
|
|
400
|
+
isReadOnly: _this2.props.isReadOnly,
|
|
401
|
+
toggleButtonProps: getToggleButtonProps(),
|
|
402
|
+
hasError: _this2.props.hasError,
|
|
403
|
+
hasWarning: _this2.props.hasWarning
|
|
404
|
+
}), isOpen && !_this2.props.isDisabled && jsxs(CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
|
|
405
|
+
hasError: _this2.props.hasError,
|
|
406
|
+
hasWarning: _this2.props.hasWarning,
|
|
407
|
+
children: [jsx(CalendarHeader, {
|
|
408
|
+
monthLabel: getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
409
|
+
yearLabel: getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
410
|
+
onPrevMonthClick: function onPrevMonthClick() {
|
|
411
|
+
return _this2.jumpMonth(-1);
|
|
412
|
+
},
|
|
413
|
+
onTodayClick: _this2.showToday,
|
|
414
|
+
onNextMonthClick: function onNextMonthClick() {
|
|
415
|
+
return _this2.jumpMonth(1);
|
|
416
|
+
},
|
|
417
|
+
onPrevYearClick: function onPrevYearClick() {
|
|
418
|
+
return _this2.jumpMonth(-12);
|
|
419
|
+
},
|
|
420
|
+
onNextYearClick: function onNextYearClick() {
|
|
421
|
+
return _this2.jumpMonth(12);
|
|
422
|
+
}
|
|
423
|
+
}), jsxs(CalendarContent, {
|
|
424
|
+
children: [_mapInstanceProperty(weekdays).call(weekdays, function (weekday) {
|
|
425
|
+
return jsx(CalendarDay, {
|
|
426
|
+
type: "heading",
|
|
427
|
+
children: weekday
|
|
428
|
+
}, weekday);
|
|
429
|
+
}), _mapInstanceProperty(paddingDays).call(paddingDays, function (day, index) {
|
|
430
|
+
return jsx(CalendarDay, {
|
|
431
|
+
type: "spacing"
|
|
432
|
+
}, index);
|
|
433
|
+
}), _mapInstanceProperty(calendarItems).call(calendarItems, function (item, index) {
|
|
434
|
+
var isHighlighted = _this2.state.suggestedItems.length + index === highlightedIndex;
|
|
435
|
+
|
|
436
|
+
var _getRange = getRange({
|
|
437
|
+
item: item,
|
|
438
|
+
value: _this2.props.value,
|
|
439
|
+
startDate: _this2.state.startDate,
|
|
440
|
+
highlightedItem: allItems[_this2.state.highlightedIndex]
|
|
441
|
+
}),
|
|
442
|
+
isRangeStart = _getRange.isRangeStart,
|
|
443
|
+
isRangeBetween = _getRange.isRangeBetween,
|
|
444
|
+
isRangeEnd = _getRange.isRangeEnd;
|
|
445
|
+
|
|
446
|
+
return jsx(CalendarDay, _objectSpread(_objectSpread({
|
|
447
|
+
isToday: isSameDay(today, item)
|
|
448
|
+
}, getItemProps({
|
|
449
|
+
disabled: _this2.props.isDisabled,
|
|
450
|
+
item: item,
|
|
451
|
+
onMouseOut: function onMouseOut() {
|
|
452
|
+
setHighlightedIndex(null);
|
|
453
|
+
}
|
|
454
|
+
})), {}, {
|
|
455
|
+
isHighlighted: isHighlighted,
|
|
456
|
+
isRangeStart: isRangeStart,
|
|
457
|
+
isRangeBetween: isRangeBetween,
|
|
458
|
+
isRangeEnd: isRangeEnd,
|
|
459
|
+
children: getCalendarDayLabel(item)
|
|
460
|
+
}), item);
|
|
461
|
+
})]
|
|
462
|
+
})]
|
|
463
|
+
}))]
|
|
464
|
+
});
|
|
424
465
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
key: weekday,
|
|
428
|
-
type: "heading"
|
|
429
|
-
}, weekday);
|
|
430
|
-
}), _mapInstanceProperty(paddingDays).call(paddingDays, function (day, index) {
|
|
431
|
-
return jsx(CalendarDay, {
|
|
432
|
-
key: index,
|
|
433
|
-
type: "spacing"
|
|
434
|
-
});
|
|
435
|
-
}), _mapInstanceProperty(calendarItems).call(calendarItems, function (item, index) {
|
|
436
|
-
var isHighlighted = _this2.state.suggestedItems.length + index === highlightedIndex;
|
|
437
|
-
|
|
438
|
-
var _getRange = getRange({
|
|
439
|
-
item: item,
|
|
440
|
-
value: _this2.props.value,
|
|
441
|
-
startDate: _this2.state.startDate,
|
|
442
|
-
highlightedItem: allItems[_this2.state.highlightedIndex]
|
|
443
|
-
}),
|
|
444
|
-
isRangeStart = _getRange.isRangeStart,
|
|
445
|
-
isRangeBetween = _getRange.isRangeBetween,
|
|
446
|
-
isRangeEnd = _getRange.isRangeEnd;
|
|
447
|
-
|
|
448
|
-
return jsx(CalendarDay, _extends({
|
|
449
|
-
key: item,
|
|
450
|
-
isToday: isSameDay(today, item)
|
|
451
|
-
}, getItemProps({
|
|
452
|
-
disabled: _this2.props.isDisabled,
|
|
453
|
-
item: item,
|
|
454
|
-
onMouseOut: function onMouseOut() {
|
|
455
|
-
setHighlightedIndex(null);
|
|
456
|
-
}
|
|
457
|
-
}), {
|
|
458
|
-
isHighlighted: isHighlighted,
|
|
459
|
-
isRangeStart: isRangeStart,
|
|
460
|
-
isRangeBetween: isRangeBetween,
|
|
461
|
-
isRangeEnd: isRangeEnd
|
|
462
|
-
}), getCalendarDayLabel(item));
|
|
463
|
-
}))));
|
|
464
|
-
}));
|
|
466
|
+
}, this.props.intl.locale)
|
|
467
|
+
});
|
|
465
468
|
}
|
|
466
469
|
}], [{
|
|
467
470
|
key: "getDerivedStateFromProps",
|
|
@@ -482,7 +485,7 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
482
485
|
}]);
|
|
483
486
|
|
|
484
487
|
return DateRangeCalendar;
|
|
485
|
-
}(
|
|
488
|
+
}(Component);
|
|
486
489
|
|
|
487
490
|
DateRangeCalendar.displayName = 'DateRangeCalendar';
|
|
488
491
|
DateRangeCalendar.defaultProps = {
|
|
@@ -568,7 +571,7 @@ DateRangeCalendar.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
568
571
|
} : {};
|
|
569
572
|
var dateRangeInput = injectIntl(DateRangeCalendar);
|
|
570
573
|
|
|
571
|
-
// NOTE: This string will be replaced
|
|
572
|
-
var version =
|
|
574
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
575
|
+
var version = "12.2.6";
|
|
573
576
|
|
|
574
577
|
export { dateRangeInput as default, version };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/date-range-input",
|
|
3
3
|
"description": "The `DateRangeInput` component allows the user to select a date range.",
|
|
4
|
-
"version": "12.2.
|
|
4
|
+
"version": "12.2.6",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"homepage": "https://uikit.commercetools.com",
|
|
12
12
|
"keywords": ["javascript", "design system", "react", "uikit"],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"private": false,
|
|
15
14
|
"publishConfig": {
|
|
16
15
|
"access": "public"
|
|
17
16
|
},
|
|
@@ -19,28 +18,25 @@
|
|
|
19
18
|
"main": "dist/commercetools-uikit-date-range-input.cjs.js",
|
|
20
19
|
"module": "dist/commercetools-uikit-date-range-input.esm.js",
|
|
21
20
|
"files": ["dist"],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"prepare": "../../../../scripts/version.js replace"
|
|
24
|
-
},
|
|
25
21
|
"dependencies": {
|
|
26
|
-
"@babel/runtime": "7.
|
|
27
|
-
"@babel/runtime-corejs3": "7.
|
|
28
|
-
"@commercetools-uikit/accessible-button": "12.2.
|
|
29
|
-
"@commercetools-uikit/calendar-utils": "12.2.
|
|
30
|
-
"@commercetools-uikit/constraints": "12.2.
|
|
31
|
-
"@commercetools-uikit/design-system": "12.2.
|
|
32
|
-
"@commercetools-uikit/hooks": "12.2.
|
|
33
|
-
"@commercetools-uikit/icons": "12.2.
|
|
34
|
-
"@commercetools-uikit/secondary-icon-button": "12.2.
|
|
35
|
-
"@commercetools-uikit/select-utils": "12.2.
|
|
36
|
-
"@commercetools-uikit/spacings-inline": "12.2.
|
|
37
|
-
"@commercetools-uikit/text": "12.2.
|
|
38
|
-
"@commercetools-uikit/tooltip": "12.2.
|
|
39
|
-
"@commercetools-uikit/utils": "12.2.
|
|
22
|
+
"@babel/runtime": "7.16.3",
|
|
23
|
+
"@babel/runtime-corejs3": "7.16.3",
|
|
24
|
+
"@commercetools-uikit/accessible-button": "12.2.5",
|
|
25
|
+
"@commercetools-uikit/calendar-utils": "12.2.6",
|
|
26
|
+
"@commercetools-uikit/constraints": "12.2.5",
|
|
27
|
+
"@commercetools-uikit/design-system": "12.2.5",
|
|
28
|
+
"@commercetools-uikit/hooks": "12.2.5",
|
|
29
|
+
"@commercetools-uikit/icons": "12.2.6",
|
|
30
|
+
"@commercetools-uikit/secondary-icon-button": "12.2.5",
|
|
31
|
+
"@commercetools-uikit/select-utils": "12.2.6",
|
|
32
|
+
"@commercetools-uikit/spacings-inline": "12.2.5",
|
|
33
|
+
"@commercetools-uikit/text": "12.2.5",
|
|
34
|
+
"@commercetools-uikit/tooltip": "12.2.5",
|
|
35
|
+
"@commercetools-uikit/utils": "12.2.5",
|
|
40
36
|
"@emotion/react": "^11.4.0",
|
|
41
37
|
"@emotion/styled": "^11.3.0",
|
|
42
|
-
"common-tags": "1.8.
|
|
43
|
-
"downshift": "6.1.
|
|
38
|
+
"common-tags": "1.8.2",
|
|
39
|
+
"downshift": "6.1.7",
|
|
44
40
|
"prop-types": "15.7.2",
|
|
45
41
|
"react-is": "17.0.2",
|
|
46
42
|
"react-required-if": "1.0.3",
|
|
@@ -49,7 +45,7 @@
|
|
|
49
45
|
"devDependencies": {
|
|
50
46
|
"moment": "2.29.1",
|
|
51
47
|
"react": "17.0.2",
|
|
52
|
-
"react-intl": "5.
|
|
48
|
+
"react-intl": "5.21.2"
|
|
53
49
|
},
|
|
54
50
|
"peerDependencies": {
|
|
55
51
|
"moment": "2.x",
|