@commercetools-uikit/date-time-input 0.0.0-canary-2021830134526
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.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/dist/commercetools-uikit-date-time-input.cjs.dev.js +573 -0
- package/dist/commercetools-uikit-date-time-input.cjs.js +7 -0
- package/dist/commercetools-uikit-date-time-input.cjs.prod.js +493 -0
- package/dist/commercetools-uikit-date-time-input.esm.js +549 -0
- package/package.json +67 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
16
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
17
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
18
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
19
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
20
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
21
|
+
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
22
|
+
var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
|
|
23
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
24
|
+
var react$1 = require('react');
|
|
25
|
+
require('prop-types');
|
|
26
|
+
var Downshift = require('downshift');
|
|
27
|
+
var reactIntl = require('react-intl');
|
|
28
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
29
|
+
var utils = require('@commercetools-uikit/utils');
|
|
30
|
+
var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
|
|
31
|
+
var calendarUtils = require('@commercetools-uikit/calendar-utils');
|
|
32
|
+
var react = require('@emotion/react');
|
|
33
|
+
var designSystem = require('@commercetools-uikit/design-system');
|
|
34
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
35
|
+
|
|
36
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
|
+
|
|
38
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
48
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
49
|
+
var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
|
|
50
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
51
|
+
var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
|
|
52
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
53
|
+
|
|
54
|
+
var getInputStyles = function getInputStyles() {
|
|
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, ";}" + ("" ), "" );
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
|
|
59
|
+
return jsxRuntime.jsx("input", {
|
|
60
|
+
disabled: props.isDisabled,
|
|
61
|
+
ref: props.timeInputRef,
|
|
62
|
+
type: "text",
|
|
63
|
+
value: props.value,
|
|
64
|
+
onChange: props.onChange,
|
|
65
|
+
onKeyDown: props.onKeyDown,
|
|
66
|
+
placeholder: props.placeholder,
|
|
67
|
+
css: getInputStyles()
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
DateCalendarTimeInput.displayName = 'DateCalendarTimeInput';
|
|
72
|
+
DateCalendarTimeInput.propTypes = {};
|
|
73
|
+
var TimeInput = DateCalendarTimeInput;
|
|
74
|
+
|
|
75
|
+
var messages = reactIntl.defineMessages({
|
|
76
|
+
placeholder: {
|
|
77
|
+
id: 'UIKit.DateTimeInput.placeholder',
|
|
78
|
+
description: 'Placeholder for date time input',
|
|
79
|
+
defaultMessage: 'MM/DD/YYYY - HH:mm AM/PM'
|
|
80
|
+
},
|
|
81
|
+
timePlaceholder: {
|
|
82
|
+
id: 'UIKit.DateTimeInput.timePlaceholder',
|
|
83
|
+
description: 'Placeholder for time input at bottom of date-time-input',
|
|
84
|
+
defaultMessage: 'HH:mm AM/PM'
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
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; }
|
|
89
|
+
|
|
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; }
|
|
91
|
+
|
|
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); }; }
|
|
93
|
+
|
|
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];
|
|
96
|
+
|
|
97
|
+
var preventDownshiftDefault = function preventDownshiftDefault(event) {
|
|
98
|
+
// eslint-disable-next-line no-param-reassign
|
|
99
|
+
event.nativeEvent.preventDownshiftDefault = true;
|
|
100
|
+
}; // This keeps the menu open when the user focuses the time input (thereby
|
|
101
|
+
// blurring the regular input/toggle button)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
var createBlurHandler = function createBlurHandler(timeInputRef) {
|
|
105
|
+
return function (event) {
|
|
106
|
+
event.persist();
|
|
107
|
+
|
|
108
|
+
if (event.relatedTarget === timeInputRef.current) {
|
|
109
|
+
preventDownshiftDefault(event);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var DateTimeInput = /*#__PURE__*/function (_Component) {
|
|
115
|
+
_inherits(DateTimeInput, _Component);
|
|
116
|
+
|
|
117
|
+
var _super = _createSuper(DateTimeInput);
|
|
118
|
+
|
|
119
|
+
function DateTimeInput() {
|
|
120
|
+
var _context;
|
|
121
|
+
|
|
122
|
+
var _this;
|
|
123
|
+
|
|
124
|
+
_classCallCheck(this, DateTimeInput);
|
|
125
|
+
|
|
126
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
127
|
+
args[_key] = arguments[_key];
|
|
128
|
+
}
|
|
129
|
+
|
|
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();
|
|
133
|
+
_this.state = {
|
|
134
|
+
calendarDate: calendarTimeUtils.getToday(_this.props.timeZone),
|
|
135
|
+
suggestedItems: [],
|
|
136
|
+
highlightedIndex: _this.props.value === '' ? null : calendarTimeUtils.getDateInMonth(_this.props.value, _this.props.timeZone) - 1,
|
|
137
|
+
timeString: ''
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
_this.jumpMonths = function (amount) {
|
|
141
|
+
var dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
142
|
+
|
|
143
|
+
_this.setState(function (prevState) {
|
|
144
|
+
var nextDate = calendarTimeUtils.changeMonth(prevState.calendarDate, _this.props.timeZone, amount);
|
|
145
|
+
return {
|
|
146
|
+
calendarDate: nextDate,
|
|
147
|
+
highlightedIndex: dayToHighlight
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
_this.showToday = function () {
|
|
153
|
+
var today = calendarTimeUtils.getToday(_this.props.timeZone);
|
|
154
|
+
|
|
155
|
+
_this.setState(function (prevState) {
|
|
156
|
+
return {
|
|
157
|
+
calendarDate: today,
|
|
158
|
+
highlightedIndex: prevState.suggestedItems.length + calendarTimeUtils.getDateInMonth(today, _this.props.timeZone) - 1
|
|
159
|
+
};
|
|
160
|
+
}, function () {
|
|
161
|
+
return _this.inputRef.current.focus();
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
_this.handleBlur = function () {
|
|
166
|
+
if (_this.props.onBlur) _this.props.onBlur({
|
|
167
|
+
target: {
|
|
168
|
+
id: _this.props.id,
|
|
169
|
+
name: _this.props.name
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
_this.handleTimeChange = function (event) {
|
|
175
|
+
var parsedTime = utils.parseTime(event.target.value);
|
|
176
|
+
|
|
177
|
+
_this.setState({
|
|
178
|
+
timeString: event.target.value
|
|
179
|
+
}); // We can't update the parent when there is no value
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if (_this.props.value === '') return;
|
|
183
|
+
var date = calendarTimeUtils.getStartOf(_this.props.value, _this.props.timeZone);
|
|
184
|
+
|
|
185
|
+
if (parsedTime) {
|
|
186
|
+
date = calendarTimeUtils.changeTime(date, _this.props.timeZone, parsedTime);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
_this.emit(date);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
_this.emit = function (value) {
|
|
193
|
+
return _this.props.onChange({
|
|
194
|
+
target: {
|
|
195
|
+
id: _this.props.id,
|
|
196
|
+
name: _this.props.name,
|
|
197
|
+
// when cleared the value is null, but we always want it to be an
|
|
198
|
+
// empty string when there is no value.
|
|
199
|
+
value: value || ''
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return _this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
_createClass(DateTimeInput, [{
|
|
208
|
+
key: "render",
|
|
209
|
+
value: function render() {
|
|
210
|
+
var _context2,
|
|
211
|
+
_this2 = this;
|
|
212
|
+
|
|
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
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
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
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
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
|
+
}
|
|
253
|
+
|
|
254
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
255
|
+
return {
|
|
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
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
267
|
+
return {
|
|
268
|
+
highlightedIndex: changes.highlightedIndex
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return null;
|
|
273
|
+
}, function () {
|
|
274
|
+
if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
|
|
275
|
+
_this2.timeInputRef.current.focus();
|
|
276
|
+
|
|
277
|
+
_this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
/* eslint-enable no-prototype-builtins */
|
|
281
|
+
|
|
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
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}, _concatInstanceProperty__default['default'](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}]);
|
|
481
|
+
|
|
482
|
+
return DateTimeInput;
|
|
483
|
+
}(react$1.Component);
|
|
484
|
+
|
|
485
|
+
DateTimeInput.displayName = 'DateTimeInput';
|
|
486
|
+
DateTimeInput.propTypes = {};
|
|
487
|
+
var dateTimeInput = reactIntl.injectIntl(DateTimeInput);
|
|
488
|
+
|
|
489
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
490
|
+
var version = '0.0.0-canary-2021830134526';
|
|
491
|
+
|
|
492
|
+
exports['default'] = dateTimeInput;
|
|
493
|
+
exports.version = version;
|