@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
  var PropTypes = 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,17 +48,16 @@ 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 PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
53
52
  var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
54
53
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
55
54
 
56
55
  var getInputStyles = function getInputStyles() {
57
- 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, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label: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, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:getInputStyles;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWUtaW5wdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSWdDIiwiZmlsZSI6InRpbWUtaW5wdXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuaW1wb3J0IHsgY3VzdG9tUHJvcGVydGllcyBhcyB2YXJzIH0gZnJvbSAnQGNvbW1lcmNldG9vbHMtdWlraXQvZGVzaWduLXN5c3RlbSc7XG5cbmNvbnN0IGdldElucHV0U3R5bGVzID0gKCkgPT4gY3NzYFxuICB3aWR0aDogMTAwJTtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBib3JkZXI6IDA7XG4gIGJvcmRlci10b3A6IDFweCBzb2xpZCAke3ZhcnMuY29sb3JOZXV0cmFsOTB9O1xuICBwYWRkaW5nOiAxMHB4IDA7XG4gIG91dGxpbmU6IDA7XG4gIGZvbnQtc2l6ZTogJHt2YXJzLmZvbnRTaXplRGVmYXVsdH07XG4gIG1hcmdpbi10b3A6ICR7dmFycy5zcGFjaW5nU307XG4gIGNvbG9yOiAke3ZhcnMuY29sb3JTb2xpZH07XG5cbiAgOmRpc2FibGVkIHtcbiAgICAvKiBGaXhlcyBiYWNrZ3JvdW5kIGNvbG9yIGluIEZpcmVmb3ggKi9cbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAke3ZhcnMuY29sb3JTdXJmYWNlfTtcbiAgfVxuYDtcbmNvbnN0IERhdGVDYWxlbmRhclRpbWVJbnB1dCA9IChwcm9wcykgPT4gKFxuICA8aW5wdXRcbiAgICBkaXNhYmxlZD17cHJvcHMuaXNEaXNhYmxlZH1cbiAgICByZWY9e3Byb3BzLnRpbWVJbnB1dFJlZn1cbiAgICB0eXBlPVwidGV4dFwiXG4gICAgdmFsdWU9e3Byb3BzLnZhbHVlfVxuICAgIG9uQ2hhbmdlPXtwcm9wcy5vbkNoYW5nZX1cbiAgICBvbktleURvd249e3Byb3BzLm9uS2V5RG93bn1cbiAgICBwbGFjZWhvbGRlcj17cHJvcHMucGxhY2Vob2xkZXJ9XG4gICAgY3NzPXtnZXRJbnB1dFN0eWxlcygpfVxuICAvPlxuKTtcblxuRGF0ZUNhbGVuZGFyVGltZUlucHV0LmRpc3BsYXlOYW1lID0gJ0RhdGVDYWxlbmRhclRpbWVJbnB1dCc7XG5cbkRhdGVDYWxlbmRhclRpbWVJbnB1dC5wcm9wVHlwZXMgPSB7XG4gIGlzRGlzYWJsZWQ6IFByb3BUeXBlcy5ib29sLmlzUmVxdWlyZWQsXG4gIHRpbWVJbnB1dFJlZjogUHJvcFR5cGVzLm9iamVjdC5pc1JlcXVpcmVkLFxuICBvbktleURvd246IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIG9uQ2hhbmdlOiBQcm9wVHlwZXMuZnVuYy5pc1JlcXVpcmVkLFxuICB2YWx1ZTogUHJvcFR5cGVzLnN0cmluZy5pc1JlcXVpcmVkLFxuICBwbGFjZWhvbGRlcjogUHJvcFR5cGVzLnN0cmluZyxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IERhdGVDYWxlbmRhclRpbWVJbnB1dDtcbiJdfQ== */");
58
57
  };
59
58
 
60
59
  var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
