@commercetools-uikit/date-time-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.
@@ -11,7 +11,6 @@ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/in
11
11
  var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
12
12
  var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
13
13
  var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
14
- var _extends = require('@babel/runtime-corejs3/helpers/extends');
15
14
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
16
15
  var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
17
16
  var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
@@ -22,7 +21,7 @@ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/ins
22
21
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
23
22
  var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
24
23
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
25
- var React = require('react');
24
+ var react$1 = require('react');
26
25
  require('prop-types');
27
26
  var Downshift = require('downshift');
28
27
  var reactIntl = require('react-intl');
@@ -32,6 +31,7 @@ var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
32
31
  var calendarUtils = require('@commercetools-uikit/calendar-utils');
33
32
  var react = require('@emotion/react');
34
33
  var designSystem = require('@commercetools-uikit/design-system');
34
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
35
35
 
36
36
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
37
37
 
@@ -48,16 +48,15 @@ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInsta
48
48
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
49
49
  var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
50
50
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
51
- var React__default = /*#__PURE__*/_interopDefault(React);
52
51
  var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
53
52
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
54
53
 
55
54
  var getInputStyles = function getInputStyles() {
56
- return /*#__PURE__*/react.css("width:100%;text-align:center;border:0;border-top:1px solid ", designSystem.customProperties.colorNeutral90, ";padding:10px 0;outline:0;font-size:", designSystem.customProperties.fontSizeDefault, ";margin-top:", designSystem.customProperties.spacingS, ";color:", designSystem.customProperties.colorSolid, ";:disabled{background-color:", designSystem.customProperties.colorSurface, ";}" + ("" ));
55
+ return /*#__PURE__*/react.css("width:100%;text-align:center;border:0;border-top:1px solid ", designSystem.customProperties.colorNeutral90, ";padding:10px 0;outline:0;font-size:", designSystem.customProperties.fontSizeDefault, ";margin-top:", designSystem.customProperties.spacingS, ";color:", designSystem.customProperties.colorSolid, ";:disabled{background-color:", designSystem.customProperties.colorSurface, ";}" + ("" ), "" );
57
56
  };
58
57
 
59
58
  var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
60
- return react.jsx("input", {
59
+ return jsxRuntime.jsx("input", {
61
60
  disabled: props.isDisabled,
62
61
  ref: props.timeInputRef,
63
62
  type: "text",
@@ -86,14 +85,14 @@ var messages = reactIntl.defineMessages({
86
85
  }
87
86
  });
88
87
 
89
- 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; }
88
+ 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; }
90
89
 
91
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source), true)).call(_context4, 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 _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
90
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source), true)).call(_context4, 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 _context5; _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
92
91
 
93
- 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); }; }
92
+ 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); }; }
94
93
 
95
- 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; } }
96
- var activationTypes = [Downshift__default['default'].stateChangeTypes.keyDownEnter, Downshift__default['default'].stateChangeTypes.clickItem];
94
+ 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; } }
95
+ var activationTypes = [Downshift__default["default"].stateChangeTypes.keyDownEnter, Downshift__default["default"].stateChangeTypes.clickItem];
97
96
 
98
97
  var preventDownshiftDefault = function preventDownshiftDefault(event) {
99
98
  // eslint-disable-next-line no-param-reassign
@@ -112,8 +111,8 @@ var createBlurHandler = function createBlurHandler(timeInputRef) {
112
111
  };
113
112
  };
114
113
 
