@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.
|
@@ -10,7 +10,6 @@ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/in
|
|
|
10
10
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
11
11
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
|
-
var _extends = require('@babel/runtime-corejs3/helpers/extends');
|
|
14
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
14
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
16
15
|
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
@@ -24,14 +23,14 @@ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/insta
|
|
|
24
23
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
25
24
|
var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
|
|
26
25
|
var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
|
|
27
|
-
var
|
|
26
|
+
var react = require('react');
|
|
28
27
|
require('prop-types');
|
|
29
28
|
var Downshift = require('downshift');
|
|
30
29
|
var reactIntl = require('react-intl');
|
|
31
30
|
var Constraints = require('@commercetools-uikit/constraints');
|
|
32
31
|
var utils = require('@commercetools-uikit/utils');
|
|
33
32
|
var calendarUtils = require('@commercetools-uikit/calendar-utils');
|
|
34
|
-
var
|
|
33
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
35
34
|
|
|
36
35
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
36
|
|
|
@@ -49,7 +48,6 @@ var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceP
|
|
|
49
48
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
50
49
|
var _sortInstanceProperty__default = /*#__PURE__*/_interopDefault(_sortInstanceProperty);
|
|
51
50
|
var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
|
|
52
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
53
51
|
var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
|
|
54
52
|
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
55
53
|
|
|
@@ -61,13 +59,13 @@ var messages = reactIntl.defineMessages({
|
|
|
61
59
|
}
|
|
62
60
|
});
|
|
63
61
|
|
|
64
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default[
|
|
62
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
65
63
|
|
|
66
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context6; _forEachInstanceProperty__default[
|
|
64
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context6; _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source), true)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context7; _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
|
|
67
65
|
|
|
68
|
-
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[
|
|
66
|
+
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); }; }
|
|
69
67
|
|
|
70
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default[
|
|
68
|
+
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; } }
|
|
71
69
|
|
|
72
70
|
var preventDownshiftDefault = function preventDownshiftDefault(event) {
|
|
73
71
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -77,8 +75,8 @@ var preventDownshiftDefault = function preventDownshiftDefault(event) {
|
|
|
77
75
|
var parseRangeText = function parseRangeText(text, locale) {
|
|
78
76
|
var _context, _context2;
|
|
79
77
|
|
|
80
|
-
var parts = _filterInstanceProperty__default[
|
|
81
|
-
var parsedDate = calendarUtils.parseInputToDate(_trimInstanceProperty__default[
|
|
78
|
+
var parts = _filterInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = text.split(' - ')).call(_context2, function (part) {
|
|
79
|
+
var parsedDate = calendarUtils.parseInputToDate(_trimInstanceProperty__default["default"](part).call(part), locale);
|
|
82
80
|
return parsedDate === '' ? null : parsedDate;
|
|
83
81
|
})).call(_context, Boolean);
|
|
84
82
|
|
|
@@ -132,8 +130,8 @@ var getRange = function getRange(_ref) {
|
|
|
132
130
|
};
|
|
133
131
|
};
|
|
134
132
|
|
|
135
|
-
var DateRangeCalendar = /*#__PURE__*/function (
|
|
136
|
-
_inherits(DateRangeCalendar,
|
|
133
|
+
var DateRangeCalendar = /*#__PURE__*/function (_Component) {
|
|
134
|
+
_inherits(DateRangeCalendar, _Component);
|
|
137
135
|
|
|
138
136
|
var _super = _createSuper(DateRangeCalendar);
|
|
139
137
|
|
|
@@ -148,8 +146,8 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
148
146
|
args[_key] = arguments[_key];
|
|
149
147
|
}
|
|
150
148
|
|
|
151
|
-
_this = _super.call.apply(_super, _concatInstanceProperty__default[
|
|
152
|
-
_this.inputRef = /*#__PURE__*/
|
|
149
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default["default"](_context3 = [this]).call(_context3, args));
|
|
150
|
+
_this.inputRef = /*#__PURE__*/react.createRef();
|
|
153
151
|
_this.state = {
|
|
154
152
|
calendarDate: _this.props.value.length === 2 ? _this.props.value[0] : calendarUtils.getToday(),
|
|
155
153
|
suggestedItems: [],
|
|
@@ -200,7 +198,7 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
200
198
|
target: {
|
|
201
199
|
id: _this.props.id,
|
|
202
200
|
name: _this.props.name,
|
|
203
|
-
value: _sortInstanceProperty__default[
|
|
201
|
+
value: _sortInstanceProperty__default["default"](unsortedRange).call(unsortedRange)
|
|
204
202
|
}
|
|
205
203
|
});
|
|
206
204
|
};
|
|
@@ -213,279 +211,283 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
213
211
|
value: function render() {
|
|
214
212
|
var _this2 = this;
|
|
215
213
|
|
|
216
|
-
return
|
|
217
|
-
max: this.props.horizontalConstraint
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (parsedRange.length === 0) return {
|
|
233
|
-
suggestedItems: [],
|
|
234
|
-
highlightedIndex: null,
|
|
235
|
-
inputValue: inputValue,
|
|
236
|
-
startDate: null
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
if (parsedRange.length === 1) {
|
|
240
|
-
var calendarDate = parsedRange[0];
|
|
241
|
-
return {
|
|
214
|
+
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
215
|
+
max: this.props.horizontalConstraint,
|
|
216
|
+
children: jsxRuntime.jsx(Downshift__default["default"], {
|
|
217
|
+
inputId: this.props.id,
|
|
218
|
+
itemToString: calendarUtils.createItemRangeToString(this.props.intl.locale),
|
|
219
|
+
inputValue: this.state.inputValue,
|
|
220
|
+
selectedItem: null,
|
|
221
|
+
highlightedIndex: this.state.highlightedIndex,
|
|
222
|
+
onInputValueChange: function onInputValueChange(inputValue, changes) {
|
|
223
|
+
// only attempt to parse input when the user typed into the input
|
|
224
|
+
// field
|
|
225
|
+
if (changes.type !== Downshift__default["default"].stateChangeTypes.changeInput) return;
|
|
226
|
+
|
|
227
|
+
_this2.setState(function () {
|
|
228
|
+
var parsedRange = parseRangeText(inputValue, _this2.props.intl.locale);
|
|
229
|
+
if (parsedRange.length === 0) return {
|
|
242
230
|
suggestedItems: [],
|
|
243
|
-
highlightedIndex: calendarUtils.getDateInMonth(calendarDate) - 1,
|
|
244
|
-
inputValue: inputValue,
|
|
245
|
-
startDate: parsedRange[0],
|
|
246
|
-
calendarDate: calendarDate
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (parsedRange.length === 2) {
|
|
251
|
-
var _calendarDate = parsedRange[1];
|
|
252
|
-
return {
|
|
253
|
-
suggestedItems: [],
|
|
254
|
-
highlightedIndex: calendarUtils.getDateInMonth(_calendarDate) - 1,
|
|
255
|
-
inputValue: inputValue,
|
|
256
|
-
startDate: parsedRange[0],
|
|
257
|
-
calendarDate: _calendarDate
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return null;
|
|
262
|
-
});
|
|
263
|
-
},
|
|
264
|
-
onStateChange: function onStateChange(changes) {
|
|
265
|
-
/* eslint-disable no-prototype-builtins */
|
|
266
|
-
_this2.setState(function (prevState) {
|
|
267
|
-
// ensure input value matches prop value when menu is closed
|
|
268
|
-
if (changes.type === Downshift__default['default'].stateChangeTypes.mouseUp || changes.type === Downshift__default['default'].stateChangeTypes.blurInput) {
|
|
269
|
-
return {
|
|
270
231
|
highlightedIndex: null,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (changes.hasOwnProperty('selectedItem')) {
|
|
277
|
-
var hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
|
|
278
|
-
var hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
|
|
279
|
-
return {
|
|
280
|
-
highlightedIndex: prevState.highlightedIndex,
|
|
281
|
-
startDate: prevState.startDate ? null : changes.selectedItem,
|
|
282
|
-
calendarDate: changes.selectedItem,
|
|
283
|
-
isOpen: !hasFinishedRangeSelection,
|
|
284
|
-
inputValue: function () {
|
|
285
|
-
if (hasFinishedRangeSelection) {
|
|
286
|
-
return calendarUtils.formatRange([prevState.startDate, changes.selectedItem], _this2.props.intl.locale);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (hasStartedRangeSelection) {
|
|
290
|
-
return calendarUtils.formatRange([changes.selectedItem], _this2.props.intl.locale);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return '';
|
|
294
|
-
}()
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (changes.hasOwnProperty('isOpen')) {
|
|
299
|
-
return {
|
|
300
|
-
isOpen: changes.isOpen,
|
|
301
|
-
highlightedIndex: changes.highlightedIndex || null,
|
|
302
|
-
inputValue: changes.inputValue || prevState.inputValue,
|
|
303
|
-
// Reset range selection progress when menu opens/closes
|
|
304
|
-
startDate: null,
|
|
305
|
-
// Ensure calendar opens on selected date.
|
|
306
|
-
// Open on the current day as a fallback.
|
|
307
|
-
calendarDate: _this2.props.value.length === 2 ? _this2.props.value[0] : calendarUtils.getToday()
|
|
232
|
+
inputValue: inputValue,
|
|
233
|
+
startDate: null
|
|
308
234
|
};
|
|
309
|
-
}
|
|
310
235
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
},
|
|
322
|
-
onChange: function onChange(selectedItem) {
|
|
323
|
-
if (_this2.state.startDate && selectedItem) {
|
|
324
|
-
_this2.emit([_this2.state.startDate, selectedItem]);
|
|
325
|
-
} else {
|
|
326
|
-
_this2.emit([]);
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
isOpen: this.state.isOpen
|
|
330
|
-
}, function (_ref2) {
|
|
331
|
-
var _context4, _context5;
|
|
332
|
-
|
|
333
|
-
var getInputProps = _ref2.getInputProps,
|
|
334
|
-
getMenuProps = _ref2.getMenuProps,
|
|
335
|
-
getItemProps = _ref2.getItemProps,
|
|
336
|
-
getToggleButtonProps = _ref2.getToggleButtonProps,
|
|
337
|
-
clearSelection = _ref2.clearSelection,
|
|
338
|
-
highlightedIndex = _ref2.highlightedIndex,
|
|
339
|
-
openMenu = _ref2.openMenu,
|
|
340
|
-
setHighlightedIndex = _ref2.setHighlightedIndex,
|
|
341
|
-
isOpen = _ref2.isOpen,
|
|
342
|
-
inputValue = _ref2.inputValue;
|
|
343
|
-
var calendarItems = calendarUtils.createCalendarItems(_this2.state.calendarDate, _this2.props.intl);
|
|
344
|
-
|
|
345
|
-
var allItems = _concatInstanceProperty__default['default'](_context4 = []).call(_context4, _toConsumableArray(_this2.state.suggestedItems), _toConsumableArray(calendarItems));
|
|
346
|
-
|
|
347
|
-
var paddingDayCount = calendarUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale);
|
|
348
|
-
|
|
349
|
-
var paddingDays = _fillInstanceProperty__default['default'](_context5 = Array(paddingDayCount)).call(_context5);
|
|
350
|
-
|
|
351
|
-
var weekdays = calendarUtils.getWeekdayNames(_this2.props.intl.locale);
|
|
352
|
-
var today = calendarUtils.getToday();
|
|
353
|
-
return react.jsx("div", {
|
|
354
|
-
onFocus: _this2.props.onFocus,
|
|
355
|
-
onBlur: _this2.handleBlur
|
|
356
|
-
}, react.jsx(calendarUtils.CalendarBody, {
|
|
357
|
-
inputRef: _this2.inputRef,
|
|
358
|
-
inputProps: getInputProps(_objectSpread({
|
|
359
|
-
// Unset the aria-labelledby as it interfers with the link
|
|
360
|
-
// between the <label for> and the <input id>.
|
|
361
|
-
'aria-labelledby': undefined,
|
|
362
|
-
name: _this2.props.name,
|
|
363
|
-
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
364
|
-
onMouseEnter: function onMouseEnter() {
|
|
365
|
-
// we remove the highlight so that the user can use the
|
|
366
|
-
// arrow keys to move the cursor when hovering
|
|
367
|
-
if (isOpen) setHighlightedIndex(null);
|
|
368
|
-
},
|
|
369
|
-
onKeyDown: function onKeyDown(event) {
|
|
370
|
-
if (_this2.props.isReadOnly) {
|
|
371
|
-
preventDownshiftDefault(event);
|
|
372
|
-
return;
|
|
236
|
+
if (parsedRange.length === 1) {
|
|
237
|
+
var calendarDate = parsedRange[0];
|
|
238
|
+
return {
|
|
239
|
+
suggestedItems: [],
|
|
240
|
+
highlightedIndex: calendarUtils.getDateInMonth(calendarDate) - 1,
|
|
241
|
+
inputValue: inputValue,
|
|
242
|
+
startDate: parsedRange[0],
|
|
243
|
+
calendarDate: calendarDate
|
|
244
|
+
};
|
|
373
245
|
}
|
|
374
246
|
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (event.keyCode === 40) {
|
|
386
|
-
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
387
|
-
// if it's the end of the month
|
|
388
|
-
// then bypass normal arrow navigation
|
|
389
|
-
preventDownshiftDefault(event); // then jump to start of next month
|
|
390
|
-
|
|
391
|
-
_this2.jumpMonth(1, 0);
|
|
392
|
-
}
|
|
393
|
-
} // ArrowUp
|
|
247
|
+
if (parsedRange.length === 2) {
|
|
248
|
+
var _calendarDate = parsedRange[1];
|
|
249
|
+
return {
|
|
250
|
+
suggestedItems: [],
|
|
251
|
+
highlightedIndex: calendarUtils.getDateInMonth(_calendarDate) - 1,
|
|
252
|
+
inputValue: inputValue,
|
|
253
|
+
startDate: parsedRange[0],
|
|
254
|
+
calendarDate: _calendarDate
|
|
255
|
+
};
|
|
256
|
+
}
|
|
394
257
|
|
|
258
|
+
return null;
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
onStateChange: function onStateChange(changes) {
|
|
262
|
+
/* eslint-disable no-prototype-builtins */
|
|
263
|
+
_this2.setState(function (prevState) {
|
|
264
|
+
// ensure input value matches prop value when menu is closed
|
|
265
|
+
if (changes.type === Downshift__default["default"].stateChangeTypes.mouseUp || changes.type === Downshift__default["default"].stateChangeTypes.blurInput) {
|
|
266
|
+
return {
|
|
267
|
+
highlightedIndex: null,
|
|
268
|
+
isOpen: false,
|
|
269
|
+
inputValue: calendarUtils.formatRange(_this2.props.value, _this2.props.intl.locale)
|
|
270
|
+
};
|
|
271
|
+
}
|
|
395
272
|
|
|
396
|
-
if (
|
|
397
|
-
var
|
|
273
|
+
if (changes.hasOwnProperty('selectedItem')) {
|
|
274
|
+
var hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
|
|
275
|
+
var hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
|
|
276
|
+
return {
|
|
277
|
+
highlightedIndex: prevState.highlightedIndex,
|
|
278
|
+
startDate: prevState.startDate ? null : changes.selectedItem,
|
|
279
|
+
calendarDate: changes.selectedItem,
|
|
280
|
+
isOpen: !hasFinishedRangeSelection,
|
|
281
|
+
inputValue: function () {
|
|
282
|
+
if (hasFinishedRangeSelection) {
|
|
283
|
+
return calendarUtils.formatRange([prevState.startDate, changes.selectedItem], _this2.props.intl.locale);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (hasStartedRangeSelection) {
|
|
287
|
+
return calendarUtils.formatRange([changes.selectedItem], _this2.props.intl.locale);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return '';
|
|
291
|
+
}()
|
|
292
|
+
};
|
|
293
|
+
}
|
|
398
294
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
295
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
296
|
+
return {
|
|
297
|
+
isOpen: changes.isOpen,
|
|
298
|
+
highlightedIndex: changes.highlightedIndex || null,
|
|
299
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
300
|
+
// Reset range selection progress when menu opens/closes
|
|
301
|
+
startDate: null,
|
|
302
|
+
// Ensure calendar opens on selected date.
|
|
303
|
+
// Open on the current day as a fallback.
|
|
304
|
+
calendarDate: _this2.props.value.length === 2 ? _this2.props.value[0] : calendarUtils.getToday()
|
|
305
|
+
};
|
|
306
|
+
}
|
|
404
307
|
|
|
405
|
-
|
|
406
|
-
|
|
308
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
309
|
+
return {
|
|
310
|
+
highlightedIndex: changes.highlightedIndex
|
|
311
|
+
};
|
|
407
312
|
}
|
|
408
|
-
},
|
|
409
|
-
// we only do this for readOnly because the input
|
|
410
|
-
// doesn't ignore these events, unlike when its disabled
|
|
411
|
-
onClick: _this2.props.isReadOnly ? undefined : openMenu
|
|
412
|
-
}, utils.filterDataAttributes(_this2.props))),
|
|
413
|
-
hasSelection: _this2.props.value.length === 2,
|
|
414
|
-
isClearable: _this2.props.isClearable,
|
|
415
|
-
onClear: function onClear() {
|
|
416
|
-
_this2.setState({
|
|
417
|
-
startDate: null
|
|
418
|
-
});
|
|
419
313
|
|
|
420
|
-
|
|
314
|
+
return null;
|
|
315
|
+
});
|
|
316
|
+
/* eslint-enable no-prototype-builtins */
|
|
421
317
|
|
|
422
|
-
clearSelection();
|
|
423
|
-
},
|
|
424
|
-
isOpen: isOpen,
|
|
425
|
-
isDisabled: _this2.props.isDisabled,
|
|
426
|
-
isReadOnly: _this2.props.isReadOnly,
|
|
427
|
-
toggleButtonProps: getToggleButtonProps(),
|
|
428
|
-
hasError: _this2.props.hasError,
|
|
429
|
-
hasWarning: _this2.props.hasWarning
|
|
430
|
-
}), isOpen && !_this2.props.isDisabled && react.jsx(calendarUtils.CalendarMenu, _extends({}, getMenuProps(), {
|
|
431
|
-
hasError: _this2.props.hasError,
|
|
432
|
-
hasWarning: _this2.props.hasWarning
|
|
433
|
-
}), react.jsx(calendarUtils.CalendarHeader, {
|
|
434
|
-
monthLabel: calendarUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
435
|
-
yearLabel: calendarUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
436
|
-
onPrevMonthClick: function onPrevMonthClick() {
|
|
437
|
-
return _this2.jumpMonth(-1);
|
|
438
|
-
},
|
|
439
|
-
onTodayClick: _this2.showToday,
|
|
440
|
-
onNextMonthClick: function onNextMonthClick() {
|
|
441
|
-
return _this2.jumpMonth(1);
|
|
442
318
|
},
|
|
443
|
-
|
|
444
|
-
|
|
319
|
+
onChange: function onChange(selectedItem) {
|
|
320
|
+
if (_this2.state.startDate && selectedItem) {
|
|
321
|
+
_this2.emit([_this2.state.startDate, selectedItem]);
|
|
322
|
+
} else {
|
|
323
|
+
_this2.emit([]);
|
|
324
|
+
}
|
|
445
325
|
},
|
|
446
|
-
|
|
447
|
-
|
|
326
|
+
isOpen: this.state.isOpen,
|
|
327
|
+
children: function children(_ref2) {
|
|
328
|
+
var _context4, _context5;
|
|
329
|
+
|
|
330
|
+
var getInputProps = _ref2.getInputProps,
|
|
331
|
+
getMenuProps = _ref2.getMenuProps,
|
|
332
|
+
getItemProps = _ref2.getItemProps,
|
|
333
|
+
getToggleButtonProps = _ref2.getToggleButtonProps,
|
|
334
|
+
clearSelection = _ref2.clearSelection,
|
|
335
|
+
highlightedIndex = _ref2.highlightedIndex,
|
|
336
|
+
openMenu = _ref2.openMenu,
|
|
337
|
+
setHighlightedIndex = _ref2.setHighlightedIndex,
|
|
338
|
+
isOpen = _ref2.isOpen,
|
|
339
|
+
inputValue = _ref2.inputValue;
|
|
340
|
+
var calendarItems = calendarUtils.createCalendarItems(_this2.state.calendarDate, _this2.props.intl);
|
|
341
|
+
|
|
342
|
+
var allItems = _concatInstanceProperty__default["default"](_context4 = []).call(_context4, _toConsumableArray(_this2.state.suggestedItems), _toConsumableArray(calendarItems));
|
|
343
|
+
|
|
344
|
+
var paddingDayCount = calendarUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale);
|
|
345
|
+
|
|
346
|
+
var paddingDays = _fillInstanceProperty__default["default"](_context5 = Array(paddingDayCount)).call(_context5);
|
|
347
|
+
|
|
348
|
+
var weekdays = calendarUtils.getWeekdayNames(_this2.props.intl.locale);
|
|
349
|
+
var today = calendarUtils.getToday();
|
|
350
|
+
return jsxRuntime.jsxs("div", {
|
|
351
|
+
onFocus: _this2.props.onFocus,
|
|
352
|
+
onBlur: _this2.handleBlur,
|
|
353
|
+
children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
|
|
354
|
+
inputRef: _this2.inputRef,
|
|
355
|
+
inputProps: getInputProps(_objectSpread({
|
|
356
|
+
// Unset the aria-labelledby as it interfers with the link
|
|
357
|
+
// between the <label for> and the <input id>.
|
|
358
|
+
'aria-labelledby': undefined,
|
|
359
|
+
name: _this2.props.name,
|
|
360
|
+
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
361
|
+
onMouseEnter: function onMouseEnter() {
|
|
362
|
+
// we remove the highlight so that the user can use the
|
|
363
|
+
// arrow keys to move the cursor when hovering
|
|
364
|
+
if (isOpen) setHighlightedIndex(null);
|
|
365
|
+
},
|
|
366
|
+
onKeyDown: function onKeyDown(event) {
|
|
367
|
+
if (_this2.props.isReadOnly) {
|
|
368
|
+
preventDownshiftDefault(event);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (event.key === 'Enter' && _trimInstanceProperty__default["default"](inputValue).call(inputValue) === '' && // do not clear value when user presses Enter to
|
|
373
|
+
// select the end date (so only clear when there is no
|
|
374
|
+
// startDate)
|
|
375
|
+
!_this2.state.startDate && _this2.props.isClearable) {
|
|
376
|
+
clearSelection();
|
|
377
|
+
|
|
378
|
+
_this2.emit([]);
|
|
379
|
+
} // ArrowDown
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
if (event.keyCode === 40) {
|
|
383
|
+
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
384
|
+
// if it's the end of the month
|
|
385
|
+
// then bypass normal arrow navigation
|
|
386
|
+
preventDownshiftDefault(event); // then jump to start of next month
|
|
387
|
+
|
|
388
|
+
_this2.jumpMonth(1, 0);
|
|
389
|
+
}
|
|
390
|
+
} // ArrowUp
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
if (event.keyCode === 38) {
|
|
394
|
+
var previousDay = calendarUtils.getPreviousDay(calendarItems[highlightedIndex]);
|
|
395
|
+
|
|
396
|
+
if (highlightedIndex <= 0) {
|
|
397
|
+
// if it's the start of the month
|
|
398
|
+
// then bypass normal arrow navigation
|
|
399
|
+
preventDownshiftDefault(event);
|
|
400
|
+
var numberOfDaysOfPrevMonth = calendarUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
|
|
401
|
+
|
|
402
|
+
_this2.jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
// we only do this for readOnly because the input
|
|
407
|
+
// doesn't ignore these events, unlike when its disabled
|
|
408
|
+
onClick: _this2.props.isReadOnly ? undefined : openMenu
|
|
409
|
+
}, utils.filterDataAttributes(_this2.props))),
|
|
410
|
+
hasSelection: _this2.props.value.length === 2,
|
|
411
|
+
isClearable: _this2.props.isClearable,
|
|
412
|
+
onClear: function onClear() {
|
|
413
|
+
_this2.setState({
|
|
414
|
+
startDate: null
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
_this2.emit([]);
|
|
418
|
+
|
|
419
|
+
clearSelection();
|
|
420
|
+
},
|
|
421
|
+
isOpen: isOpen,
|
|
422
|
+
isDisabled: _this2.props.isDisabled,
|
|
423
|
+
isReadOnly: _this2.props.isReadOnly,
|
|
424
|
+
toggleButtonProps: getToggleButtonProps(),
|
|
425
|
+
hasError: _this2.props.hasError,
|
|
426
|
+
hasWarning: _this2.props.hasWarning
|
|
427
|
+
}), isOpen && !_this2.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
|
|
428
|
+
hasError: _this2.props.hasError,
|
|
429
|
+
hasWarning: _this2.props.hasWarning,
|
|
430
|
+
children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
|
|
431
|
+
monthLabel: calendarUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
432
|
+
yearLabel: calendarUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
433
|
+
onPrevMonthClick: function onPrevMonthClick() {
|
|
434
|
+
return _this2.jumpMonth(-1);
|
|
435
|
+
},
|
|
436
|
+
onTodayClick: _this2.showToday,
|
|
437
|
+
onNextMonthClick: function onNextMonthClick() {
|
|
438
|
+
return _this2.jumpMonth(1);
|
|
439
|
+
},
|
|
440
|
+
onPrevYearClick: function onPrevYearClick() {
|
|
441
|
+
return _this2.jumpMonth(-12);
|
|
442
|
+
},
|
|
443
|
+
onNextYearClick: function onNextYearClick() {
|
|
444
|
+
return _this2.jumpMonth(12);
|
|
445
|
+
}
|
|
446
|
+
}), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
|
|
447
|
+
children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, function (weekday) {
|
|
448
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, {
|
|
449
|
+
type: "heading",
|
|
450
|
+
children: weekday
|
|
451
|
+
}, weekday);
|
|
452
|
+
}), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, function (day, index) {
|
|
453
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, {
|
|
454
|
+
type: "spacing"
|
|
455
|
+
}, index);
|
|
456
|
+
}), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, function (item, index) {
|
|
457
|
+
var isHighlighted = _this2.state.suggestedItems.length + index === highlightedIndex;
|
|
458
|
+
|
|
459
|
+
var _getRange = getRange({
|
|
460
|
+
item: item,
|
|
461
|
+
value: _this2.props.value,
|
|
462
|
+
startDate: _this2.state.startDate,
|
|
463
|
+
highlightedItem: allItems[_this2.state.highlightedIndex]
|
|
464
|
+
}),
|
|
465
|
+
isRangeStart = _getRange.isRangeStart,
|
|
466
|
+
isRangeBetween = _getRange.isRangeBetween,
|
|
467
|
+
isRangeEnd = _getRange.isRangeEnd;
|
|
468
|
+
|
|
469
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
|
|
470
|
+
isToday: calendarUtils.isSameDay(today, item)
|
|
471
|
+
}, getItemProps({
|
|
472
|
+
disabled: _this2.props.isDisabled,
|
|
473
|
+
item: item,
|
|
474
|
+
onMouseOut: function onMouseOut() {
|
|
475
|
+
setHighlightedIndex(null);
|
|
476
|
+
}
|
|
477
|
+
})), {}, {
|
|
478
|
+
isHighlighted: isHighlighted,
|
|
479
|
+
isRangeStart: isRangeStart,
|
|
480
|
+
isRangeBetween: isRangeBetween,
|
|
481
|
+
isRangeEnd: isRangeEnd,
|
|
482
|
+
children: calendarUtils.getCalendarDayLabel(item)
|
|
483
|
+
}), item);
|
|
484
|
+
})]
|
|
485
|
+
})]
|
|
486
|
+
}))]
|
|
487
|
+
});
|
|
448
488
|
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
key: weekday,
|
|
452
|
-
type: "heading"
|
|
453
|
-
}, weekday);
|
|
454
|
-
}), _mapInstanceProperty__default['default'](paddingDays).call(paddingDays, function (day, index) {
|
|
455
|
-
return react.jsx(calendarUtils.CalendarDay, {
|
|
456
|
-
key: index,
|
|
457
|
-
type: "spacing"
|
|
458
|
-
});
|
|
459
|
-
}), _mapInstanceProperty__default['default'](calendarItems).call(calendarItems, function (item, index) {
|
|
460
|
-
var isHighlighted = _this2.state.suggestedItems.length + index === highlightedIndex;
|
|
461
|
-
|
|
462
|
-
var _getRange = getRange({
|
|
463
|
-
item: item,
|
|
464
|
-
value: _this2.props.value,
|
|
465
|
-
startDate: _this2.state.startDate,
|
|
466
|
-
highlightedItem: allItems[_this2.state.highlightedIndex]
|
|
467
|
-
}),
|
|
468
|
-
isRangeStart = _getRange.isRangeStart,
|
|
469
|
-
isRangeBetween = _getRange.isRangeBetween,
|
|
470
|
-
isRangeEnd = _getRange.isRangeEnd;
|
|
471
|
-
|
|
472
|
-
return react.jsx(calendarUtils.CalendarDay, _extends({
|
|
473
|
-
key: item,
|
|
474
|
-
isToday: calendarUtils.isSameDay(today, item)
|
|
475
|
-
}, getItemProps({
|
|
476
|
-
disabled: _this2.props.isDisabled,
|
|
477
|
-
item: item,
|
|
478
|
-
onMouseOut: function onMouseOut() {
|
|
479
|
-
setHighlightedIndex(null);
|
|
480
|
-
}
|
|
481
|
-
}), {
|
|
482
|
-
isHighlighted: isHighlighted,
|
|
483
|
-
isRangeStart: isRangeStart,
|
|
484
|
-
isRangeBetween: isRangeBetween,
|
|
485
|
-
isRangeEnd: isRangeEnd
|
|
486
|
-
}), calendarUtils.getCalendarDayLabel(item));
|
|
487
|
-
}))));
|
|
488
|
-
}));
|
|
489
|
+
}, this.props.intl.locale)
|
|
490
|
+
});
|
|
489
491
|
}
|
|
490
492
|
}], [{
|
|
491
493
|
key: "getDerivedStateFromProps",
|
|
@@ -506,7 +508,7 @@ var DateRangeCalendar = /*#__PURE__*/function (_React$Component) {
|
|
|
506
508
|
}]);
|
|
507
509
|
|
|
508
510
|
return DateRangeCalendar;
|
|
509
|
-
}(
|
|
511
|
+
}(react.Component);
|
|
510
512
|
|
|
511
513
|
DateRangeCalendar.displayName = 'DateRangeCalendar';
|
|
512
514
|
DateRangeCalendar.defaultProps = {
|
|
@@ -520,8 +522,8 @@ DateRangeCalendar.isEmpty = function (range) {
|
|
|
520
522
|
DateRangeCalendar.propTypes = {};
|
|
521
523
|
var dateRangeInput = reactIntl.injectIntl(DateRangeCalendar);
|
|
522
524
|
|
|
523
|
-
// NOTE: This string will be replaced
|
|
524
|
-
var version =
|
|
525
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
526
|
+
var version = "12.2.6";
|
|
525
527
|
|
|
526
|
-
exports[
|
|
528
|
+
exports["default"] = dateRangeInput;
|
|
527
529
|
exports.version = version;
|