61
- return react.jsx("input", {
60
+ return jsxRuntime.jsx("input", {
62
61
  disabled: props.isDisabled,
63
62
  ref: props.timeInputRef,
64
63
  type: "text",
@@ -72,12 +71,12 @@ var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
72
71
 
73
72
  DateCalendarTimeInput.displayName = 'DateCalendarTimeInput';
74
73
  DateCalendarTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
75
- isDisabled: PropTypes__default['default'].bool.isRequired,
76
- timeInputRef: PropTypes__default['default'].object.isRequired,
77
- onKeyDown: PropTypes__default['default'].func.isRequired,
78
- onChange: PropTypes__default['default'].func.isRequired,
79
- value: PropTypes__default['default'].string.isRequired,
80
- placeholder: PropTypes__default['default'].string
74
+ isDisabled: PropTypes__default["default"].bool.isRequired,
75
+ timeInputRef: PropTypes__default["default"].object.isRequired,
76
+ onKeyDown: PropTypes__default["default"].func.isRequired,
77
+ onChange: PropTypes__default["default"].func.isRequired,
78
+ value: PropTypes__default["default"].string.isRequired,
79
+ placeholder: PropTypes__default["default"].string
81
80
  } : {};
82
81
  var TimeInput = DateCalendarTimeInput;
83
82
 
@@ -94,14 +93,14 @@ var messages = reactIntl.defineMessages({
94
93
  }
95
94
  });
96
95
 
97
- 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; }
96
+ 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; }
98
97
 
99
- 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; }
98
+ 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; }
100
99
 
101
- 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); }; }
100
+ 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); }; }
102
101
 
103
- 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; } }
104
- var activationTypes = [Downshift__default['default'].stateChangeTypes.keyDownEnter, Downshift__default['default'].stateChangeTypes.clickItem];
102
+ 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; } }
103
+ var activationTypes = [Downshift__default["default"].stateChangeTypes.keyDownEnter, Downshift__default["default"].stateChangeTypes.clickItem];
105
104
 
106
105
  var preventDownshiftDefault = function preventDownshiftDefault(event) {
107
106
  // eslint-disable-next-line no-param-reassign
@@ -120,8 +119,8 @@ var createBlurHandler = function createBlurHandler(timeInputRef) {
120
119
  };
121
120
  };
122
121
 
