@commercetools-uikit/date-range-input 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339
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 +100 -0
- package/dist/commercetools-uikit-date-range-input.cjs.d.ts +3 -0
- package/dist/commercetools-uikit-date-range-input.cjs.dev.js +459 -0
- package/dist/commercetools-uikit-date-range-input.cjs.js +7 -0
- package/dist/commercetools-uikit-date-range-input.cjs.prod.js +441 -0
- package/dist/commercetools-uikit-date-range-input.esm.js +435 -0
- package/dist/declarations/src/date-range-input.d.ts +79 -0
- package/dist/declarations/src/export-types.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +62 -0
|
@@ -0,0 +1,435 @@
|
|
|
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 _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
5
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
6
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
7
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
8
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
9
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
10
|
+
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
11
|
+
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
12
|
+
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
13
|
+
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
14
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
15
|
+
import _pt from 'prop-types';
|
|
16
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
17
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
18
|
+
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
19
|
+
import _sortInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/sort';
|
|
20
|
+
import _fillInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/fill';
|
|
21
|
+
import { Component, createRef } from 'react';
|
|
22
|
+
import Downshift from 'downshift';
|
|
23
|
+
import { injectIntl } from 'react-intl';
|
|
24
|
+
import Constraints from '@commercetools-uikit/constraints';
|
|
25
|
+
import { filterDataAttributes } from '@commercetools-uikit/utils';
|
|
26
|
+
import { createItemRangeToString, getDateInMonth, formatRange, getToday, createCalendarItems, getPaddingDayCount, getWeekdayNames, CalendarBody, getPreviousDay, getDaysInMonth, CalendarMenu, CalendarHeader, getMonthCalendarLabel, getYearCalendarLabel, CalendarContent, CalendarDay, isSameDay, getCalendarDayLabel, parseInputToDate, isBetween, changeMonth } from '@commercetools-uikit/calendar-utils';
|
|
27
|
+
import { getLocalizedDateTimeFormatPattern } from '@commercetools-uikit/calendar-time-utils';
|
|
28
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
29
|
+
|
|
30
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
31
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
33
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
34
|
+
const preventDownshiftDefault = event => {
|
|
35
|
+
event.nativeEvent.preventDownshiftDefault = true;
|
|
36
|
+
};
|
|
37
|
+
const parseRangeText = (text, locale) => {
|
|
38
|
+
var _context, _context2;
|
|
39
|
+
const parts = _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = text.split(' - ')).call(_context2, part => {
|
|
40
|
+
const parsedDate = parseInputToDate(_trimInstanceProperty(part).call(part), locale);
|
|
41
|
+
return parsedDate === '' ? null : parsedDate;
|
|
42
|
+
})).call(_context, Boolean);
|
|
43
|
+
return parts;
|
|
44
|
+
};
|
|
45
|
+
const isSameRange = (a, b) => {
|
|
46
|
+
if (a.length !== b.length) return false;
|
|
47
|
+
if (a.length === 0) return true;
|
|
48
|
+
if (a[0] === b[0] && a[1] === b[1]) return true;
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
const getRange = _ref => {
|
|
52
|
+
let item = _ref.item,
|
|
53
|
+
value = _ref.value,
|
|
54
|
+
startDate = _ref.startDate,
|
|
55
|
+
highlightedItem = _ref.highlightedItem;
|
|
56
|
+
const isRangeSelectionInProgress = startDate;
|
|
57
|
+
const hasSelection = value.length === 2;
|
|
58
|
+
const isStartDate = isSameDay(item, startDate);
|
|
59
|
+
const isBetween$1 = highlightedItem && isBetween(item, startDate, highlightedItem);
|
|
60
|
+
let isRangeStart = false;
|
|
61
|
+
if (isRangeSelectionInProgress) {
|
|
62
|
+
isRangeStart = isStartDate;
|
|
63
|
+
} else if (hasSelection) {
|
|
64
|
+
isRangeStart = value[0] === item;
|
|
65
|
+
}
|
|
66
|
+
let isRangeBetween = false;
|
|
67
|
+
if (isRangeSelectionInProgress) {
|
|
68
|
+
isRangeBetween = isBetween$1;
|
|
69
|
+
} else if (hasSelection) {
|
|
70
|
+
isRangeBetween = isBetween(item, value[0], value[1]);
|
|
71
|
+
}
|
|
72
|
+
let isRangeEnd = false;
|
|
73
|
+
if (isRangeSelectionInProgress) {
|
|
74
|
+
isRangeEnd = item === highlightedItem;
|
|
75
|
+
} else if (hasSelection) {
|
|
76
|
+
isRangeEnd = value[1] === item;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
isRangeStart,
|
|
80
|
+
isRangeBetween,
|
|
81
|
+
isRangeEnd
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
let DateRangeInput = /*#__PURE__*/function (_Component) {
|
|
85
|
+
function DateRangeInput() {
|
|
86
|
+
var _this;
|
|
87
|
+
_classCallCheck(this, DateRangeInput);
|
|
88
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
89
|
+
args[_key] = arguments[_key];
|
|
90
|
+
}
|
|
91
|
+
_this = _callSuper(this, DateRangeInput, [...args]);
|
|
92
|
+
_this.inputRef = /*#__PURE__*/createRef();
|
|
93
|
+
_this.state = {
|
|
94
|
+
calendarDate: _this.props.value.length === 2 ? _this.props.value[0] : getToday(),
|
|
95
|
+
suggestedItems: [],
|
|
96
|
+
startDate: null,
|
|
97
|
+
highlightedIndex: null,
|
|
98
|
+
isOpen: false,
|
|
99
|
+
inputValue: formatRange(_this.props.value, _this.props.intl.locale),
|
|
100
|
+
prevValue: _this.props.value,
|
|
101
|
+
prevLocale: _this.props.intl.locale
|
|
102
|
+
};
|
|
103
|
+
_this.jumpMonth = function (amount) {
|
|
104
|
+
let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
105
|
+
_this.setState(prevState => {
|
|
106
|
+
const nextDate = changeMonth(prevState.calendarDate, amount);
|
|
107
|
+
return {
|
|
108
|
+
calendarDate: nextDate,
|
|
109
|
+
highlightedIndex: dayToHighlight
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
_this.showToday = () => {
|
|
114
|
+
const today = getToday();
|
|
115
|
+
_this.setState(prevState => ({
|
|
116
|
+
calendarDate: today,
|
|
117
|
+
highlightedIndex: prevState.suggestedItems.length + getDateInMonth(today) - 1
|
|
118
|
+
}), () => _this.inputRef.current?.focus());
|
|
119
|
+
};
|
|
120
|
+
_this.handleBlur = () => {
|
|
121
|
+
if (_this.props.onBlur) _this.props.onBlur({
|
|
122
|
+
target: {
|
|
123
|
+
id: _this.props.id,
|
|
124
|
+
name: _this.props.name
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
_this.emit = unsortedRange => {
|
|
129
|
+
_this.props.onChange?.({
|
|
130
|
+
target: {
|
|
131
|
+
id: _this.props.id,
|
|
132
|
+
name: _this.props.name,
|
|
133
|
+
value: _sortInstanceProperty(unsortedRange).call(unsortedRange)
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
return _this;
|
|
138
|
+
}
|
|
139
|
+
_inherits(DateRangeInput, _Component);
|
|
140
|
+
return _createClass(DateRangeInput, [{
|
|
141
|
+
key: "render",
|
|
142
|
+
value: function render() {
|
|
143
|
+
return jsx(Constraints.Horizontal, {
|
|
144
|
+
max: this.props.horizontalConstraint,
|
|
145
|
+
children: jsx(Downshift, {
|
|
146
|
+
inputId: this.props.id,
|
|
147
|
+
itemToString: createItemRangeToString(this.props.intl.locale),
|
|
148
|
+
inputValue: this.state.inputValue,
|
|
149
|
+
selectedItem: null,
|
|
150
|
+
highlightedIndex: this.state.highlightedIndex,
|
|
151
|
+
onInputValueChange: (inputValue, changes) => {
|
|
152
|
+
// only attempt to parse input when the user typed into the input
|
|
153
|
+
// field
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
if (changes.type !== Downshift.stateChangeTypes.changeInput) return;
|
|
156
|
+
this.setState(() => {
|
|
157
|
+
const parsedRange = parseRangeText(inputValue, this.props.intl.locale);
|
|
158
|
+
if (parsedRange.length === 0) return {
|
|
159
|
+
suggestedItems: [],
|
|
160
|
+
highlightedIndex: null,
|
|
161
|
+
inputValue,
|
|
162
|
+
startDate: null
|
|
163
|
+
};
|
|
164
|
+
if (parsedRange.length === 1) {
|
|
165
|
+
const calendarDate = parsedRange[0];
|
|
166
|
+
return {
|
|
167
|
+
suggestedItems: [],
|
|
168
|
+
highlightedIndex: getDateInMonth(calendarDate) - 1,
|
|
169
|
+
inputValue,
|
|
170
|
+
startDate: parsedRange[0],
|
|
171
|
+
calendarDate
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (parsedRange.length === 2) {
|
|
175
|
+
const calendarDate = parsedRange[1];
|
|
176
|
+
return {
|
|
177
|
+
suggestedItems: [],
|
|
178
|
+
highlightedIndex: getDateInMonth(calendarDate) - 1,
|
|
179
|
+
inputValue,
|
|
180
|
+
startDate: parsedRange[0],
|
|
181
|
+
calendarDate
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
onStateChange: changes => {
|
|
188
|
+
this.setState(prevState => {
|
|
189
|
+
if (changes.type === Downshift.stateChangeTypes.mouseUp || changes.type === Downshift.stateChangeTypes.blurInput) {
|
|
190
|
+
return {
|
|
191
|
+
highlightedIndex: null,
|
|
192
|
+
isOpen: false,
|
|
193
|
+
inputValue: formatRange(this.props.value, this.props.intl.locale)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (changes.hasOwnProperty('selectedItem')) {
|
|
197
|
+
const hasStartedRangeSelection = Boolean(!prevState.startDate && changes.selectedItem);
|
|
198
|
+
const hasFinishedRangeSelection = Boolean(prevState.startDate && changes.selectedItem);
|
|
199
|
+
return {
|
|
200
|
+
highlightedIndex: prevState.highlightedIndex,
|
|
201
|
+
startDate: prevState.startDate ? null : changes.selectedItem,
|
|
202
|
+
calendarDate: changes.selectedItem,
|
|
203
|
+
isOpen: !hasFinishedRangeSelection,
|
|
204
|
+
inputValue: (() => {
|
|
205
|
+
if (hasFinishedRangeSelection) {
|
|
206
|
+
return formatRange([prevState.startDate, changes.selectedItem], this.props.intl.locale);
|
|
207
|
+
}
|
|
208
|
+
if (hasStartedRangeSelection) {
|
|
209
|
+
return formatRange([changes.selectedItem], this.props.intl.locale);
|
|
210
|
+
}
|
|
211
|
+
return '';
|
|
212
|
+
})()
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
216
|
+
return {
|
|
217
|
+
isOpen: changes.isOpen,
|
|
218
|
+
highlightedIndex: changes.highlightedIndex || null,
|
|
219
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
220
|
+
// Reset range selection progress when menu opens/closes
|
|
221
|
+
startDate: null,
|
|
222
|
+
// Ensure calendar opens on selected date.
|
|
223
|
+
// Open on the current day as a fallback.
|
|
224
|
+
calendarDate: this.props.value.length === 2 ? this.props.value[0] : getToday()
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
228
|
+
return {
|
|
229
|
+
highlightedIndex: changes.highlightedIndex
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
onChange: selectedItem => {
|
|
236
|
+
if (this.state.startDate && selectedItem) {
|
|
237
|
+
this.emit([this.state.startDate, selectedItem]);
|
|
238
|
+
} else {
|
|
239
|
+
this.emit([]);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
isOpen: this.state.isOpen,
|
|
243
|
+
children: _ref2 => {
|
|
244
|
+
var _context3;
|
|
245
|
+
let getInputProps = _ref2.getInputProps,
|
|
246
|
+
getMenuProps = _ref2.getMenuProps,
|
|
247
|
+
getItemProps = _ref2.getItemProps,
|
|
248
|
+
getToggleButtonProps = _ref2.getToggleButtonProps,
|
|
249
|
+
clearSelection = _ref2.clearSelection,
|
|
250
|
+
highlightedIndex = _ref2.highlightedIndex,
|
|
251
|
+
openMenu = _ref2.openMenu,
|
|
252
|
+
setHighlightedIndex = _ref2.setHighlightedIndex,
|
|
253
|
+
isOpen = _ref2.isOpen,
|
|
254
|
+
inputValue = _ref2.inputValue;
|
|
255
|
+
const calendarItems = createCalendarItems(this.state.calendarDate);
|
|
256
|
+
const allItems = [...this.state.suggestedItems, ...calendarItems];
|
|
257
|
+
const paddingDayCount = getPaddingDayCount(this.state.calendarDate, this.props.intl.locale);
|
|
258
|
+
const paddingDays = _fillInstanceProperty(_context3 = Array(paddingDayCount)).call(_context3, undefined);
|
|
259
|
+
const weekdays = getWeekdayNames(this.props.intl.locale);
|
|
260
|
+
const today = getToday();
|
|
261
|
+
return jsxs("div", {
|
|
262
|
+
onFocus: this.props.onFocus,
|
|
263
|
+
onBlur: this.handleBlur,
|
|
264
|
+
children: [jsx(CalendarBody, {
|
|
265
|
+
inputRef: this.inputRef,
|
|
266
|
+
inputProps: getInputProps(_objectSpread({
|
|
267
|
+
/* ARIA */
|
|
268
|
+
'aria-invalid': this.props['aria-invalid'],
|
|
269
|
+
'aria-errormessage': this.props['aria-errormessage'],
|
|
270
|
+
// Unset the aria-labelledby as it interfers with the link
|
|
271
|
+
// between the <label for> and the <input id>.
|
|
272
|
+
'aria-labelledby': undefined,
|
|
273
|
+
name: this.props.name,
|
|
274
|
+
placeholder: typeof this.props.placeholder === 'string' ? this.props.placeholder : `${getLocalizedDateTimeFormatPattern(this.props.intl.locale)} - ${getLocalizedDateTimeFormatPattern(this.props.intl.locale)}`,
|
|
275
|
+
onMouseEnter: () => {
|
|
276
|
+
// we remove the highlight so that the user can use the
|
|
277
|
+
// arrow keys to move the cursor when hovering
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
if (isOpen) setHighlightedIndex(null);
|
|
280
|
+
},
|
|
281
|
+
onKeyDown: event => {
|
|
282
|
+
if (this.props.isReadOnly) {
|
|
283
|
+
preventDownshiftDefault(event);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (event.key === 'Enter' && inputValue?.trim() === '' &&
|
|
287
|
+
// do not clear value when user presses Enter to
|
|
288
|
+
// select the end date (so only clear when there is no
|
|
289
|
+
// startDate)
|
|
290
|
+
!this.state.startDate && this.props.isClearable) {
|
|
291
|
+
clearSelection();
|
|
292
|
+
this.emit([]);
|
|
293
|
+
}
|
|
294
|
+
// ArrowDown
|
|
295
|
+
if (event.key === 'ArrowDown') {
|
|
296
|
+
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
297
|
+
// if it's the end of the month
|
|
298
|
+
// then bypass normal arrow navigation
|
|
299
|
+
preventDownshiftDefault(event);
|
|
300
|
+
// then jump to start of next month
|
|
301
|
+
this.jumpMonth(1, 0);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// ArrowUp
|
|
305
|
+
if (event.key === 'ArrowUp') {
|
|
306
|
+
const previousDay = getPreviousDay(calendarItems[highlightedIndex]);
|
|
307
|
+
if (highlightedIndex <= 0) {
|
|
308
|
+
// if it's the start of the month
|
|
309
|
+
// then bypass normal arrow navigation
|
|
310
|
+
preventDownshiftDefault(event);
|
|
311
|
+
const numberOfDaysOfPrevMonth = getDaysInMonth(previousDay);
|
|
312
|
+
// then jump to the last day of the previous month
|
|
313
|
+
this.jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
// we only do this for readOnly because the input
|
|
318
|
+
// doesn't ignore these events, unlike when its disabled
|
|
319
|
+
onClick: this.props.isReadOnly ? undefined : openMenu
|
|
320
|
+
}, filterDataAttributes(this.props))),
|
|
321
|
+
hasSelection: this.props.value.length === 2,
|
|
322
|
+
isClearable: this.props.isClearable,
|
|
323
|
+
onClear: () => {
|
|
324
|
+
this.setState({
|
|
325
|
+
startDate: null
|
|
326
|
+
});
|
|
327
|
+
this.emit([]);
|
|
328
|
+
clearSelection();
|
|
329
|
+
},
|
|
330
|
+
isOpen: isOpen,
|
|
331
|
+
isDisabled: this.props.isDisabled,
|
|
332
|
+
isReadOnly: this.props.isReadOnly,
|
|
333
|
+
isCondensed: this.props.isCondensed,
|
|
334
|
+
toggleButtonProps: getToggleButtonProps(),
|
|
335
|
+
hasError: this.props.hasError,
|
|
336
|
+
hasWarning: this.props.hasWarning
|
|
337
|
+
}), isOpen && !this.props.isDisabled && jsxs(CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
|
|
338
|
+
hasError: this.props.hasError,
|
|
339
|
+
hasWarning: this.props.hasWarning,
|
|
340
|
+
children: [jsx(CalendarHeader, {
|
|
341
|
+
monthLabel: getMonthCalendarLabel(this.state.calendarDate, this.props.intl.locale),
|
|
342
|
+
yearLabel: getYearCalendarLabel(this.state.calendarDate, this.props.intl.locale),
|
|
343
|
+
onPrevMonthClick: () => this.jumpMonth(-1),
|
|
344
|
+
onTodayClick: this.showToday,
|
|
345
|
+
onNextMonthClick: () => this.jumpMonth(1),
|
|
346
|
+
onPrevYearClick: () => this.jumpMonth(-12),
|
|
347
|
+
onNextYearClick: () => this.jumpMonth(12)
|
|
348
|
+
}), jsxs(CalendarContent, {
|
|
349
|
+
children: [_mapInstanceProperty(weekdays).call(weekdays, weekday => jsx(CalendarDay, {
|
|
350
|
+
type: "heading",
|
|
351
|
+
children: weekday
|
|
352
|
+
}, weekday)), _mapInstanceProperty(paddingDays).call(paddingDays, (_, index) => jsx(CalendarDay, {
|
|
353
|
+
type: "spacing"
|
|
354
|
+
}, index)), _mapInstanceProperty(calendarItems).call(calendarItems, (item, index) => {
|
|
355
|
+
const isHighlighted = this.state.suggestedItems.length + index === highlightedIndex;
|
|
356
|
+
const _getRange = getRange({
|
|
357
|
+
item,
|
|
358
|
+
value: this.props.value,
|
|
359
|
+
startDate: this.state.startDate,
|
|
360
|
+
highlightedItem: allItems[this.state.highlightedIndex || 0]
|
|
361
|
+
}),
|
|
362
|
+
isRangeStart = _getRange.isRangeStart,
|
|
363
|
+
isRangeBetween = _getRange.isRangeBetween,
|
|
364
|
+
isRangeEnd = _getRange.isRangeEnd;
|
|
365
|
+
return jsx(CalendarDay, _objectSpread(_objectSpread({
|
|
366
|
+
isToday: isSameDay(today, item)
|
|
367
|
+
}, getItemProps({
|
|
368
|
+
disabled: this.props.isDisabled,
|
|
369
|
+
item,
|
|
370
|
+
onMouseOut: () => {
|
|
371
|
+
// @ts-ignore
|
|
372
|
+
setHighlightedIndex(null);
|
|
373
|
+
}
|
|
374
|
+
})), {}, {
|
|
375
|
+
isHighlighted: isHighlighted,
|
|
376
|
+
isRangeStart: isRangeStart,
|
|
377
|
+
isRangeBetween: isRangeBetween,
|
|
378
|
+
isRangeEnd: isRangeEnd,
|
|
379
|
+
children: getCalendarDayLabel(item)
|
|
380
|
+
}), item);
|
|
381
|
+
})]
|
|
382
|
+
})]
|
|
383
|
+
}))]
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}, this.props.intl.locale)
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}], [{
|
|
390
|
+
key: "getDerivedStateFromProps",
|
|
391
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
392
|
+
// We need to update the input value string in case so that is is formatted
|
|
393
|
+
// according to the locale and holds the current value in case the value
|
|
394
|
+
// changes or when the locale changes
|
|
395
|
+
const shouldUpdateInputValue = !isSameRange(props.value, state.prevValue) || props.intl.locale !== state.prevLocale;
|
|
396
|
+
if (!shouldUpdateInputValue) return null;
|
|
397
|
+
return {
|
|
398
|
+
prevLocale: props.intl.locale,
|
|
399
|
+
// This is not the input value but the actual value passed to
|
|
400
|
+
// DateRangeInput
|
|
401
|
+
prevValue: props.value,
|
|
402
|
+
inputValue: formatRange(props.value, props.intl.locale)
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}]);
|
|
406
|
+
}(Component);
|
|
407
|
+
DateRangeInput.displayName = 'DateRangeInput';
|
|
408
|
+
DateRangeInput.defaultProps = {
|
|
409
|
+
isClearable: true
|
|
410
|
+
};
|
|
411
|
+
DateRangeInput.isEmpty = range => range.length === 0;
|
|
412
|
+
DateRangeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
413
|
+
horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
414
|
+
value: _pt.arrayOf(_pt.any).isRequired,
|
|
415
|
+
'aria-invalid': _pt.bool,
|
|
416
|
+
'aria-errormessage': _pt.string,
|
|
417
|
+
onChange: _pt.func,
|
|
418
|
+
isClearable: _pt.bool,
|
|
419
|
+
onFocus: _pt.func,
|
|
420
|
+
onBlur: _pt.func,
|
|
421
|
+
id: _pt.string,
|
|
422
|
+
name: _pt.string,
|
|
423
|
+
placeholder: _pt.string,
|
|
424
|
+
isCondensed: _pt.bool,
|
|
425
|
+
isDisabled: _pt.bool,
|
|
426
|
+
isReadOnly: _pt.bool,
|
|
427
|
+
hasError: _pt.bool,
|
|
428
|
+
hasWarning: _pt.bool
|
|
429
|
+
} : {};
|
|
430
|
+
var dateRangeInput = injectIntl(DateRangeInput);
|
|
431
|
+
|
|
432
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
433
|
+
var version = "19.25.1";
|
|
434
|
+
|
|
435
|
+
export { dateRangeInput as default, version };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type WrappedComponentProps } from 'react-intl';
|
|
2
|
+
import type { MomentInput } from 'moment';
|
|
3
|
+
type TCustomEvent = {
|
|
4
|
+
target: {
|
|
5
|
+
id?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
value?: MomentInput[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type TDateRangeInputProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Horizontal size limit of the input field.
|
|
13
|
+
*/
|
|
14
|
+
horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
15
|
+
/**
|
|
16
|
+
* The selected date range, must either be an empty array or an array of two strings holding dates formatted as "YYYY-MM-DD".
|
|
17
|
+
*/
|
|
18
|
+
value: MomentInput[];
|
|
19
|
+
/**
|
|
20
|
+
* Indicate if the value entered in the input is invalid.
|
|
21
|
+
*/
|
|
22
|
+
'aria-invalid'?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* HTML ID of an element containing an error message related to the input.
|
|
25
|
+
*/
|
|
26
|
+
'aria-errormessage'?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Called when the date range changes. Called with an event containing either an empty array (no value) or an array holding two string in this format: "YYYY-MM-DD".
|
|
29
|
+
*/
|
|
30
|
+
onChange?: (event: TCustomEvent) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Allows the range to be cleared
|
|
33
|
+
*/
|
|
34
|
+
isClearable?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Called when the date input gains focus.
|
|
37
|
+
*/
|
|
38
|
+
onFocus?: (event: TCustomEvent) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Called when the date input loses focus.
|
|
41
|
+
*/
|
|
42
|
+
onBlur?: (event: TCustomEvent) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Used as the HTML `id` attribute.
|
|
45
|
+
*/
|
|
46
|
+
id?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Used as the HTML `name` attribute.
|
|
49
|
+
*/
|
|
50
|
+
name?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Placeholder value to show in the input field
|
|
53
|
+
*/
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Use this property to reduce the paddings of the component for a ui compact variant
|
|
57
|
+
*/
|
|
58
|
+
isCondensed?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Disables the date picker
|
|
61
|
+
*/
|
|
62
|
+
isDisabled?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Disables the date picker menu and makes input field read-only
|
|
65
|
+
*/
|
|
66
|
+
isReadOnly?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Indicates the input field has an error
|
|
69
|
+
*/
|
|
70
|
+
hasError?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Indicates the input field has warning
|
|
73
|
+
*/
|
|
74
|
+
hasWarning?: boolean;
|
|
75
|
+
} & WrappedComponentProps;
|
|
76
|
+
declare const _default: import("react").FC<import("react-intl").WithIntlProps<TDateRangeInputProps>> & {
|
|
77
|
+
WrappedComponent: import("react").ComponentType<TDateRangeInputProps>;
|
|
78
|
+
};
|
|
79
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { TDateRangeInputProps } from "./date-range-input.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-uikit/date-range-input",
|
|
3
|
+
"description": "The `DateRangeInput` component allows the user to select a date range.",
|
|
4
|
+
"version": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
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-range-input"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://uikit.commercetools.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"javascript",
|
|
14
|
+
"typescript",
|
|
15
|
+
"design-system",
|
|
16
|
+
"react",
|
|
17
|
+
"uikit"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "dist/commercetools-uikit-date-range-input.cjs.js",
|
|
25
|
+
"module": "dist/commercetools-uikit-date-range-input.esm.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@babel/runtime": "^7.20.13",
|
|
31
|
+
"@babel/runtime-corejs3": "^7.20.13",
|
|
32
|
+
"@commercetools-uikit/accessible-button": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
33
|
+
"@commercetools-uikit/calendar-time-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
34
|
+
"@commercetools-uikit/calendar-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
35
|
+
"@commercetools-uikit/constraints": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
36
|
+
"@commercetools-uikit/design-system": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
37
|
+
"@commercetools-uikit/hooks": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
38
|
+
"@commercetools-uikit/icons": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
39
|
+
"@commercetools-uikit/secondary-icon-button": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
40
|
+
"@commercetools-uikit/select-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
41
|
+
"@commercetools-uikit/spacings-inline": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
42
|
+
"@commercetools-uikit/text": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
43
|
+
"@commercetools-uikit/tooltip": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
44
|
+
"@commercetools-uikit/utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
45
|
+
"@emotion/react": "^11.10.5",
|
|
46
|
+
"@emotion/styled": "^11.10.5",
|
|
47
|
+
"downshift": "6.1.12",
|
|
48
|
+
"prop-types": "15.8.1",
|
|
49
|
+
"react-is": "17.0.2",
|
|
50
|
+
"warning": "4.0.3"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"moment": "2.30.1",
|
|
54
|
+
"react": "17.0.2",
|
|
55
|
+
"react-intl": "^6.3.2"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"moment": "2.x",
|
|
59
|
+
"react": "17.x",
|
|
60
|
+
"react-intl": "6.x"
|
|
61
|
+
}
|
|
62
|
+
}
|