@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.
|
@@ -7,7 +7,6 @@ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/inst
|
|
|
7
7
|
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
8
8
|
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
9
9
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
10
|
-
import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
|
|
11
10
|
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
12
11
|
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
13
12
|
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
@@ -18,7 +17,7 @@ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/insta
|
|
|
18
17
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
19
18
|
import _fillInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/fill';
|
|
20
19
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
21
|
-
import
|
|
20
|
+
import { createRef, Component } from 'react';
|
|
22
21
|
import PropTypes from 'prop-types';
|
|
23
22
|
import Downshift from 'downshift';
|
|
24
23
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
@@ -26,11 +25,12 @@ import Constraints from '@commercetools-uikit/constraints';
|
|
|
26
25
|
import { parseTime, filterDataAttributes } from '@commercetools-uikit/utils';
|
|
27
26
|
import { getToday, getDateInMonth, changeMonth, getStartOf, changeTime, createItemDateTimeToString, formatTime, createSuggestedItems, createCalendarItems, getPaddingDayCount, getWeekdayNames, parseInputText, getPreviousDay, getDaysInMonth, getMonthCalendarLabel, getYearCalendarLabel, isSameDay, getCalendarDayLabel } from '@commercetools-uikit/calendar-time-utils';
|
|
28
27
|
import { CalendarBody, CalendarMenu, CalendarHeader, CalendarContent, CalendarDay } from '@commercetools-uikit/calendar-utils';
|
|
29
|
-
import {
|
|
28
|
+
import { css } from '@emotion/react';
|
|
30
29
|
import { customProperties } from '@commercetools-uikit/design-system';
|
|
30
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
31
31
|
|
|
32
32
|
var getInputStyles = function getInputStyles() {
|
|
33
|
-
return /*#__PURE__*/css("width:100%;text-align:center;border:0;border-top:1px solid ", customProperties.colorNeutral90, ";padding:10px 0;outline:0;font-size:", customProperties.fontSizeDefault, ";margin-top:", customProperties.spacingS, ";color:", customProperties.colorSolid, ";:disabled{background-color:", customProperties.colorSurface, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:getInputStyles;"));
|
|
33
|
+
return /*#__PURE__*/css("width:100%;text-align:center;border:0;border-top:1px solid ", customProperties.colorNeutral90, ";padding:10px 0;outline:0;font-size:", customProperties.fontSizeDefault, ";margin-top:", customProperties.spacingS, ";color:", customProperties.colorSolid, ";:disabled{background-color:", customProperties.colorSurface, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:getInputStyles;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWUtaW5wdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSWdDIiwiZmlsZSI6InRpbWUtaW5wdXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuaW1wb3J0IHsgY3VzdG9tUHJvcGVydGllcyBhcyB2YXJzIH0gZnJvbSAnQGNvbW1lcmNldG9vbHMtdWlraXQvZGVzaWduLXN5c3RlbSc7XG5cbmNvbnN0IGdldElucHV0U3R5bGVzID0gKCkgPT4gY3NzYFxuICB3aWR0aDogMTAwJTtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBib3JkZXI6IDA7XG4gIGJvcmRlci10b3A6IDFweCBzb2xpZCAke3ZhcnMuY29sb3JOZXV0cmFsOTB9O1xuICBwYWRkaW5nOiAxMHB4IDA7XG4gIG91dGxpbmU6IDA7XG4gIGZvbnQtc2l6ZTogJHt2YXJzLmZvbnRTaXplRGVmYXVsdH07XG4gIG1hcmdpbi10b3A6ICR7dmFycy5zcGFjaW5nU307XG4gIGNvbG9yOiAke3ZhcnMuY29sb3JTb2xpZH07XG5cbiAgOmRpc2FibGVkIHtcbiAgICAvKiBGaXhlcyBiYWNrZ3JvdW5kIGNvbG9yIGluIEZpcmVmb3ggKi9cbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAke3ZhcnMuY29sb3JTdXJmYWNlfTtcbiAgfVxuYDtcbmNvbnN0IERhdGVDYWxlbmRhclRpbWVJbnB1dCA9IChwcm9wcykgPT4gKFxuICA8aW5wdXRcbiAgICBkaXNhYmxlZD17cHJvcHMuaXNEaXNhYmxlZH1cbiAgICByZWY9e3Byb3BzLnRpbWVJbnB1dFJlZn1cbiAgICB0eXBlPVwidGV4dFwiXG4gICAgdmFsdWU9e3Byb3BzLnZhbHVlfVxuICAgIG9uQ2hhbmdlPXtwcm9wcy5vbkNoYW5nZX1cbiAgICBvbktleURvd249e3Byb3BzLm9uS2V5RG93bn1cbiAgICBwbGFjZWhvbGRlcj17cHJvcHMucGxhY2Vob2xkZXJ9XG4gICAgY3NzPXtnZXRJbnB1dFN0eWxlcygpfVxuICAvPlxuKTtcblxuRGF0ZUNhbGVuZGFyVGltZUlucHV0LmRpc3BsYXlOYW1lID0gJ0RhdGVDYWxlbmRhclRpbWVJbnB1dCc7XG5cbkRhdGVDYWxlbmRhclRpbWVJbnB1dC5wcm9wVHlwZXMgPSB7XG4gIGlzRGlzYWJsZWQ6IFByb3BUeXBlcy5ib29sLmlzUmVxdWlyZWQsXG4gIHRpbWVJbnB1dFJlZjogUHJvcFR5cGVzLm9iamVjdC5pc1JlcXVpcmVkLFxuICBvbktleURvd246IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIG9uQ2hhbmdlOiBQcm9wVHlwZXMuZnVuYy5pc1JlcXVpcmVkLFxuICB2YWx1ZTogUHJvcFR5cGVzLnN0cmluZy5pc1JlcXVpcmVkLFxuICBwbGFjZWhvbGRlcjogUHJvcFR5cGVzLnN0cmluZyxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IERhdGVDYWxlbmRhclRpbWVJbnB1dDtcbiJdfQ== */");
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
|
|
@@ -96,8 +96,8 @@ var createBlurHandler = function createBlurHandler(timeInputRef) {
|
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
var DateTimeInput = /*#__PURE__*/function (
|
|
100
|
-
_inherits(DateTimeInput,
|
|
99
|
+
var DateTimeInput = /*#__PURE__*/function (_Component) {
|
|
100
|
+
_inherits(DateTimeInput, _Component);
|
|
101
101
|
|
|
102
102
|
var _super = _createSuper(DateTimeInput);
|
|
103
103
|
|
|
@@ -113,8 +113,8 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
_this = _super.call.apply(_super, _concatInstanceProperty(_context = [this]).call(_context, args));
|
|
116
|
-
_this.inputRef = /*#__PURE__*/
|
|
117
|
-
_this.timeInputRef = /*#__PURE__*/
|
|
116
|
+
_this.inputRef = /*#__PURE__*/createRef();
|
|
117
|
+
_this.timeInputRef = /*#__PURE__*/createRef();
|
|
118
118
|
_this.state = {
|
|
119
119
|
calendarDate: getToday(_this.props.timeZone),
|
|
120
120
|
suggestedItems: [],
|
|
@@ -196,272 +196,276 @@ var DateTimeInput = /*#__PURE__*/function (_React$Component) {
|
|
|
196
196
|
_this2 = this;
|
|
197
197
|
|
|
198
198
|
return jsx(Constraints.Horizontal, {
|
|
199
|
-
max: this.props.horizontalConstraint
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
stateReducer: function stateReducer(state, changes) {
|
|
213
|
-
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
214
|
-
return _objectSpread(_objectSpread({}, changes), {}, {
|
|
215
|
-
isOpen: true
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return changes;
|
|
220
|
-
},
|
|
221
|
-
onStateChange: function onStateChange(changes) {
|
|
222
|
-
/* eslint-disable no-prototype-builtins */
|
|
223
|
-
_this2.setState(function (prevState) {
|
|
224
|
-
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
225
|
-
return {
|
|
226
|
-
startDate: changes.isOpen ? prevState.startDate : null,
|
|
227
|
-
inputValue: changes.inputValue || prevState.inputValue,
|
|
228
|
-
timeString: changes.selectedItem ? formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (changes.hasOwnProperty('inputValue')) {
|
|
233
|
-
var suggestedItems = createSuggestedItems(changes.inputValue, _this2.props.timeZone);
|
|
234
|
-
return {
|
|
235
|
-
suggestedItems: suggestedItems,
|
|
236
|
-
highlightedIndex: suggestedItems.length > 0 ? 0 : null
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (changes.hasOwnProperty('isOpen')) {
|
|
241
|
-
return {
|
|
242
|
-
inputValue: changes.inputValue || prevState.inputValue,
|
|
243
|
-
startDate: changes.isOpen ? prevState.startDate : null,
|
|
244
|
-
// set time input value to time from value when menu is opened
|
|
245
|
-
timeString: changes.isOpen && _this2.props.value !== '' ? formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
|
|
246
|
-
// ensure calendar always opens on selected item, or on
|
|
247
|
-
// current month when there is no selected item
|
|
248
|
-
calendarDate: _this2.props.value === '' ? getToday() : _this2.props.value
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
253
|
-
return {
|
|
254
|
-
highlightedIndex: changes.highlightedIndex
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return null;
|
|
259
|
-
}, function () {
|
|
199
|
+
max: this.props.horizontalConstraint,
|
|
200
|
+
children: jsx(Downshift // Setting the key to the timeZone conveniently forces a rerender
|
|
201
|
+
// when the time-zone changes. Otherwise we'd need to make
|
|
202
|
+
// inputValue a controlled property so that we can update
|
|
203
|
+
// the displayed value as downshift seems to ignore an updated
|
|
204
|
+
// itemToString function.
|
|
205
|
+
, {
|
|
206
|
+
inputId: this.props.id,
|
|
207
|
+
itemToString: createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
|
|
208
|
+
selectedItem: this.props.value === '' ? null : this.props.value,
|
|
209
|
+
highlightedIndex: this.state.highlightedIndex,
|
|
210
|
+
onChange: this.emit,
|
|
211
|
+
stateReducer: function stateReducer(state, changes) {
|
|
260
212
|
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
213
|
+
return _objectSpread(_objectSpread({}, changes), {}, {
|
|
214
|
+
isOpen: true
|
|
215
|
+
});
|
|
264
216
|
}
|
|
265
|
-
});
|
|
266
|
-
/* eslint-enable no-prototype-builtins */
|
|
267
217
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
openMenu = _ref.openMenu,
|
|
279
|
-
closeMenu = _ref.closeMenu,
|
|
280
|
-
setHighlightedIndex = _ref.setHighlightedIndex,
|
|
281
|
-
selectedItem = _ref.selectedItem,
|
|
282
|
-
inputValue = _ref.inputValue,
|
|
283
|
-
isOpen = _ref.isOpen;
|
|
284
|
-
var suggestedItems = _this2.state.suggestedItems;
|
|
285
|
-
var calendarItems = createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
|
|
286
|
-
var paddingDayCount = getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
|
|
287
|
-
|
|
288
|
-
var paddingDays = _fillInstanceProperty(_context3 = Array(paddingDayCount)).call(_context3);
|
|
289
|
-
|
|
290
|
-
var weekdays = getWeekdayNames(_this2.props.intl.locale);
|
|
291
|
-
var today = getToday();
|
|
292
|
-
var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
|
|
293
|
-
return jsx("div", {
|
|
294
|
-
onFocus: _this2.props.onFocus,
|
|
295
|
-
onBlur: _this2.handleBlur
|
|
296
|
-
}, jsx(CalendarBody, {
|
|
297
|
-
inputRef: _this2.inputRef,
|
|
298
|
-
inputProps: getInputProps(_objectSpread({
|
|
299
|
-
// Unset the aria-labelledby as it interfers with the link
|
|
300
|
-
// between the <label for> and the <input id>.
|
|
301
|
-
'aria-labelledby': undefined,
|
|
302
|
-
name: _this2.props.name,
|
|
303
|
-
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
304
|
-
onMouseEnter: function onMouseEnter() {
|
|
305
|
-
// we remove the highlight so that the user can use the
|
|
306
|
-
// arrow keys to move the cursor when hovering
|
|
307
|
-
if (isOpen) setHighlightedIndex(null);
|
|
308
|
-
},
|
|
309
|
-
onKeyDown: function onKeyDown(event) {
|
|
310
|
-
if (_this2.props.isReadOnly) {
|
|
311
|
-
preventDownshiftDefault(event);
|
|
312
|
-
return;
|
|
313
|
-
} // parse input when user presses enter on regular input,
|
|
314
|
-
// close menu and notify parent
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (event.key === 'Enter' && highlightedIndex === null) {
|
|
318
|
-
preventDownshiftDefault(event);
|
|
319
|
-
var parsedDate = parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
|
|
320
|
-
|
|
321
|
-
_this2.emit(parsedDate);
|
|
322
|
-
|
|
323
|
-
closeMenu();
|
|
324
|
-
} // ArrowDown
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (event.keyCode === 40) {
|
|
328
|
-
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
329
|
-
// if it's the end of the month
|
|
330
|
-
// then bypass normal arrow navigation
|
|
331
|
-
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
332
|
-
// then jump to start of next month
|
|
333
|
-
|
|
334
|
-
_this2.jumpMonths(1, 0);
|
|
335
|
-
}
|
|
336
|
-
} // ArrowUp
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if (event.keyCode === 38) {
|
|
340
|
-
var previousDay = getPreviousDay(calendarItems[highlightedIndex]);
|
|
341
|
-
|
|
342
|
-
if (highlightedIndex <= 0) {
|
|
343
|
-
// if it's the start of the month
|
|
344
|
-
// then bypass normal arrow navigation
|
|
345
|
-
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
346
|
-
|
|
347
|
-
var numberOfDaysOfPrevMonth = getDaysInMonth(previousDay); // then jump to the last day of the previous month
|
|
348
|
-
|
|
349
|
-
_this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
onClick: _this2.props.isReadOnly ? undefined : openMenu,
|
|
354
|
-
onBlur: createBlurHandler(_this2.timeInputRef),
|
|
355
|
-
onChange: function onChange(event) {
|
|
356
|
-
// keep timeInput and regular input in sync when user
|
|
357
|
-
// types into regular input
|
|
358
|
-
if (!isOpen) return;
|
|
359
|
-
var time = event.target.value.split(' ')[1];
|
|
360
|
-
if (!time) return;
|
|
361
|
-
var parsedTime = parseTime(time);
|
|
362
|
-
|
|
363
|
-
_this2.setState(function () {
|
|
364
|
-
if (!parsedTime) return {
|
|
365
|
-
timeString: ''
|
|
218
|
+
return changes;
|
|
219
|
+
},
|
|
220
|
+
onStateChange: function onStateChange(changes) {
|
|
221
|
+
/* eslint-disable no-prototype-builtins */
|
|
222
|
+
_this2.setState(function (prevState) {
|
|
223
|
+
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
224
|
+
return {
|
|
225
|
+
startDate: changes.isOpen ? prevState.startDate : null,
|
|
226
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
227
|
+
timeString: changes.selectedItem ? formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
|
|
366
228
|
};
|
|
367
|
-
|
|
229
|
+
}
|
|
368
230
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
231
|
+
if (changes.hasOwnProperty('inputValue')) {
|
|
232
|
+
var suggestedItems = createSuggestedItems(changes.inputValue, _this2.props.timeZone);
|
|
233
|
+
return {
|
|
234
|
+
suggestedItems: suggestedItems,
|
|
235
|
+
highlightedIndex: suggestedItems.length > 0 ? 0 : null
|
|
236
|
+
};
|
|
237
|
+
}
|
|
372
238
|
|
|
239
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
373
240
|
return {
|
|
374
|
-
|
|
241
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
242
|
+
startDate: changes.isOpen ? prevState.startDate : null,
|
|
243
|
+
// set time input value to time from value when menu is opened
|
|
244
|
+
timeString: changes.isOpen && _this2.props.value !== '' ? formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
|
|
245
|
+
// ensure calendar always opens on selected item, or on
|
|
246
|
+
// current month when there is no selected item
|
|
247
|
+
calendarDate: _this2.props.value === '' ? getToday() : _this2.props.value
|
|
375
248
|
};
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}, filterDataAttributes(_this2.props))),
|
|
379
|
-
hasSelection: Boolean(selectedItem),
|
|
380
|
-
onClear: clearSelection,
|
|
381
|
-
isOpen: isOpen,
|
|
382
|
-
isDisabled: _this2.props.isDisabled,
|
|
383
|
-
isReadOnly: _this2.props.isReadOnly,
|
|
384
|
-
toggleButtonProps: getToggleButtonProps({
|
|
385
|
-
onBlur: createBlurHandler(_this2.timeInputRef)
|
|
386
|
-
}),
|
|
387
|
-
hasError: _this2.props.hasError,
|
|
388
|
-
hasWarning: _this2.props.hasWarning
|
|
389
|
-
}), isOpen && !_this2.props.isDisabled && jsx(CalendarMenu, _extends({}, getMenuProps(), {
|
|
390
|
-
hasFooter: true,
|
|
391
|
-
hasError: _this2.props.hasError,
|
|
392
|
-
hasWarning: _this2.props.hasWarning
|
|
393
|
-
}), jsx(CalendarHeader, {
|
|
394
|
-
monthLabel: getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
395
|
-
yearLabel: getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
396
|
-
onPrevMonthClick: function onPrevMonthClick() {
|
|
397
|
-
return _this2.jumpMonths(-1);
|
|
398
|
-
},
|
|
399
|
-
onTodayClick: _this2.showToday,
|
|
400
|
-
onNextMonthClick: function onNextMonthClick() {
|
|
401
|
-
return _this2.jumpMonths(1);
|
|
402
|
-
},
|
|
403
|
-
onPrevYearClick: function onPrevYearClick() {
|
|
404
|
-
return _this2.jumpMonths(-12);
|
|
405
|
-
},
|
|
406
|
-
onNextYearClick: function onNextYearClick() {
|
|
407
|
-
return _this2.jumpMonths(12);
|
|
408
|
-
}
|
|
409
|
-
}), jsx(CalendarContent, null, _mapInstanceProperty(weekdays).call(weekdays, function (weekday) {
|
|
410
|
-
return jsx(CalendarDay, {
|
|
411
|
-
key: weekday,
|
|
412
|
-
type: "heading"
|
|
413
|
-
}, weekday);
|
|
414
|
-
}), _mapInstanceProperty(paddingDays).call(paddingDays, function (day, index) {
|
|
415
|
-
return jsx(CalendarDay, {
|
|
416
|
-
key: index,
|
|
417
|
-
type: "spacing"
|
|
418
|
-
});
|
|
419
|
-
}), _mapInstanceProperty(calendarItems).call(calendarItems, function (item, index) {
|
|
420
|
-
return jsx(CalendarDay, _extends({
|
|
421
|
-
key: item,
|
|
422
|
-
isToday: isSameDay(today, item)
|
|
423
|
-
}, getItemProps({
|
|
424
|
-
disabled: _this2.props.isDisabled,
|
|
425
|
-
item: item,
|
|
426
|
-
onMouseOut: function onMouseOut() {
|
|
427
|
-
setHighlightedIndex(null);
|
|
428
|
-
}
|
|
429
|
-
}), {
|
|
430
|
-
isHighlighted: suggestedItems.length + index === highlightedIndex,
|
|
431
|
-
isSelected: isSameDay(item, _this2.props.value)
|
|
432
|
-
}), getCalendarDayLabel(item, _this2.props.timeZone));
|
|
433
|
-
})), jsx(TimeInput, {
|
|
434
|
-
isDisabled: !isTimeInputVisible,
|
|
435
|
-
timeInputRef: _this2.timeInputRef,
|
|
436
|
-
placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
|
|
437
|
-
value: _this2.state.timeString,
|
|
438
|
-
onChange: _this2.handleTimeChange,
|
|
439
|
-
onKeyDown: function onKeyDown(event) {
|
|
440
|
-
if (event.key === 'ArrowUp') {
|
|
441
|
-
setHighlightedIndex(null);
|
|
442
|
-
|
|
443
|
-
_this2.inputRef.current.focus();
|
|
444
|
-
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
249
|
+
}
|
|
447
250
|
|
|
448
|
-
|
|
449
|
-
|
|
251
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
252
|
+
return {
|
|
253
|
+
highlightedIndex: changes.highlightedIndex
|
|
254
|
+
};
|
|
255
|
+
}
|
|
450
256
|
|
|
451
|
-
|
|
257
|
+
return null;
|
|
258
|
+
}, function () {
|
|
259
|
+
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
260
|
+
_this2.timeInputRef.current.focus();
|
|
452
261
|
|
|
453
|
-
|
|
262
|
+
_this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
/* eslint-enable no-prototype-builtins */
|
|
454
266
|
|
|
455
|
-
|
|
456
|
-
|
|
267
|
+
},
|
|
268
|
+
children: function children(_ref) {
|
|
269
|
+
var _context3;
|
|
270
|
+
|
|
271
|
+
var getInputProps = _ref.getInputProps,
|
|
272
|
+
getMenuProps = _ref.getMenuProps,
|
|
273
|
+
getItemProps = _ref.getItemProps,
|
|
274
|
+
getToggleButtonProps = _ref.getToggleButtonProps,
|
|
275
|
+
clearSelection = _ref.clearSelection,
|
|
276
|
+
highlightedIndex = _ref.highlightedIndex,
|
|
277
|
+
openMenu = _ref.openMenu,
|
|
278
|
+
closeMenu = _ref.closeMenu,
|
|
279
|
+
setHighlightedIndex = _ref.setHighlightedIndex,
|
|
280
|
+
selectedItem = _ref.selectedItem,
|
|
281
|
+
inputValue = _ref.inputValue,
|
|
282
|
+
isOpen = _ref.isOpen;
|
|
283
|
+
var suggestedItems = _this2.state.suggestedItems;
|
|
284
|
+
var calendarItems = createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
|
|
285
|
+
var paddingDayCount = getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
|
|
286
|
+
|
|
287
|
+
var paddingDays = _fillInstanceProperty(_context3 = Array(paddingDayCount)).call(_context3);
|
|
288
|
+
|
|
289
|
+
var weekdays = getWeekdayNames(_this2.props.intl.locale);
|
|
290
|
+
var today = getToday();
|
|
291
|
+
var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
|
|
292
|
+
return jsxs("div", {
|
|
293
|
+
onFocus: _this2.props.onFocus,
|
|
294
|
+
onBlur: _this2.handleBlur,
|
|
295
|
+
children: [jsx(CalendarBody, {
|
|
296
|
+
inputRef: _this2.inputRef,
|
|
297
|
+
inputProps: getInputProps(_objectSpread({
|
|
298
|
+
// Unset the aria-labelledby as it interfers with the link
|
|
299
|
+
// between the <label for> and the <input id>.
|
|
300
|
+
'aria-labelledby': undefined,
|
|
301
|
+
name: _this2.props.name,
|
|
302
|
+
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
303
|
+
onMouseEnter: function onMouseEnter() {
|
|
304
|
+
// we remove the highlight so that the user can use the
|
|
305
|
+
// arrow keys to move the cursor when hovering
|
|
306
|
+
if (isOpen) setHighlightedIndex(null);
|
|
307
|
+
},
|
|
308
|
+
onKeyDown: function onKeyDown(event) {
|
|
309
|
+
if (_this2.props.isReadOnly) {
|
|
310
|
+
preventDownshiftDefault(event);
|
|
311
|
+
return;
|
|
312
|
+
} // parse input when user presses enter on regular input,
|
|
313
|
+
// close menu and notify parent
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
if (event.key === 'Enter' && highlightedIndex === null) {
|
|
317
|
+
preventDownshiftDefault(event);
|
|
318
|
+
var parsedDate = parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
|
|
319
|
+
|
|
320
|
+
_this2.emit(parsedDate);
|
|
321
|
+
|
|
322
|
+
closeMenu();
|
|
323
|
+
} // ArrowDown
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
if (event.keyCode === 40) {
|
|
327
|
+
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
328
|
+
// if it's the end of the month
|
|
329
|
+
// then bypass normal arrow navigation
|
|
330
|
+
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
331
|
+
// then jump to start of next month
|
|
332
|
+
|
|
333
|
+
_this2.jumpMonths(1, 0);
|
|
334
|
+
}
|
|
335
|
+
} // ArrowUp
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
if (event.keyCode === 38) {
|
|
339
|
+
var previousDay = getPreviousDay(calendarItems[highlightedIndex]);
|
|
340
|
+
|
|
341
|
+
if (highlightedIndex <= 0) {
|
|
342
|
+
// if it's the start of the month
|
|
343
|
+
// then bypass normal arrow navigation
|
|
344
|
+
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
345
|
+
|
|
346
|
+
var numberOfDaysOfPrevMonth = getDaysInMonth(previousDay); // then jump to the last day of the previous month
|
|
347
|
+
|
|
348
|
+
_this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
onClick: _this2.props.isReadOnly ? undefined : openMenu,
|
|
353
|
+
onBlur: createBlurHandler(_this2.timeInputRef),
|
|
354
|
+
onChange: function onChange(event) {
|
|
355
|
+
// keep timeInput and regular input in sync when user
|
|
356
|
+
// types into regular input
|
|
357
|
+
if (!isOpen) return;
|
|
358
|
+
var time = event.target.value.split(' ')[1];
|
|
359
|
+
if (!time) return;
|
|
360
|
+
var parsedTime = parseTime(time);
|
|
361
|
+
|
|
362
|
+
_this2.setState(function () {
|
|
363
|
+
if (!parsedTime) return {
|
|
364
|
+
timeString: ''
|
|
365
|
+
};
|
|
366
|
+
var date = getToday(_this2.props.timeZone);
|
|
367
|
+
|
|
368
|
+
if (parsedTime) {
|
|
369
|
+
date = changeTime(date, _this2.props.timeZone, parsedTime);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
timeString: formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}, filterDataAttributes(_this2.props))),
|
|
378
|
+
hasSelection: Boolean(selectedItem),
|
|
379
|
+
onClear: clearSelection,
|
|
380
|
+
isOpen: isOpen,
|
|
381
|
+
isDisabled: _this2.props.isDisabled,
|
|
382
|
+
isReadOnly: _this2.props.isReadOnly,
|
|
383
|
+
toggleButtonProps: getToggleButtonProps({
|
|
384
|
+
onBlur: createBlurHandler(_this2.timeInputRef)
|
|
385
|
+
}),
|
|
386
|
+
hasError: _this2.props.hasError,
|
|
387
|
+
hasWarning: _this2.props.hasWarning
|
|
388
|
+
}), isOpen && !_this2.props.isDisabled && jsxs(CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
|
|
389
|
+
hasFooter: true,
|
|
390
|
+
hasError: _this2.props.hasError,
|
|
391
|
+
hasWarning: _this2.props.hasWarning,
|
|
392
|
+
children: [jsx(CalendarHeader, {
|
|
393
|
+
monthLabel: getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
394
|
+
yearLabel: getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
395
|
+
onPrevMonthClick: function onPrevMonthClick() {
|
|
396
|
+
return _this2.jumpMonths(-1);
|
|
397
|
+
},
|
|
398
|
+
onTodayClick: _this2.showToday,
|
|
399
|
+
onNextMonthClick: function onNextMonthClick() {
|
|
400
|
+
return _this2.jumpMonths(1);
|
|
401
|
+
},
|
|
402
|
+
onPrevYearClick: function onPrevYearClick() {
|
|
403
|
+
return _this2.jumpMonths(-12);
|
|
404
|
+
},
|
|
405
|
+
onNextYearClick: function onNextYearClick() {
|
|
406
|
+
return _this2.jumpMonths(12);
|
|
407
|
+
}
|
|
408
|
+
}), jsxs(CalendarContent, {
|
|
409
|
+
children: [_mapInstanceProperty(weekdays).call(weekdays, function (weekday) {
|
|
410
|
+
return jsx(CalendarDay, {
|
|
411
|
+
type: "heading",
|
|
412
|
+
children: weekday
|
|
413
|
+
}, weekday);
|
|
414
|
+
}), _mapInstanceProperty(paddingDays).call(paddingDays, function (day, index) {
|
|
415
|
+
return jsx(CalendarDay, {
|
|
416
|
+
type: "spacing"
|
|
417
|
+
}, index);
|
|
418
|
+
}), _mapInstanceProperty(calendarItems).call(calendarItems, function (item, index) {
|
|
419
|
+
return jsx(CalendarDay, _objectSpread(_objectSpread({
|
|
420
|
+
isToday: isSameDay(today, item)
|
|
421
|
+
}, getItemProps({
|
|
422
|
+
disabled: _this2.props.isDisabled,
|
|
423
|
+
item: item,
|
|
424
|
+
onMouseOut: function onMouseOut() {
|
|
425
|
+
setHighlightedIndex(null);
|
|
426
|
+
}
|
|
427
|
+
})), {}, {
|
|
428
|
+
isHighlighted: suggestedItems.length + index === highlightedIndex,
|
|
429
|
+
isSelected: isSameDay(item, _this2.props.value),
|
|
430
|
+
children: getCalendarDayLabel(item, _this2.props.timeZone)
|
|
431
|
+
}), item);
|
|
432
|
+
})]
|
|
433
|
+
}), jsx(TimeInput, {
|
|
434
|
+
isDisabled: !isTimeInputVisible,
|
|
435
|
+
timeInputRef: _this2.timeInputRef,
|
|
436
|
+
placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
|
|
437
|
+
value: _this2.state.timeString,
|
|
438
|
+
onChange: _this2.handleTimeChange,
|
|
439
|
+
onKeyDown: function onKeyDown(event) {
|
|
440
|
+
if (event.key === 'ArrowUp') {
|
|
441
|
+
setHighlightedIndex(null);
|
|
442
|
+
|
|
443
|
+
_this2.inputRef.current.focus();
|
|
444
|
+
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (event.key === 'Enter') {
|
|
449
|
+
setHighlightedIndex(null);
|
|
450
|
+
|
|
451
|
+
_this2.inputRef.current.focus();
|
|
452
|
+
|
|
453
|
+
_this2.inputRef.current.setSelectionRange(0, 100);
|
|
454
|
+
|
|
455
|
+
closeMenu();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
})]
|
|
459
|
+
}))]
|
|
460
|
+
});
|
|
457
461
|
}
|
|
458
|
-
})))
|
|
459
|
-
})
|
|
462
|
+
}, _concatInstanceProperty(_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
|
|
463
|
+
});
|
|
460
464
|
}
|
|
461
465
|
}]);
|
|
462
466
|
|
|
463
467
|
return DateTimeInput;
|
|
464
|
-
}(
|
|
468
|
+
}(Component);
|
|
465
469
|
|
|
466
470
|
DateTimeInput.displayName = 'DateTimeInput';
|
|
467
471
|
DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
@@ -539,7 +543,7 @@ DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
539
543
|
} : {};
|
|
540
544
|
var dateTimeInput = injectIntl(DateTimeInput);
|
|
541
545
|
|
|
542
|
-
// NOTE: This string will be replaced
|
|
543
|
-
var version =
|
|
546
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
547
|
+
var version = "12.2.6";
|
|
544
548
|
|
|
545
549
|
export { dateTimeInput as default, version };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/date-time-input",
|
|
3
3
|
"description": "The `DateTimeInput` component allows the user to select a date. This component also supports multiple date selection.",
|
|
4
|
-
"version": "12.2.
|
|
4
|
+
"version": "12.2.6",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"homepage": "https://uikit.commercetools.com",
|
|
12
12
|
"keywords": ["javascript", "design system", "react", "uikit"],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"private": false,
|
|
15
14
|
"publishConfig": {
|
|
16
15
|
"access": "public"
|
|
17
16
|
},
|
|
@@ -19,29 +18,26 @@
|
|
|
19
18
|
"main": "dist/commercetools-uikit-date-time-input.cjs.js",
|
|
20
19
|
"module": "dist/commercetools-uikit-date-time-input.esm.js",
|
|
21
20
|
"files": ["dist"],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"prepare": "../../../../scripts/version.js replace"
|
|
24
|
-
},
|
|
25
21
|
"dependencies": {
|
|
26
|
-
"@babel/runtime": "7.
|
|
27
|
-
"@babel/runtime-corejs3": "7.
|
|
28
|
-
"@commercetools-uikit/accessible-button": "12.2.
|
|
29
|
-
"@commercetools-uikit/calendar-time-utils": "12.2.
|
|
30
|
-
"@commercetools-uikit/calendar-utils": "12.2.
|
|
31
|
-
"@commercetools-uikit/constraints": "12.2.
|
|
32
|
-
"@commercetools-uikit/design-system": "12.2.
|
|
33
|
-
"@commercetools-uikit/hooks": "12.2.
|
|
34
|
-
"@commercetools-uikit/icons": "12.2.
|
|
35
|
-
"@commercetools-uikit/secondary-icon-button": "12.2.
|
|
36
|
-
"@commercetools-uikit/select-utils": "12.2.
|
|
37
|
-
"@commercetools-uikit/spacings-inline": "12.2.
|
|
38
|
-
"@commercetools-uikit/text": "12.2.
|
|
39
|
-
"@commercetools-uikit/tooltip": "12.2.
|
|
40
|
-
"@commercetools-uikit/utils": "12.2.
|
|
22
|
+
"@babel/runtime": "7.16.3",
|
|
23
|
+
"@babel/runtime-corejs3": "7.16.3",
|
|
24
|
+
"@commercetools-uikit/accessible-button": "12.2.5",
|
|
25
|
+
"@commercetools-uikit/calendar-time-utils": "12.2.5",
|
|
26
|
+
"@commercetools-uikit/calendar-utils": "12.2.6",
|
|
27
|
+
"@commercetools-uikit/constraints": "12.2.5",
|
|
28
|
+
"@commercetools-uikit/design-system": "12.2.5",
|
|
29
|
+
"@commercetools-uikit/hooks": "12.2.5",
|
|
30
|
+
"@commercetools-uikit/icons": "12.2.6",
|
|
31
|
+
"@commercetools-uikit/secondary-icon-button": "12.2.5",
|
|
32
|
+
"@commercetools-uikit/select-utils": "12.2.6",
|
|
33
|
+
"@commercetools-uikit/spacings-inline": "12.2.5",
|
|
34
|
+
"@commercetools-uikit/text": "12.2.5",
|
|
35
|
+
"@commercetools-uikit/tooltip": "12.2.5",
|
|
36
|
+
"@commercetools-uikit/utils": "12.2.5",
|
|
41
37
|
"@emotion/react": "^11.4.0",
|
|
42
38
|
"@emotion/styled": "^11.3.0",
|
|
43
|
-
"common-tags": "1.8.
|
|
44
|
-
"downshift": "6.1.
|
|
39
|
+
"common-tags": "1.8.2",
|
|
40
|
+
"downshift": "6.1.7",
|
|
45
41
|
"prop-types": "15.7.2",
|
|
46
42
|
"react-is": "17.0.2",
|
|
47
43
|
"react-required-if": "1.0.3",
|
|
@@ -50,7 +46,7 @@
|
|
|
50
46
|
"devDependencies": {
|
|
51
47
|
"moment": "2.29.1",
|
|
52
48
|
"react": "17.0.2",
|
|
53
|
-
"react-intl": "5.
|
|
49
|
+
"react-intl": "5.21.2"
|
|
54
50
|
},
|
|
55
51
|
"peerDependencies": {
|
|
56
52
|
"moment": "2.x",
|