123
- var DateTimeInput = /*#__PURE__*/function (_React$Component) {
124
- _inherits(DateTimeInput, _React$Component);
122
+ var DateTimeInput = /*#__PURE__*/function (_Component) {
123
+ _inherits(DateTimeInput, _Component);
125
124
 
126
125
  var _super = _createSuper(DateTimeInput);
127
126
 
@@ -136,9 +135,9 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
136
135
  args[_key] = arguments[_key];
137
136
  }
138
137
 
139
- _this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context = [this]).call(_context, args));
140
- _this.inputRef = /*#__PURE__*/React__default['default'].createRef();
141
- _this.timeInputRef = /*#__PURE__*/React__default['default'].createRef();
138
+ _this = _super.call.apply(_super, _concatInstanceProperty__default["default"](_context = [this]).call(_context, args));
139
+ _this.inputRef = /*#__PURE__*/react$1.createRef();
140
+ _this.timeInputRef = /*#__PURE__*/react$1.createRef();
142
141
  _this.state = {
143
142
  calendarDate: calendarTimeUtils.getToday(_this.props.timeZone),
144
143
  suggestedItems: [],
@@ -219,352 +218,356 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
219
218
  var _context2,
220
219
  _this2 = this;
221
220
 
222
- return react.jsx(Constraints__default['default'].Horizontal, {
223
- max: this.props.horizontalConstraint
224
- }, react.jsx(Downshift__default['default'] // Setting the key to the timeZone conveniently forces a rerender
225
- // when the time-zone changes. Otherwise we'd need to make
226
- // inputValue a controlled property so that we can update
227
- // the displayed value as downshift seems to ignore an updated
228
- // itemToString function.
229
- , {
230
- key: _concatInstanceProperty__default['default'](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale),
231
- inputId: this.props.id,
232
- itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
233
- selectedItem: this.props.value === '' ? null : this.props.value,
234
- highlightedIndex: this.state.highlightedIndex,
235
- onChange: this.emit,
236
- stateReducer: function stateReducer(state, changes) {
237
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
238
- return _objectSpread(_objectSpread({}, changes), {}, {
239
- isOpen: true
240
- });
241
- }
242
-
243
- return changes;
244
- },
245
- onStateChange: function onStateChange(changes) {
246
- /* eslint-disable no-prototype-builtins */
247
- _this2.setState(function (prevState) {
248
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
249
- return {
250
- startDate: changes.isOpen ? prevState.startDate : null,
251
- inputValue: changes.inputValue || prevState.inputValue,
252
- timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
253
- };
254
- }
255
-
256
- if (changes.hasOwnProperty('inputValue')) {
257
- var suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, _this2.props.timeZone);
258
- return {
259
- suggestedItems: suggestedItems,
260
- highlightedIndex: suggestedItems.length > 0 ? 0 : null
261
- };
262
- }
263
-
264
- if (changes.hasOwnProperty('isOpen')) {
265
- return {
266
- inputValue: changes.inputValue || prevState.inputValue,
267
- startDate: changes.isOpen ? prevState.startDate : null,
268
- // set time input value to time from value when menu is opened
269
- timeString: changes.isOpen && _this2.props.value !== '' ? calendarTimeUtils.formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
270
- // ensure calendar always opens on selected item, or on
271
- // current month when there is no selected item
272
- calendarDate: _this2.props.value === '' ? calendarTimeUtils.getToday() : _this2.props.value
273
- };
274
- }
275
-
276
- if (changes.hasOwnProperty('highlightedIndex')) {
277
- return {
278
- highlightedIndex: changes.highlightedIndex
279
- };
280
- }
281
-
282
- return null;
283
- }, function () {
284
- if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
285
- _this2.timeInputRef.current.focus();
286
-
287
- _this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
221
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
222
+ max: this.props.horizontalConstraint,
223
+ children: jsxRuntime.jsx(Downshift__default["default"] // Setting the key to the timeZone conveniently forces a rerender
224
+ // when the time-zone changes. Otherwise we'd need to make
225
+ // inputValue a controlled property so that we can update
226
+ // the displayed value as downshift seems to ignore an updated
227
+ // itemToString function.
228
+ , {
229
+ inputId: this.props.id,
230
+ itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
231
+ selectedItem: this.props.value === '' ? null : this.props.value,
232
+ highlightedIndex: this.state.highlightedIndex,
233
+ onChange: this.emit,
234
+ stateReducer: function stateReducer(state, changes) {
235
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
236
+ return _objectSpread(_objectSpread({}, changes), {}, {
237
+ isOpen: true
238
+ });
288
239
  }
289
- });
290
- /* eslint-enable no-prototype-builtins */
291
240
 
292
- }
293
- }, function (_ref) {
294
- var _context3;
295
-
296
- var getInputProps = _ref.getInputProps,
297
- getMenuProps = _ref.getMenuProps,
298
- getItemProps = _ref.getItemProps,
299
- getToggleButtonProps = _ref.getToggleButtonProps,
300
- clearSelection = _ref.clearSelection,
301
- highlightedIndex = _ref.highlightedIndex,
302
- openMenu = _ref.openMenu,
303
- closeMenu = _ref.closeMenu,
304
- setHighlightedIndex = _ref.setHighlightedIndex,
305
- selectedItem = _ref.selectedItem,
306
- inputValue = _ref.inputValue,
307
- isOpen = _ref.isOpen;
308
- var suggestedItems = _this2.state.suggestedItems;
309
- var calendarItems = calendarTimeUtils.createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
310
- var paddingDayCount = calendarTimeUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
311
-
312
- var paddingDays = _fillInstanceProperty__default['default'](_context3 = Array(paddingDayCount)).call(_context3);
313
-
314
- var weekdays = calendarTimeUtils.getWeekdayNames(_this2.props.intl.locale);
315
- var today = calendarTimeUtils.getToday();
316
- var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
317
- return react.jsx("div", {
318
- onFocus: _this2.props.onFocus,
319
- onBlur: _this2.handleBlur
320
- }, react.jsx(calendarUtils.CalendarBody, {
321
- inputRef: _this2.inputRef,
322
- inputProps: getInputProps(_objectSpread({
323
- // Unset the aria-labelledby as it interfers with the link
324
- // between the <label for> and the <input id>.
325
- 'aria-labelledby': undefined,
326
- name: _this2.props.name,
327
- placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
328
- onMouseEnter: function onMouseEnter() {
329
- // we remove the highlight so that the user can use the
330
- // arrow keys to move the cursor when hovering
331
- if (isOpen) setHighlightedIndex(null);
332
- },
333
- onKeyDown: function onKeyDown(event) {
334
- if (_this2.props.isReadOnly) {
335
- preventDownshiftDefault(event);
336
- return;
337
- } // parse input when user presses enter on regular input,
338
- // close menu and notify parent
339
-
340
-
341
- if (event.key === 'Enter' && highlightedIndex === null) {
342
- preventDownshiftDefault(event);
343
- var parsedDate = calendarTimeUtils.parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
344
-
345
- _this2.emit(parsedDate);
346
-
347
- closeMenu();
348
- } // ArrowDown
349
-
350
-
351
- if (event.keyCode === 40) {
352
- if (highlightedIndex + 1 >= calendarItems.length) {
353
- // if it's the end of the month
354
- // then bypass normal arrow navigation
355
- preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
356
- // then jump to start of next month
357
-
358
- _this2.jumpMonths(1, 0);
359
- }
360
- } // ArrowUp
361
-
362
-
363
- if (event.keyCode === 38) {
364
- var previousDay = calendarTimeUtils.getPreviousDay(calendarItems[highlightedIndex]);
365
-
366
- if (highlightedIndex <= 0) {
367
- // if it's the start of the month
368
- // then bypass normal arrow navigation
369
- preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
370
-
371
- var numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
372
-
373
- _this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
374
- }
375
- }
376
- },
377
- onClick: _this2.props.isReadOnly ? undefined : openMenu,
378
- onBlur: createBlurHandler(_this2.timeInputRef),
379
- onChange: function onChange(event) {
380
- // keep timeInput and regular input in sync when user
381
- // types into regular input
382
- if (!isOpen) return;
383
- var time = event.target.value.split(' ')[1];
384
- if (!time) return;
385
- var parsedTime = utils.parseTime(time);
386
-
387
- _this2.setState(function () {
388
- if (!parsedTime) return {
389
- timeString: ''
241
+ return changes;
242
+ },
243
+ onStateChange: function onStateChange(changes) {
244
+ /* eslint-disable no-prototype-builtins */
245
+ _this2.setState(function (prevState) {
246
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
247
+ return {
248
+ startDate: changes.isOpen ? prevState.startDate : null,
249
+ inputValue: changes.inputValue || prevState.inputValue,
250
+ timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
390
251
  };
391
- var date = calendarTimeUtils.getToday(_this2.props.timeZone);
252
+ }
392
253
 
393
- if (parsedTime) {
394
- date = calendarTimeUtils.changeTime(date, _this2.props.timeZone, parsedTime);
395
- }
254
+ if (changes.hasOwnProperty('inputValue')) {
255
+ var suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, _this2.props.timeZone);
256
+ return {
257
+ suggestedItems: suggestedItems,
258
+ highlightedIndex: suggestedItems.length > 0 ? 0 : null
259
+ };
260
+ }
396
261
 
262
+ if (changes.hasOwnProperty('isOpen')) {
397
263
  return {
398
- timeString: calendarTimeUtils.formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
264
+ inputValue: changes.inputValue || prevState.inputValue,
265
+ startDate: changes.isOpen ? prevState.startDate : null,
266
+ // set time input value to time from value when menu is opened
267
+ timeString: changes.isOpen && _this2.props.value !== '' ? calendarTimeUtils.formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
268
+ // ensure calendar always opens on selected item, or on
269
+ // current month when there is no selected item
270
+ calendarDate: _this2.props.value === '' ? calendarTimeUtils.getToday() : _this2.props.value
399
271
  };
400
- });
401
- }
402
- }, utils.filterDataAttributes(_this2.props))),
403
- hasSelection: Boolean(selectedItem),
404
- onClear: clearSelection,
405
- isOpen: isOpen,
406
- isDisabled: _this2.props.isDisabled,
407
- isReadOnly: _this2.props.isReadOnly,
408
- toggleButtonProps: getToggleButtonProps({
409
- onBlur: createBlurHandler(_this2.timeInputRef)
410
- }),
411
- hasError: _this2.props.hasError,
412
- hasWarning: _this2.props.hasWarning
413
- }), isOpen && !_this2.props.isDisabled && react.jsx(calendarUtils.CalendarMenu, _extends({}, getMenuProps(), {
414
- hasFooter: true,
415
- hasError: _this2.props.hasError,
416
- hasWarning: _this2.props.hasWarning
417
- }), react.jsx(calendarUtils.CalendarHeader, {
418
- monthLabel: calendarTimeUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
419
- yearLabel: calendarTimeUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
420
- onPrevMonthClick: function onPrevMonthClick() {
421
- return _this2.jumpMonths(-1);
422
- },
423
- onTodayClick: _this2.showToday,
424
- onNextMonthClick: function onNextMonthClick() {
425
- return _this2.jumpMonths(1);
426
- },
427
- onPrevYearClick: function onPrevYearClick() {
428
- return _this2.jumpMonths(-12);
429
- },
430
- onNextYearClick: function onNextYearClick() {
431
- return _this2.jumpMonths(12);
432
- }
433
- }), react.jsx(calendarUtils.CalendarContent, null, _mapInstanceProperty__default['default'](weekdays).call(weekdays, function (weekday) {
434
- return react.jsx(calendarUtils.CalendarDay, {
435
- key: weekday,
436
- type: "heading"
437
- }, weekday);
438
- }), _mapInstanceProperty__default['default'](paddingDays).call(paddingDays, function (day, index) {
439
- return react.jsx(calendarUtils.CalendarDay, {
440
- key: index,
441
- type: "spacing"
442
- });
443
- }), _mapInstanceProperty__default['default'](calendarItems).call(calendarItems, function (item, index) {
444
- return react.jsx(calendarUtils.CalendarDay, _extends({
445
- key: item,
446
- isToday: calendarTimeUtils.isSameDay(today, item)
447
- }, getItemProps({
448
- disabled: _this2.props.isDisabled,
449
- item: item,
450
- onMouseOut: function onMouseOut() {
451
- setHighlightedIndex(null);
452
- }
453
- }), {
454
- isHighlighted: suggestedItems.length + index === highlightedIndex,
455
- isSelected: calendarTimeUtils.isSameDay(item, _this2.props.value)
456
- }), calendarTimeUtils.getCalendarDayLabel(item, _this2.props.timeZone));
457
- })), react.jsx(TimeInput, {
458
- isDisabled: !isTimeInputVisible,
459
- timeInputRef: _this2.timeInputRef,
460
- placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
461
- value: _this2.state.timeString,
462
- onChange: _this2.handleTimeChange,
463
- onKeyDown: function onKeyDown(event) {
464
- if (event.key === 'ArrowUp') {
465
- setHighlightedIndex(null);
466
-
467
- _this2.inputRef.current.focus();
468
-
469
- return;
470
- }
272
+ }
471
273
 
472
- if (event.key === 'Enter') {
473
- setHighlightedIndex(null);
274
+ if (changes.hasOwnProperty('highlightedIndex')) {
275
+ return {
276
+ highlightedIndex: changes.highlightedIndex
277
+ };
278
+ }
474
279
 
475
- _this2.inputRef.current.focus();
280
+ return null;
281
+ }, function () {
282
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
283
+ _this2.timeInputRef.current.focus();
476
284
 
477
- _this2.inputRef.current.setSelectionRange(0, 100);
285
+ _this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
286
+ }
287
+ });
288
+ /* eslint-enable no-prototype-builtins */
478
289
 
479
- closeMenu();
480
- }
290
+ },
291
+ children: function children(_ref) {
292
+ var _context3;
293
+
294
+ var getInputProps = _ref.getInputProps,
295
+ getMenuProps = _ref.getMenuProps,
296
+ getItemProps = _ref.getItemProps,
297
+ getToggleButtonProps = _ref.getToggleButtonProps,
298
+ clearSelection = _ref.clearSelection,
299
+ highlightedIndex = _ref.highlightedIndex,
300
+ openMenu = _ref.openMenu,
301
+ closeMenu = _ref.closeMenu,
302
+ setHighlightedIndex = _ref.setHighlightedIndex,
303
+ selectedItem = _ref.selectedItem,
304
+ inputValue = _ref.inputValue,
305
+ isOpen = _ref.isOpen;
306
+ var suggestedItems = _this2.state.suggestedItems;
307
+ var calendarItems = calendarTimeUtils.createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
308
+ var paddingDayCount = calendarTimeUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
309
+
310
+ var paddingDays = _fillInstanceProperty__default["default"](_context3 = Array(paddingDayCount)).call(_context3);
311
+
312
+ var weekdays = calendarTimeUtils.getWeekdayNames(_this2.props.intl.locale);
313
+ var today = calendarTimeUtils.getToday();
314
+ var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
315
+ return jsxRuntime.jsxs("div", {
316
+ onFocus: _this2.props.onFocus,
317
+ onBlur: _this2.handleBlur,
318
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
319
+ inputRef: _this2.inputRef,
320
+ inputProps: getInputProps(_objectSpread({
321
+ // Unset the aria-labelledby as it interfers with the link
322
+ // between the <label for> and the <input id>.
323
+ 'aria-labelledby': undefined,
324
+ name: _this2.props.name,
325
+ placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
326
+ onMouseEnter: function onMouseEnter() {
327
+ // we remove the highlight so that the user can use the
328
+ // arrow keys to move the cursor when hovering
329
+ if (isOpen) setHighlightedIndex(null);
330
+ },
331
+ onKeyDown: function onKeyDown(event) {
332
+ if (_this2.props.isReadOnly) {
333
+ preventDownshiftDefault(event);
334
+ return;
335
+ } // parse input when user presses enter on regular input,
336
+ // close menu and notify parent
337
+
338
+
339
+ if (event.key === 'Enter' && highlightedIndex === null) {
340
+ preventDownshiftDefault(event);
341
+ var parsedDate = calendarTimeUtils.parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
342
+
343
+ _this2.emit(parsedDate);
344
+
345
+ closeMenu();
346
+ } // ArrowDown
347
+
348
+
349
+ if (event.keyCode === 40) {
350
+ if (highlightedIndex + 1 >= calendarItems.length) {
351
+ // if it's the end of the month
352
+ // then bypass normal arrow navigation
353
+ preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
354
+ // then jump to start of next month
355
+
356
+ _this2.jumpMonths(1, 0);
357
+ }
358
+ } // ArrowUp
359
+
360
+
361
+ if (event.keyCode === 38) {
362
+ var previousDay = calendarTimeUtils.getPreviousDay(calendarItems[highlightedIndex]);
363
+
364
+ if (highlightedIndex <= 0) {
365
+ // if it's the start of the month
366
+ // then bypass normal arrow navigation
367
+ preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
368
+
369
+ var numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
370
+
371
+ _this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
372
+ }
373
+ }
374
+ },
375
+ onClick: _this2.props.isReadOnly ? undefined : openMenu,
376
+ onBlur: createBlurHandler(_this2.timeInputRef),
377
+ onChange: function onChange(event) {
378
+ // keep timeInput and regular input in sync when user
379
+ // types into regular input
380
+ if (!isOpen) return;
381
+ var time = event.target.value.split(' ')[1];
382
+ if (!time) return;
383
+ var parsedTime = utils.parseTime(time);
384
+
385
+ _this2.setState(function () {
386
+ if (!parsedTime) return {
387
+ timeString: ''
388
+ };
389
+ var date = calendarTimeUtils.getToday(_this2.props.timeZone);
390
+
391
+ if (parsedTime) {
392
+ date = calendarTimeUtils.changeTime(date, _this2.props.timeZone, parsedTime);
393
+ }
394
+
395
+ return {
396
+ timeString: calendarTimeUtils.formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
397
+ };
398
+ });
399
+ }
400
+ }, utils.filterDataAttributes(_this2.props))),
401
+ hasSelection: Boolean(selectedItem),
402
+ onClear: clearSelection,
403
+ isOpen: isOpen,
404
+ isDisabled: _this2.props.isDisabled,
405
+ isReadOnly: _this2.props.isReadOnly,
406
+ toggleButtonProps: getToggleButtonProps({
407
+ onBlur: createBlurHandler(_this2.timeInputRef)
408
+ }),
409
+ hasError: _this2.props.hasError,
410
+ hasWarning: _this2.props.hasWarning
411
+ }), isOpen && !_this2.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
412
+ hasFooter: true,
413
+ hasError: _this2.props.hasError,
414
+ hasWarning: _this2.props.hasWarning,
415
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
416
+ monthLabel: calendarTimeUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
417
+ yearLabel: calendarTimeUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
418
+ onPrevMonthClick: function onPrevMonthClick() {
419
+ return _this2.jumpMonths(-1);
420
+ },
421
+ onTodayClick: _this2.showToday,
422
+ onNextMonthClick: function onNextMonthClick() {
423
+ return _this2.jumpMonths(1);
424
+ },
425
+ onPrevYearClick: function onPrevYearClick() {
426
+ return _this2.jumpMonths(-12);
427
+ },
428
+ onNextYearClick: function onNextYearClick() {
429
+ return _this2.jumpMonths(12);
430
+ }
431
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
432
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, function (weekday) {
433
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, {
434
+ type: "heading",
435
+ children: weekday
436
+ }, weekday);
437
+ }), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, function (day, index) {
438
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, {
439
+ type: "spacing"
440
+ }, index);
441
+ }), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, function (item, index) {
442
+ return jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
443
+ isToday: calendarTimeUtils.isSameDay(today, item)
444
+ }, getItemProps({
445
+ disabled: _this2.props.isDisabled,
446
+ item: item,
447
+ onMouseOut: function onMouseOut() {
448
+ setHighlightedIndex(null);
449
+ }
450
+ })), {}, {
451
+ isHighlighted: suggestedItems.length + index === highlightedIndex,
452
+ isSelected: calendarTimeUtils.isSameDay(item, _this2.props.value),
453
+ children: calendarTimeUtils.getCalendarDayLabel(item, _this2.props.timeZone)
454
+ }), item);
455
+ })]
456
+ }), jsxRuntime.jsx(TimeInput, {
457
+ isDisabled: !isTimeInputVisible,
458
+ timeInputRef: _this2.timeInputRef,
459
+ placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
460
+ value: _this2.state.timeString,
461
+ onChange: _this2.handleTimeChange,
462
+ onKeyDown: function onKeyDown(event) {
463
+ if (event.key === 'ArrowUp') {
464
+ setHighlightedIndex(null);
465
+
466
+ _this2.inputRef.current.focus();
467
+
468
+ return;
469
+ }
470
+
471
+ if (event.key === 'Enter') {
472
+ setHighlightedIndex(null);
473
+
474
+ _this2.inputRef.current.focus();
475
+
476
+ _this2.inputRef.current.setSelectionRange(0, 100);
477
+
478
+ closeMenu();
479
+ }
480
+ }
481
+ })]
482
+ }))]
483
+ });
481
484
  }
