@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,549 @@
|
|
|
1
|
+
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
2
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
3
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
4
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
5
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
6
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
7
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
8
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
9
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
10
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
11
|
+
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
12
|
+
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
13
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
14
|
+
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
15
|
+
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
16
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
17
|
+
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
18
|
+
import _fillInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/fill';
|
|
19
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
20
|
+
import { createRef, Component } from 'react';
|
|
21
|
+
import PropTypes from 'prop-types';
|
|
22
|
+
import Downshift from 'downshift';
|
|
23
|
+
import { defineMessages, injectIntl } from 'react-intl';
|
|
24
|
+
import Constraints from '@commercetools-uikit/constraints';
|
|
25
|
+
import { parseTime, filterDataAttributes } from '@commercetools-uikit/utils';
|
|
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';
|
|
27
|
+
import { CalendarBody, CalendarMenu, CalendarHeader, CalendarContent, CalendarDay } from '@commercetools-uikit/calendar-utils';
|
|
28
|
+
import { css } from '@emotion/react';
|
|
29
|
+
import { customProperties } from '@commercetools-uikit/design-system';
|
|
30
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
31
|
+
|
|
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;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWUtaW5wdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSWdDIiwiZmlsZSI6InRpbWUtaW5wdXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuaW1wb3J0IHsgY3VzdG9tUHJvcGVydGllcyBhcyB2YXJzIH0gZnJvbSAnQGNvbW1lcmNldG9vbHMtdWlraXQvZGVzaWduLXN5c3RlbSc7XG5cbmNvbnN0IGdldElucHV0U3R5bGVzID0gKCkgPT4gY3NzYFxuICB3aWR0aDogMTAwJTtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBib3JkZXI6IDA7XG4gIGJvcmRlci10b3A6IDFweCBzb2xpZCAke3ZhcnMuY29sb3JOZXV0cmFsOTB9O1xuICBwYWRkaW5nOiAxMHB4IDA7XG4gIG91dGxpbmU6IDA7XG4gIGZvbnQtc2l6ZTogJHt2YXJzLmZvbnRTaXplRGVmYXVsdH07XG4gIG1hcmdpbi10b3A6ICR7dmFycy5zcGFjaW5nU307XG4gIGNvbG9yOiAke3ZhcnMuY29sb3JTb2xpZH07XG5cbiAgOmRpc2FibGVkIHtcbiAgICAvKiBGaXhlcyBiYWNrZ3JvdW5kIGNvbG9yIGluIEZpcmVmb3ggKi9cbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAke3ZhcnMuY29sb3JTdXJmYWNlfTtcbiAgfVxuYDtcbmNvbnN0IERhdGVDYWxlbmRhclRpbWVJbnB1dCA9IChwcm9wcykgPT4gKFxuICA8aW5wdXRcbiAgICBkaXNhYmxlZD17cHJvcHMuaXNEaXNhYmxlZH1cbiAgICByZWY9e3Byb3BzLnRpbWVJbnB1dFJlZn1cbiAgICB0eXBlPVwidGV4dFwiXG4gICAgdmFsdWU9e3Byb3BzLnZhbHVlfVxuICAgIG9uQ2hhbmdlPXtwcm9wcy5vbkNoYW5nZX1cbiAgICBvbktleURvd249e3Byb3BzLm9uS2V5RG93bn1cbiAgICBwbGFjZWhvbGRlcj17cHJvcHMucGxhY2Vob2xkZXJ9XG4gICAgY3NzPXtnZXRJbnB1dFN0eWxlcygpfVxuICAvPlxuKTtcblxuRGF0ZUNhbGVuZGFyVGltZUlucHV0LmRpc3BsYXlOYW1lID0gJ0RhdGVDYWxlbmRhclRpbWVJbnB1dCc7XG5cbkRhdGVDYWxlbmRhclRpbWVJbnB1dC5wcm9wVHlwZXMgPSB7XG4gIGlzRGlzYWJsZWQ6IFByb3BUeXBlcy5ib29sLmlzUmVxdWlyZWQsXG4gIHRpbWVJbnB1dFJlZjogUHJvcFR5cGVzLm9iamVjdC5pc1JlcXVpcmVkLFxuICBvbktleURvd246IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIG9uQ2hhbmdlOiBQcm9wVHlwZXMuZnVuYy5pc1JlcXVpcmVkLFxuICB2YWx1ZTogUHJvcFR5cGVzLnN0cmluZy5pc1JlcXVpcmVkLFxuICBwbGFjZWhvbGRlcjogUHJvcFR5cGVzLnN0cmluZyxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IERhdGVDYWxlbmRhclRpbWVJbnB1dDtcbiJdfQ== */");
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
|
|
37
|
+
return jsx("input", {
|
|
38
|
+
disabled: props.isDisabled,
|
|
39
|
+
ref: props.timeInputRef,
|
|
40
|
+
type: "text",
|
|
41
|
+
value: props.value,
|
|
42
|
+
onChange: props.onChange,
|
|
43
|
+
onKeyDown: props.onKeyDown,
|
|
44
|
+
placeholder: props.placeholder,
|
|
45
|
+
css: getInputStyles()
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
DateCalendarTimeInput.displayName = 'DateCalendarTimeInput';
|
|
50
|
+
DateCalendarTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
51
|
+
isDisabled: PropTypes.bool.isRequired,
|
|
52
|
+
timeInputRef: PropTypes.object.isRequired,
|
|
53
|
+
onKeyDown: PropTypes.func.isRequired,
|
|
54
|
+
onChange: PropTypes.func.isRequired,
|
|
55
|
+
value: PropTypes.string.isRequired,
|
|
56
|
+
placeholder: PropTypes.string
|
|
57
|
+
} : {};
|
|
58
|
+
var TimeInput = DateCalendarTimeInput;
|
|
59
|
+
|
|
60
|
+
var messages = defineMessages({
|
|
61
|
+
placeholder: {
|
|
62
|
+
id: 'UIKit.DateTimeInput.placeholder',
|
|
63
|
+
description: 'Placeholder for date time input',
|
|
64
|
+
defaultMessage: 'MM/DD/YYYY - HH:mm AM/PM'
|
|
65
|
+
},
|
|
66
|
+
timePlaceholder: {
|
|
67
|
+
id: 'UIKit.DateTimeInput.timePlaceholder',
|
|
68
|
+
description: 'Placeholder for time input at bottom of date-time-input',
|
|
69
|
+
defaultMessage: 'HH:mm AM/PM'
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
74
|
+
|
|
75
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
76
|
+
|
|
77
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
78
|
+
|
|
79
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
80
|
+
var activationTypes = [Downshift.stateChangeTypes.keyDownEnter, Downshift.stateChangeTypes.clickItem];
|
|
81
|
+
|
|
82
|
+
var preventDownshiftDefault = function preventDownshiftDefault(event) {
|
|
83
|
+
// eslint-disable-next-line no-param-reassign
|
|
84
|
+
event.nativeEvent.preventDownshiftDefault = true;
|
|
85
|
+
}; // This keeps the menu open when the user focuses the time input (thereby
|
|
86
|
+
// blurring the regular input/toggle button)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
var createBlurHandler = function createBlurHandler(timeInputRef) {
|
|
90
|
+
return function (event) {
|
|
91
|
+
event.persist();
|
|
92
|
+
|
|
93
|
+
if (event.relatedTarget === timeInputRef.current) {
|
|
94
|
+
preventDownshiftDefault(event);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
var DateTimeInput = /*#__PURE__*/function (_Component) {
|
|
100
|
+
_inherits(DateTimeInput, _Component);
|
|
101
|
+
|
|
102
|
+
var _super = _createSuper(DateTimeInput);
|
|
103
|
+
|
|
104
|
+
function DateTimeInput() {
|
|
105
|
+
var _context;
|
|
106
|
+
|
|
107
|
+
var _this;
|
|
108
|
+
|
|
109
|
+
_classCallCheck(this, DateTimeInput);
|
|
110
|
+
|
|
111
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
112
|
+
args[_key] = arguments[_key];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_this = _super.call.apply(_super, _concatInstanceProperty(_context = [this]).call(_context, args));
|
|
116
|
+
_this.inputRef = /*#__PURE__*/createRef();
|
|
117
|
+
_this.timeInputRef = /*#__PURE__*/createRef();
|
|
118
|
+
_this.state = {
|
|
119
|
+
calendarDate: getToday(_this.props.timeZone),
|
|
120
|
+
suggestedItems: [],
|
|
121
|
+
highlightedIndex: _this.props.value === '' ? null : getDateInMonth(_this.props.value, _this.props.timeZone) - 1,
|
|
122
|
+
timeString: ''
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
_this.jumpMonths = function (amount) {
|
|
126
|
+
var dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
127
|
+
|
|
128
|
+
_this.setState(function (prevState) {
|
|
129
|
+
var nextDate = changeMonth(prevState.calendarDate, _this.props.timeZone, amount);
|
|
130
|
+
return {
|
|
131
|
+
calendarDate: nextDate,
|
|
132
|
+
highlightedIndex: dayToHighlight
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
_this.showToday = function () {
|
|
138
|
+
var today = getToday(_this.props.timeZone);
|
|
139
|
+
|
|
140
|
+
_this.setState(function (prevState) {
|
|
141
|
+
return {
|
|
142
|
+
calendarDate: today,
|
|
143
|
+
highlightedIndex: prevState.suggestedItems.length + getDateInMonth(today, _this.props.timeZone) - 1
|
|
144
|
+
};
|
|
145
|
+
}, function () {
|
|
146
|
+
return _this.inputRef.current.focus();
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
_this.handleBlur = function () {
|
|
151
|
+
if (_this.props.onBlur) _this.props.onBlur({
|
|
152
|
+
target: {
|
|
153
|
+
id: _this.props.id,
|
|
154
|
+
name: _this.props.name
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
_this.handleTimeChange = function (event) {
|
|
160
|
+
var parsedTime = parseTime(event.target.value);
|
|
161
|
+
|
|
162
|
+
_this.setState({
|
|
163
|
+
timeString: event.target.value
|
|
164
|
+
}); // We can't update the parent when there is no value
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if (_this.props.value === '') return;
|
|
168
|
+
var date = getStartOf(_this.props.value, _this.props.timeZone);
|
|
169
|
+
|
|
170
|
+
if (parsedTime) {
|
|
171
|
+
date = changeTime(date, _this.props.timeZone, parsedTime);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
_this.emit(date);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
_this.emit = function (value) {
|
|
178
|
+
return _this.props.onChange({
|
|
179
|
+
target: {
|
|
180
|
+
id: _this.props.id,
|
|
181
|
+
name: _this.props.name,
|
|
182
|
+
// when cleared the value is null, but we always want it to be an
|
|
183
|
+
// empty string when there is no value.
|
|
184
|
+
value: value || ''
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return _this;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_createClass(DateTimeInput, [{
|
|
193
|
+
key: "render",
|
|
194
|
+
value: function render() {
|
|
195
|
+
var _context2,
|
|
196
|
+
_this2 = this;
|
|
197
|
+
|
|
198
|
+
return jsx(Constraints.Horizontal, {
|
|
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) {
|
|
212
|
+
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
213
|
+
return _objectSpread(_objectSpread({}, changes), {}, {
|
|
214
|
+
isOpen: true
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
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
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
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
|
+
}
|
|
238
|
+
|
|
239
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
240
|
+
return {
|
|
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
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
252
|
+
return {
|
|
253
|
+
highlightedIndex: changes.highlightedIndex
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return null;
|
|
258
|
+
}, function () {
|
|
259
|
+
if (_includesInstanceProperty(activationTypes).call(activationTypes, changes.type)) {
|
|
260
|
+
_this2.timeInputRef.current.focus();
|
|
261
|
+
|
|
262
|
+
_this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
/* eslint-enable no-prototype-builtins */
|
|
266
|
+
|
|
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
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}, _concatInstanceProperty(_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}]);
|
|
466
|
+
|
|
467
|
+
return DateTimeInput;
|
|
468
|
+
}(Component);
|
|
469
|
+
|
|
470
|
+
DateTimeInput.displayName = 'DateTimeInput';
|
|
471
|
+
DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
472
|
+
intl: PropTypes.shape({
|
|
473
|
+
locale: PropTypes.string.isRequired,
|
|
474
|
+
formatMessage: PropTypes.func.isRequired
|
|
475
|
+
}).isRequired,
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Horizontal size limit of the input field.
|
|
479
|
+
*/
|
|
480
|
+
horizontalConstraint: PropTypes.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* The selected date, must either be an empty string or a date formatted in ISO 8601 (e.g. "2018-10-04T09:00:00.000Z").
|
|
484
|
+
*/
|
|
485
|
+
value: PropTypes.string.isRequired,
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Called when the date changes. Called with an event containing an empty string (no value) or a string in this format: "YYYY-MM-DD".
|
|
489
|
+
* <br />
|
|
490
|
+
* Signature: `(event) => void`
|
|
491
|
+
*/
|
|
492
|
+
onChange: PropTypes.func.isRequired,
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Called when the date input gains focus.
|
|
496
|
+
*/
|
|
497
|
+
onFocus: PropTypes.func,
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Called when the date input loses focus.
|
|
501
|
+
*/
|
|
502
|
+
onBlur: PropTypes.func,
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Specifies the time zone in which the calendar and selected values are shown. It also influences how entered dates and times are parsed.
|
|
506
|
+
*/
|
|
507
|
+
timeZone: PropTypes.string.isRequired,
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Used as the HTML `id` attribute.
|
|
511
|
+
*/
|
|
512
|
+
id: PropTypes.string,
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Used as the HTML `name` attribute.
|
|
516
|
+
*/
|
|
517
|
+
name: PropTypes.string,
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Placeholder value to show in the input field
|
|
521
|
+
*/
|
|
522
|
+
placeholder: PropTypes.string,
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Disables the date picker
|
|
526
|
+
*/
|
|
527
|
+
isDisabled: PropTypes.bool,
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Disables the date picker menu and sets the input field as read-only
|
|
531
|
+
*/
|
|
532
|
+
isReadOnly: PropTypes.bool,
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Indicates the input field has an error
|
|
536
|
+
*/
|
|
537
|
+
hasError: PropTypes.bool,
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Indicates the input field has a warning
|
|
541
|
+
*/
|
|
542
|
+
hasWarning: PropTypes.bool
|
|
543
|
+
} : {};
|
|
544
|
+
var dateTimeInput = injectIntl(DateTimeInput);
|
|
545
|
+
|
|
546
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
547
|
+
var version = '0.0.0-canary-2021830134526';
|
|
548
|
+
|
|
549
|
+
export { dateTimeInput as default, version };
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-uikit/date-time-input",
|
|
3
|
+
"description": "The `DateTimeInput` component allows the user to select a date. This component also supports multiple date selection.",
|
|
4
|
+
"version": "0.0.0-canary-2021830134526",
|
|
5
|
+
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/commercetools/ui-kit.git",
|
|
9
|
+
"directory": "packages/components/inputs/date-time-input"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://uikit.commercetools.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"javascript",
|
|
14
|
+
"design system",
|
|
15
|
+
"react",
|
|
16
|
+
"uikit"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"private": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "dist/commercetools-uikit-date-time-input.cjs.js",
|
|
25
|
+
"module": "dist/commercetools-uikit-date-time-input.esm.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"prepare": "../../../../scripts/version.js replace"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@babel/runtime": "7.14.8",
|
|
34
|
+
"@babel/runtime-corejs3": "7.14.9",
|
|
35
|
+
"@commercetools-uikit/accessible-button": "0.0.0-canary-2021830134526",
|
|
36
|
+
"@commercetools-uikit/calendar-time-utils": "0.0.0-canary-2021830134526",
|
|
37
|
+
"@commercetools-uikit/calendar-utils": "0.0.0-canary-2021830134526",
|
|
38
|
+
"@commercetools-uikit/constraints": "0.0.0-canary-2021830134526",
|
|
39
|
+
"@commercetools-uikit/design-system": "0.0.0-canary-2021830134526",
|
|
40
|
+
"@commercetools-uikit/hooks": "0.0.0-canary-2021830134526",
|
|
41
|
+
"@commercetools-uikit/icons": "0.0.0-canary-2021830134526",
|
|
42
|
+
"@commercetools-uikit/secondary-icon-button": "0.0.0-canary-2021830134526",
|
|
43
|
+
"@commercetools-uikit/select-utils": "0.0.0-canary-2021830134526",
|
|
44
|
+
"@commercetools-uikit/spacings-inline": "0.0.0-canary-2021830134526",
|
|
45
|
+
"@commercetools-uikit/text": "0.0.0-canary-2021830134526",
|
|
46
|
+
"@commercetools-uikit/tooltip": "0.0.0-canary-2021830134526",
|
|
47
|
+
"@commercetools-uikit/utils": "12.2.0",
|
|
48
|
+
"@emotion/react": "^11.4.0",
|
|
49
|
+
"@emotion/styled": "^11.3.0",
|
|
50
|
+
"common-tags": "1.8.0",
|
|
51
|
+
"downshift": "6.1.7",
|
|
52
|
+
"prop-types": "15.7.2",
|
|
53
|
+
"react-is": "17.0.2",
|
|
54
|
+
"react-required-if": "1.0.3",
|
|
55
|
+
"warning": "4.0.3"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"moment": "2.29.1",
|
|
59
|
+
"react": "17.0.2",
|
|
60
|
+
"react-intl": "5.20.7"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"moment": "2.x",
|
|
64
|
+
"react": "17.x",
|
|
65
|
+
"react-intl": "5.x"
|
|
66
|
+
}
|
|
67
|
+
}
|