115
- var DateTimeInput = /*#__PURE__*/function (_React$Component) {
116
- _inherits(DateTimeInput, _React$Component);
114
+ var DateTimeInput = /*#__PURE__*/function (_Component) {
115
+ _inherits(DateTimeInput, _Component);
117
116
 
118
117
  var _super = _createSuper(DateTimeInput);
119
118
 
@@ -128,9 +127,9 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
128
127
  args[_key] = arguments[_key];
129
128
  }
130
129
 
131
- _this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context = [this]).call(_context, args));
132
- _this.inputRef = /*#__PURE__*/React__default['default'].createRef();
133
- _this.timeInputRef = /*#__PURE__*/React__default['default'].createRef();
130
+ _this = _super.call.apply(_super, _concatInstanceProperty__default["default"](_context = [this]).call(_context, args));
131
+ _this.inputRef = /*#__PURE__*/react$1.createRef();
132
+ _this.timeInputRef = /*#__PURE__*/react$1.createRef();
134
133
  _this.state = {
135
134
  calendarDate: calendarTimeUtils.getToday(_this.props.timeZone),
136
135
  suggestedItems: [],
@@ -211,280 +210,284 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
211
210
  var _context2,
212
211
  _this2 = this;
213
212
 
214
- return react.jsx(Constraints__default['default'].Horizontal, {
215
- max: this.props.horizontalConstraint
216
- }, react.jsx(Downshift__default['default'] // Setting the key to the timeZone conveniently forces a rerender
217
- // when the time-zone changes. Otherwise we'd need to make
218
- // inputValue a controlled property so that we can update
219
- // the displayed value as downshift seems to ignore an updated
220
- // itemToString function.
221
- , {
222
- key: _concatInstanceProperty__default['default'](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale),
223
- inputId: this.props.id,
224
- itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
225
- selectedItem: this.props.value === '' ? null : this.props.value,
226
- highlightedIndex: this.state.highlightedIndex,
227
- onChange: this.emit,
228
- stateReducer: function stateReducer(state, changes) {
229
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
230
- return _objectSpread(_objectSpread({}, changes), {}, {
231
- isOpen: true
232
- });
233
- }
234
-
235
- return changes;
236
- },
237
- onStateChange: function onStateChange(changes) {
238
- /* eslint-disable no-prototype-builtins */
239
- _this2.setState(function (prevState) {
240
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
241
- return {
242
- startDate: changes.isOpen ? prevState.startDate : null,
243
- inputValue: changes.inputValue || prevState.inputValue,
244
- timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
245
- };
246
- }
247
-
248
- if (changes.hasOwnProperty('inputValue')) {
249
- var suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, _this2.props.timeZone);
250
- return {
251
- suggestedItems: suggestedItems,
252
- highlightedIndex: suggestedItems.length > 0 ? 0 : null
253
- };
254
- }
255
-
256
- if (changes.hasOwnProperty('isOpen')) {
257
- return {
258
- inputValue: changes.inputValue || prevState.inputValue,
259
- startDate: changes.isOpen ? prevState.startDate : null,
260
- // set time input value to time from value when menu is opened
261
- timeString: changes.isOpen && _this2.props.value !== '' ? calendarTimeUtils.formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
262
- // ensure calendar always opens on selected item, or on
263
- // current month when there is no selected item
264
- calendarDate: _this2.props.value === '' ? calendarTimeUtils.getToday() : _this2.props.value
265
- };
266
- }
267
-
268
- if (changes.hasOwnProperty('highlightedIndex')) {
269
- return {
270
- highlightedIndex: changes.highlightedIndex
271
- };
272
- }
273
-
274
- return null;
275
- }, function () {
276
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
277
- _this2.timeInputRef.current.focus();
278
-
279
- _this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
213
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
214
+ max: this.props.horizontalConstraint,
215
+ children: jsxRuntime.jsx(Downshift__default["default"] // Setting the key to the timeZone conveniently forces a rerender
216
+ // when the time-zone changes. Otherwise we'd need to make
217
+ // inputValue a controlled property so that we can update
218
+ // the displayed value as downshift seems to ignore an updated
219
+ // itemToString function.
220
+ , {
221
+ inputId: this.props.id,
222
+ itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
223
+ selectedItem: this.props.value === '' ? null : this.props.value,
224
+ highlightedIndex: this.state.highlightedIndex,
225
+ onChange: this.emit,
226
+ stateReducer: function stateReducer(state, changes) {
227
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
228
+ return _objectSpread(_objectSpread({}, changes), {}, {
229
+ isOpen: true
230
+ });
280
231
  }
281
- });
282
- /* eslint-enable no-prototype-builtins */
283
232
 
284
- }
285
- }, function (_ref) {
286
- var _context3;
287
-
288
- var getInputProps = _ref.getInputProps,
289
- getMenuProps = _ref.getMenuProps,
290
- getItemProps = _ref.getItemProps,
291
- getToggleButtonProps = _ref.getToggleButtonProps,
292
- clearSelection = _ref.clearSelection,
293
- highlightedIndex = _ref.highlightedIndex,
294
- openMenu = _ref.openMenu,
295
- closeMenu = _ref.closeMenu,
296
- setHighlightedIndex = _ref.setHighlightedIndex,
297
- selectedItem = _ref.selectedItem,
298
- inputValue = _ref.inputValue,
299
- isOpen = _ref.isOpen;
300
- var suggestedItems = _this2.state.suggestedItems;
301
- var calendarItems = calendarTimeUtils.createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
302
- var paddingDayCount = calendarTimeUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
303
-
304
- var paddingDays = _fillInstanceProperty__default['default'](_context3 = Array(paddingDayCount)).call(_context3);
305
-
306
- var weekdays = calendarTimeUtils.getWeekdayNames(_this2.props.intl.locale);
307
- var today = calendarTimeUtils.getToday();
308
- var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
309
- return react.jsx("div", {
310
- onFocus: _this2.props.onFocus,
311
- onBlur: _this2.handleBlur
312
- }, react.jsx(calendarUtils.CalendarBody, {
313
- inputRef: _this2.inputRef,
314
- inputProps: getInputProps(_objectSpread({
315
- // Unset the aria-labelledby as it interfers with the link
316
- // between the <label for> and the <input id>.
317
- 'aria-labelledby': undefined,
318
- name: _this2.props.name,
319
- placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
320
- onMouseEnter: function onMouseEnter() {
321
- // we remove the highlight so that the user can use the
322
- // arrow keys to move the cursor when hovering
323
- if (isOpen) setHighlightedIndex(null);
324
- },
325
- onKeyDown: function onKeyDown(event) {
326
- if (_this2.props.isReadOnly) {
327
- preventDownshiftDefault(event);
328
- return;
329
- } // parse input when user presses enter on regular input,
330
- // close menu and notify parent
331
-
332
-
333
- if (event.key === 'Enter' && highlightedIndex === null) {
334
- preventDownshiftDefault(event);
335
- var parsedDate = calendarTimeUtils.parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
336
-
337
- _this2.emit(parsedDate);
338
-
339
- closeMenu();
340
- } // ArrowDown
341
-
342
-
343
- if (event.keyCode === 40) {
344
- if (highlightedIndex + 1 >= calendarItems.length) {
345
- // if it's the end of the month
346
- // then bypass normal arrow navigation
347
- preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
348
- // then jump to start of next month
349
-
350
- _this2.jumpMonths(1, 0);
351
- }
352
- } // ArrowUp
353
-
354
-
355
- if (event.keyCode === 38) {
356
- var previousDay = calendarTimeUtils.getPreviousDay(calendarItems[highlightedIndex]);
357
-
358
- if (highlightedIndex <= 0) {
359
- // if it's the start of the month
360
- // then bypass normal arrow navigation
361
- preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
362
-
363
- var numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
364
-
365
- _this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
366
- }
367
- }
368
- },
369
- onClick: _this2.props.isReadOnly ? undefined : openMenu,
370
- onBlur: createBlurHandler(_this2.timeInputRef),
371
- onChange: function onChange(event) {
372
- // keep timeInput and regular input in sync when user
373
- // types into regular input
374
- if (!isOpen) return;
375
- var time = event.target.value.split(' ')[1];
376
- if (!time) return;
377
- var parsedTime = utils.parseTime(time);
378
-
379
- _this2.setState(function () {
380
- if (!parsedTime) return {
381
- timeString: ''
233
+ return changes;
234
+ },
235
+ onStateChange: function onStateChange(changes) {
236
+ /* eslint-disable no-prototype-builtins */
237
+ _this2.setState(function (prevState) {
238
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
239
+ return {
240
+ startDate: changes.isOpen ? prevState.startDate : null,
241
+ inputValue: changes.inputValue || prevState.inputValue,
242
+ timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
382
243
  };
383
- var date = calendarTimeUtils.getToday(_this2.props.timeZone);
244
+ }
384
245
 
385
- if (parsedTime) {
386
- date = calendarTimeUtils.changeTime(date, _this2.props.timeZone, parsedTime);
387
- }
246
+ if (changes.hasOwnProperty('inputValue')) {
247
+ var suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, _this2.props.timeZone);
248
+ return {
249
+ suggestedItems: suggestedItems,
250
+ highlightedIndex: suggestedItems.length > 0 ? 0 : null
251
+ };
252
+ }
388
253
 
254
+ if (changes.hasOwnProperty('isOpen')) {
389
255
  return {
390
- timeString: calendarTimeUtils.formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
256
+ inputValue: changes.inputValue || prevState.inputValue,
257
+ startDate: changes.isOpen ? prevState.startDate : null,
258
+ // set time input value to time from value when menu is opened
259
+ timeString: changes.isOpen && _this2.props.value !== '' ? calendarTimeUtils.formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
260
+ // ensure calendar always opens on selected item, or on
261
+ // current month when there is no selected item
262
+ calendarDate: _this2.props.value === '' ? calendarTimeUtils.getToday() : _this2.props.value
391
263
  };
392
- });
393
- }
394
- }, utils.filterDataAttributes(_this2.props))),
395
- hasSelection: Boolean(selectedItem),
396
- onClear: clearSelection,
397
- isOpen: isOpen,
398
- isDisabled: _this2.props.isDisabled,
399
- isReadOnly: _this2.props.isReadOnly,
400
- toggleButtonProps: getToggleButtonProps({
401
- onBlur: createBlurHandler(_this2.timeInputRef)
402
- }),
403
- hasError: _this2.props.hasError,
404
- hasWarning: _this2.props.hasWarning
405
- }), isOpen && !_this2.props.isDisabled && react.jsx(calendarUtils.CalendarMenu, _extends({}, getMenuProps(), {
406
- hasFooter: true,
407
- hasError: _this2.props.hasError,
408
- hasWarning: _this2.props.hasWarning
409
- }), react.jsx(calendarUtils.CalendarHeader, {
410
- monthLabel: calendarTimeUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
411
- yearLabel: calendarTimeUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
412
- onPrevMonthClick: function onPrevMonthClick() {
413
- return _this2.jumpMonths(-1);
414
- },
415
- onTodayClick: _this2.showToday,
416
- onNextMonthClick: function onNextMonthClick() {
417
- return _this2.jumpMonths(1);
418
- },
419
- onPrevYearClick: function onPrevYearClick() {
420
- return _this2.jumpMonths(-12);
421
- },
422
- onNextYearClick: function onNextYearClick() {
423
- return _this2.jumpMonths(12);
424
- }
425
- }), react.jsx(calendarUtils.CalendarContent, null, _mapInstanceProperty__default['default'](weekdays).call(weekdays, function (weekday) {
426
- return react.jsx(calendarUtils.CalendarDay, {
427
- key: weekday,
428
- type: "heading"
429
- }, weekday);
430
- }), _mapInstanceProperty__default['default'](paddingDays).call(paddingDays, function (day, index) {
431
- return react.jsx(calendarUtils.CalendarDay, {
432
- key: index,
433
- type: "spacing"
434
- });
435
- }), _mapInstanceProperty__default['default'](calendarItems).call(calendarItems, function (item, index) {
436
- return react.jsx(calendarUtils.CalendarDay, _extends({
437
- key: item,
438
- isToday: calendarTimeUtils.isSameDay(today, item)
439
- }, getItemProps({
440
- disabled: _this2.props.isDisabled,
441
- item: item,
442
- onMouseOut: function onMouseOut() {
443
- setHighlightedIndex(null);
444
- }
445
- }), {
446
- isHighlighted: suggestedItems.length + index === highlightedIndex,
447
- isSelected: calendarTimeUtils.isSameDay(item, _this2.props.value)
448
- }), calendarTimeUtils.getCalendarDayLabel(item, _this2.props.timeZone));
449
- })), react.jsx(TimeInput, {
450
- isDisabled: !isTimeInputVisible,
451
- timeInputRef: _this2.timeInputRef,
452
- placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
453
- value: _this2.state.timeString,
454
- onChange: _this2.handleTimeChange,
455
- onKeyDown: function onKeyDown(event) {
456
- if (event.key === 'ArrowUp') {
457
- setHighlightedIndex(null);
458
-
459
- _this2.inputRef.current.focus();
460
-
461
- return;
462
- }
264
+ }
463
265
 
464
- if (event.key === 'Enter') {
465
- setHighlightedIndex(null);
266
+ if (changes.hasOwnProperty('highlightedIndex')) {
267
+ return {
268
+ highlightedIndex: changes.highlightedIndex
269
+ };
270
+ }
466
271
 
467
- _this2.inputRef.current.focus();
272
+ return null;
273
+ }, function () {
274
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
275
+ _this2.timeInputRef.current.focus();
468
276
 
469
- _this2.inputRef.current.setSelectionRange(0, 100);
277
+ _this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
278
+ }
279
+ });
280
+ /* eslint-enable no-prototype-builtins */
470
281
 
471
- closeMenu();
472
- }
282
+ },
283
+ children: function children(_ref) {
284
+ var _context3;
285
+
286
+ var getInputProps = _ref.getInputProps,
287
+ getMenuProps = _ref.getMenuProps,
288
+ getItemProps = _ref.getItemProps,
289
+ getToggleButtonProps = _ref.getToggleButtonProps,
290
+ clearSelection = _ref.clearSelection,
291
+ highlightedIndex = _ref.highlightedIndex,
292
+ openMenu = _ref.openMenu,
293
+ closeMenu = _ref.closeMenu,
294
+ setHighlightedIndex = _ref.setHighlightedIndex,
295
+ selectedItem = _ref.selectedItem,
296
+ inputValue = _ref.inputValue,
297
+ isOpen = _ref.isOpen;
298
+ var suggestedItems = _this2.state.suggestedItems;
299
+ var calendarItems = calendarTimeUtils.createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
300
+ var paddingDayCount = calendarTimeUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
301
+
302
+ var paddingDays = _fillInstanceProperty__default["default"](_context3 = Array(paddingDayCount)).call(_context3);
303
+
304
+ var weekdays = calendarTimeUtils.getWeekdayNames(_this2.props.intl.locale);
305
+ var today = calendarTimeUtils.getToday();
306
+ var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
307
+ return jsxRuntime.jsxs("div", {
308
+ onFocus: _this2.props.onFocus,
309
+ onBlur: _this2.handleBlur,
310
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
311
+ inputRef: _this2.inputRef,
312
+ inputProps: getInputProps(_objectSpread({
313
+ // Unset the aria-labelledby as it interfers with the link
314
+ // between the <label for> and the <input id>.
315
+ 'aria-labelledby': undefined,
316
+ name: _this2.props.name,
317
+ placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
318
+ onMouseEnter: function onMouseEnter() {
319
+ // we remove the highlight so that the user can use the
320
+ // arrow keys to move the cursor when hovering
321
+ if (isOpen) setHighlightedIndex(null);
322
+ },
323
+ onKeyDown: function onKeyDown(event) {
324
+ if (_this2.props.isReadOnly) {
325
+ preventDownshiftDefault(event);
326
+ return;
327
+ } // parse input when user presses enter on regular input,
328
+ // close menu and notify parent
329
+
330
+
331
+ if (event.key === 'Enter' && highlightedIndex === null) {
332
+ preventDownshiftDefault(event);
333
+ var parsedDate = calendarTimeUtils.parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
334
+
335
+ _this2.emit(parsedDate);
336
+
337
+ closeMenu();
338
+ } // ArrowDown
339
+
340
+
341
+ if (event.keyCode === 40) {
342
+ if (highlightedIndex + 1 >= calendarItems.length) {
343
+ // if it's the end of the month
344
+ // then bypass normal arrow navigation
345
+ preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
346
+ // then jump to start of next month
347
+
348
+ _this2.jumpMonths(1, 0);
349
+ }
350
+ } // ArrowUp
351
+
352
+
353
+ if (event.keyCode === 38) {
354
+ var previousDay = calendarTimeUtils.getPreviousDay(calendarItems[highlightedIndex]);
355
+
356
+ if (highlightedIndex <= 0) {
357
+ // if it's the start of the month
358
+ // then bypass normal arrow navigation
359
+ preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
360
+
361
+ var numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
362
+
363
+ _this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
364
+ }
365
+ }
366
+ },
367
+ onClick: _this2.props.isReadOnly ? undefined : openMenu,
368
+ onBlur: createBlurHandler(_this2.timeInputRef),
369
+ onChange: function onChange(event) {
370
+ // keep timeInput and regular input in sync when user
371
+ // types into regular input
372
+ if (!isOpen) return;
373
+ var time = event.target.value.split(' ')[1];
374
+ if (!time) return;
375
+ var parsedTime = utils.parseTime(time);
376
+
377
+ _this2.setState(function () {
378
+ if (!parsedTime) return {
379
+ timeString: ''
380
+ };
381
+ var date = calendarTimeUtils.getToday(_this2.props.timeZone);
382
+
383
+ if (parsedTime) {
384
+ date = calendarTimeUtils.changeTime(date, _this2.props.timeZone, parsedTime);
385
+ }
386
+
387
+ return {
388
+ timeString: calendarTimeUtils.formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
389
+ };
390
+ });
391
+ }
392
+ }, utils.filterDataAttributes(_this2.props))),
393
+ hasSelection: Boolean(selectedItem),
394
+ onClear: clearSelection,
395
+ isOpen: isOpen,
396
+ isDisabled: _this2.props.isDisabled,
397
+ isReadOnly: _this2.props.isReadOnly,
398
+ toggleButtonProps: getToggleButtonProps({
399
+ onBlur: createBlurHandler(_this2.timeInputRef)
400
+ }),
401
+ hasError: _this2.props.hasError,
402
+ hasWarning: _this2.props.hasWarning
403
+ }), isOpen && !_this2.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
404
+ hasFooter: true,
405
+ hasError: _this2.props.hasError,
406
+ hasWarning: _this2.props.hasWarning,
407
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
408
+ monthLabel: calendarTimeUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
409
+ yearLabel: calendarTimeUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
410
+ onPrevMonthClick: function onPrevMonthClick() {
411
+ return _this2.jumpMonths(-1);
412
+ },
413
+ onTodayClick: _this2.showToday,
414
+ onNextMonthClick: function onNextMonthClick() {
415
+ return _this2.jumpMonths(1);
416
+ },
417
+ onPrevYearClick: function onPrevYearClick() {
418
+ return _this2.jumpMonths(-12);
419
+ },
420
+ onNextYearClick: function onNextYearClick() {
421
+ return _this2.jumpMonths(12);
422
+ }
423
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
424
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, function (weekday) {
425
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, {
426
+ type: "heading",
427
+ children: weekday
428
+ }, weekday);
429
+ }), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, function (day, index) {
430
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, {
431
+ type: "spacing"
432
+ }, index);
433
+ }), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, function (item, index) {
434
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
435
+ isToday: calendarTimeUtils.isSameDay(today, item)
436
+ }, getItemProps({
437
+ disabled: _this2.props.isDisabled,
438
+ item: item,
439
+ onMouseOut: function onMouseOut() {
440
+ setHighlightedIndex(null);
441
+ }
442
+ })), {}, {
443
+ isHighlighted: suggestedItems.length + index === highlightedIndex,
444
+ isSelected: calendarTimeUtils.isSameDay(item, _this2.props.value),
445
+ children: calendarTimeUtils.getCalendarDayLabel(item, _this2.props.timeZone)
446
+ }), item);
447
+ })]
448
+ }), jsxRuntime.jsx(TimeInput, {
449
+ isDisabled: !isTimeInputVisible,
450
+ timeInputRef: _this2.timeInputRef,
451
+ placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
452
+ value: _this2.state.timeString,
453
+ onChange: _this2.handleTimeChange,
454
+ onKeyDown: function onKeyDown(event) {
455
+ if (event.key === 'ArrowUp') {
456
+ setHighlightedIndex(null);
457
+
458
+ _this2.inputRef.current.focus();
459
+
460
+ return;
461
+ }
462
+
463
+ if (event.key === 'Enter') {
464
+ setHighlightedIndex(null);
465
+
466
+ _this2.inputRef.current.focus();
467
+
468
+ _this2.inputRef.current.setSelectionRange(0, 100);
469
+
470
+ closeMenu();
471
+ }
472
+ }
473
+ })]
474
+ }))]
475
+ });
473
476
  }
474
- })));
475
- }));
477
+ }, _concatInstanceProperty__default["default"](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
478
+ });
476
479
  }
477
480
  }]);
478
481
 
479
482
  return DateTimeInput;
480
- }(React__default['default'].Component);
483
+ }(react$1.Component);
481
484
 
482
485
  DateTimeInput.displayName = 'DateTimeInput';
483
486
  DateTimeInput.propTypes = {};
484
487
  var dateTimeInput = reactIntl.injectIntl(DateTimeInput);
485
488
 
486
- // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
487
- var version = '12.2.2';
489
+ // NOTE: This string will be replaced on build time with the package version.
490
+ var version = "12.2.6";
488
491
 
489
- exports['default'] = dateTimeInput;
492
+ exports["default"] = dateTimeInput;
490
493
  exports.version = version;