482
- })));
483
- }));
485
+ }, _concatInstanceProperty__default["default"](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
486
+ });
484
487
  }
485
488
  }]);
486
489
 
487
490
  return DateTimeInput;
488
- }(React__default['default'].Component);
491
+ }(react$1.Component);
489
492
 
490
493
  DateTimeInput.displayName = 'DateTimeInput';
491
494
  DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
492
- intl: PropTypes__default['default'].shape({
493
- locale: PropTypes__default['default'].string.isRequired,
494
- formatMessage: PropTypes__default['default'].func.isRequired
495
+ intl: PropTypes__default["default"].shape({
496
+ locale: PropTypes__default["default"].string.isRequired,
497
+ formatMessage: PropTypes__default["default"].func.isRequired
495
498
  }).isRequired,
496
499
 
497
500
  /**
498
501
  * Horizontal size limit of the input field.
499
502
  */
500
- horizontalConstraint: PropTypes__default['default'].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
503
+ horizontalConstraint: PropTypes__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
501
504
 
502
505
  /**
503
506
  * The selected date, must either be an empty string or a date formatted in ISO 8601 (e.g. "2018-10-04T09:00:00.000Z").
504
507
  */
505
- value: PropTypes__default['default'].string.isRequired,
508
+ value: PropTypes__default["default"].string.isRequired,
506
509
 
507
510
  /**
508
511
  * Called when the date changes. Called with an event containing an empty string (no value) or a string in this format: "YYYY-MM-DD".
509
512
  * <br />
510
513
  * Signature: `(event) => void`
511
514
  */
512
- onChange: PropTypes__default['default'].func.isRequired,
515
+ onChange: PropTypes__default["default"].func.isRequired,
513
516
 
514
517
  /**
515
518
  * Called when the date input gains focus.
516
519
  */
517
- onFocus: PropTypes__default['default'].func,
520
+ onFocus: PropTypes__default["default"].func,
518
521
 
519
522
  /**
520
523
  * Called when the date input loses focus.
521
524
  */
522
- onBlur: PropTypes__default['default'].func,
525
+ onBlur: PropTypes__default["default"].func,
523
526
 
524
527
  /**
525
528
  * Specifies the time zone in which the calendar and selected values are shown. It also influences how entered dates and times are parsed.
526
529
  */
527
- timeZone: PropTypes__default['default'].string.isRequired,
530
+ timeZone: PropTypes__default["default"].string.isRequired,
528
531
 
529
532
  /**
530
533
  * Used as the HTML `id` attribute.
531
534
  */
532
- id: PropTypes__default['default'].string,
535
+ id: PropTypes__default["default"].string,
533
536
 
534
537
  /**
535
538
  * Used as the HTML `name` attribute.
536
539
  */
537
- name: PropTypes__default['default'].string,
540
+ name: PropTypes__default["default"].string,
538
541
 
539
542
  /**
540
543
  * Placeholder value to show in the input field
541
544
  */
542
- placeholder: PropTypes__default['default'].string,
545
+ placeholder: PropTypes__default["default"].string,
543
546
 
544
547
  /**
545
548
  * Disables the date picker
546
549
  */
547
- isDisabled: PropTypes__default['default'].bool,
550
+ isDisabled: PropTypes__default["default"].bool,
548
551
 
549
552
  /**
550
553
  * Disables the date picker menu and sets the input field as read-only
551
554
  */
552
- isReadOnly: PropTypes__default['default'].bool,
555
+ isReadOnly: PropTypes__default["default"].bool,
553
556
 
554
557
  /**
555
558
  * Indicates the input field has an error
556
559
  */
557
- hasError: PropTypes__default['default'].bool,
560
+ hasError: PropTypes__default["default"].bool,
558
561
 
559
562
  /**
560
563
  * Indicates the input field has a warning
561
564
  */
562
- hasWarning: PropTypes__default['default'].bool
565
+ hasWarning: PropTypes__default["default"].bool
563
566
  } : {};
564
567
  var dateTimeInput = reactIntl.injectIntl(DateTimeInput);
565
568
 
566
- // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
567
- var version = '12.2.2';
569
+ // NOTE: This string will be replaced on build time with the package version.
570
+ var version = "12.2.6";
568
571
 
569
- exports['default'] = dateTimeInput;
572
+ exports["default"] = dateTimeInput;
570
573
  exports.version = version;