@elliemae/ds-date-range-picker 2.3.0-alpha.8 → 2.3.0-next.2
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/cjs/DSDateRangePicker.js +204 -0
- package/cjs/components/DSDateRangePickerImpl.js +343 -0
- package/cjs/components/DatePickerLabel/DatePickerLabel.js +20 -0
- package/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js +100 -0
- package/cjs/components/DayPickerRangeController.js +147 -0
- package/cjs/index.js +15 -0
- package/cjs/isMaxDiffSafe.js +20 -0
- package/esm/DSDateRangePicker.js +191 -0
- package/esm/components/DSDateRangePickerImpl.js +330 -0
- package/esm/components/DatePickerLabel/DatePickerLabel.js +14 -0
- package/{dist/esm → esm}/components/DatePickerRangeHeader/DatePickerRangeHeader.js +45 -36
- package/esm/components/DayPickerRangeController.js +139 -0
- package/esm/index.js +3 -0
- package/esm/isMaxDiffSafe.js +15 -0
- package/package.json +33 -35
- package/types/DSDateRangePicker.d.ts +243 -0
- package/types/components/DSDateRangePickerImpl.d.ts +24 -0
- package/types/components/DatePickerLabel/DatePickerLabel.d.ts +6 -0
- package/types/components/DatePickerRangeHeader/DatePickerRangeHeader.d.ts +10 -0
- package/types/components/DayPickerRangeController.d.ts +36 -0
- package/types/index.d.ts +2 -0
- package/types/isMaxDiffSafe.d.ts +2 -0
- package/dist/cjs/DSDateRangePicker.js +0 -210
- package/dist/cjs/DSDateRangePicker.js.map +0 -7
- package/dist/cjs/components/DSDateRangePickerImpl.js +0 -293
- package/dist/cjs/components/DSDateRangePickerImpl.js.map +0 -7
- package/dist/cjs/components/DatePickerLabel/DatePickerLabel.js +0 -39
- package/dist/cjs/components/DatePickerLabel/DatePickerLabel.js.map +0 -7
- package/dist/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js +0 -112
- package/dist/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +0 -7
- package/dist/cjs/components/DayPickerRangeController.js +0 -161
- package/dist/cjs/components/DayPickerRangeController.js.map +0 -7
- package/dist/cjs/index.js +0 -36
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/isMaxDiffSafe.js +0 -46
- package/dist/cjs/isMaxDiffSafe.js.map +0 -7
- package/dist/esm/DSDateRangePicker.js +0 -184
- package/dist/esm/DSDateRangePicker.js.map +0 -7
- package/dist/esm/components/DSDateRangePickerImpl.js +0 -264
- package/dist/esm/components/DSDateRangePickerImpl.js.map +0 -7
- package/dist/esm/components/DatePickerLabel/DatePickerLabel.js +0 -10
- package/dist/esm/components/DatePickerLabel/DatePickerLabel.js.map +0 -7
- package/dist/esm/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +0 -7
- package/dist/esm/components/DayPickerRangeController.js +0 -132
- package/dist/esm/components/DayPickerRangeController.js.map +0 -7
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/isMaxDiffSafe.js +0 -17
- package/dist/esm/isMaxDiffSafe.js.map +0 -7
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import { convertPropToCssClassName } from '@elliemae/ds-classnames';
|
|
5
|
+
import { DSFormItemLayout, DSInputMask, MASK_TYPES, MASK_PIPES } from '@elliemae/ds-form';
|
|
6
|
+
import DSPopper from '@elliemae/ds-popper';
|
|
7
|
+
import { renderMonthElement, DatePickerPicker } from '@elliemae/ds-date-picker';
|
|
8
|
+
import DayPickerRangeController from './DayPickerRangeController.js';
|
|
9
|
+
import { isMaxDiffSafe } from '../isMaxDiffSafe.js';
|
|
10
|
+
|
|
11
|
+
const START_DATE = 'startDate';
|
|
12
|
+
const END_DATE = 'endDate';
|
|
13
|
+
const {
|
|
14
|
+
classNameElement,
|
|
15
|
+
classNameBlock
|
|
16
|
+
} = convertPropToCssClassName('datepicker');
|
|
17
|
+
class DSDateRangePickerImpl extends React.Component {
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
|
|
21
|
+
this.onDatesChange = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
startDate,
|
|
24
|
+
endDate
|
|
25
|
+
} = _ref;
|
|
26
|
+
const {
|
|
27
|
+
onDatesChange
|
|
28
|
+
} = this.props;
|
|
29
|
+
onDatesChange(startDate, endDate);
|
|
30
|
+
const safe = isMaxDiffSafe(startDate, endDate, this.state.startDate, this.state.endDate);
|
|
31
|
+
|
|
32
|
+
if (!safe) {
|
|
33
|
+
this.setState({
|
|
34
|
+
showPicker: false
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.setState({
|
|
39
|
+
startDate,
|
|
40
|
+
endDate,
|
|
41
|
+
primaryStartInput: false,
|
|
42
|
+
primaryEndInput: false
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
this.onFocusChange = () => {
|
|
47
|
+
this.setState(_ref2 => {
|
|
48
|
+
let {
|
|
49
|
+
focusedInput
|
|
50
|
+
} = _ref2;
|
|
51
|
+
return {
|
|
52
|
+
focusedInput: focusedInput === START_DATE ? END_DATE : START_DATE
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.handleKeyDown = event => {
|
|
58
|
+
if (event.key === 'Escape') this.setState({
|
|
59
|
+
showPicker: false
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
this.getSafeStartInputValue = () => {
|
|
64
|
+
const {
|
|
65
|
+
startInput,
|
|
66
|
+
primaryStartInput,
|
|
67
|
+
startDate
|
|
68
|
+
} = this.state;
|
|
69
|
+
if (primaryStartInput && startInput) return startInput;
|
|
70
|
+
if (!startDate) return '';
|
|
71
|
+
return startDate.format('MMDDYYYY');
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
this.getSafeEndInputValue = () => {
|
|
75
|
+
const {
|
|
76
|
+
endInput,
|
|
77
|
+
primaryEndInput,
|
|
78
|
+
endDate
|
|
79
|
+
} = this.state;
|
|
80
|
+
if (primaryEndInput && endInput) return endInput;
|
|
81
|
+
if (!endDate) return '';
|
|
82
|
+
return endDate.format('MMDDYYYY');
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
this.changeFocus = () => {
|
|
86
|
+
const {
|
|
87
|
+
disabled
|
|
88
|
+
} = this.props;
|
|
89
|
+
|
|
90
|
+
if (!disabled) {
|
|
91
|
+
this.setState(() => ({
|
|
92
|
+
focusedInput: 'startDate'
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
this.handleChangeStart = e => {
|
|
98
|
+
var _momentValue;
|
|
99
|
+
|
|
100
|
+
const {
|
|
101
|
+
onChangeStartInput,
|
|
102
|
+
isDayBlocked,
|
|
103
|
+
minimumNights
|
|
104
|
+
} = this.props;
|
|
105
|
+
const {
|
|
106
|
+
endDate
|
|
107
|
+
} = this.state;
|
|
108
|
+
const startInputVal = e.target.value;
|
|
109
|
+
let momentValue = null;
|
|
110
|
+
|
|
111
|
+
if (startInputVal && moment(startInputVal, 'MM/DD/YYYY', true).isValid()) {
|
|
112
|
+
momentValue = moment(startInputVal);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const startDateBlocked = isDayBlocked(momentValue);
|
|
116
|
+
const isStartDateAcceptable = !startDateBlocked && momentValue && startInputVal !== '';
|
|
117
|
+
const areDatesValid = endDate && momentValue && (endDate === null || endDate === void 0 ? void 0 : endDate.isValid()) && ((_momentValue = momentValue) === null || _momentValue === void 0 ? void 0 : _momentValue.isValid());
|
|
118
|
+
const canEndBeSameAsStart = minimumNights === 0;
|
|
119
|
+
const isStartAcceptableWithSelectedEnd = !endDate || areDatesValid && (canEndBeSameAsStart && momentValue.diff(endDate, 'days') <= 0 || !canEndBeSameAsStart && momentValue.diff(endDate, 'days') < 0);
|
|
120
|
+
const invalidDate = !isStartDateAcceptable || !isStartAcceptableWithSelectedEnd;
|
|
121
|
+
if (startDateBlocked) momentValue = null;
|
|
122
|
+
onChangeStartInput(momentValue);
|
|
123
|
+
this.setState(prevState => ({
|
|
124
|
+
startDate: momentValue,
|
|
125
|
+
startInput: startInputVal,
|
|
126
|
+
primaryStartInput: true,
|
|
127
|
+
startDateError: invalidDate,
|
|
128
|
+
endDateError: !isStartDateAcceptable || !prevState.endDateError ? prevState.endDateError : !isStartAcceptableWithSelectedEnd
|
|
129
|
+
}));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
this.handleChangeEnd = e => {
|
|
133
|
+
var _momentValue2;
|
|
134
|
+
|
|
135
|
+
const {
|
|
136
|
+
onChangeEndInput,
|
|
137
|
+
isDayBlocked,
|
|
138
|
+
minimumNights
|
|
139
|
+
} = this.props;
|
|
140
|
+
const {
|
|
141
|
+
startDate
|
|
142
|
+
} = this.state;
|
|
143
|
+
const endInputValue = e.target.value;
|
|
144
|
+
let momentValue = null;
|
|
145
|
+
|
|
146
|
+
if (endInputValue && moment(endInputValue, 'MM/DD/YYYY', true).isValid()) {
|
|
147
|
+
momentValue = moment(endInputValue);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const endDateBlocked = isDayBlocked(momentValue);
|
|
151
|
+
const isEndDateAcceptable = !endDateBlocked && momentValue && endInputValue !== '';
|
|
152
|
+
const areDatesValid = startDate && momentValue && (startDate === null || startDate === void 0 ? void 0 : startDate.isValid()) && ((_momentValue2 = momentValue) === null || _momentValue2 === void 0 ? void 0 : _momentValue2.isValid());
|
|
153
|
+
const canEndBeSameAsStart = minimumNights === 0;
|
|
154
|
+
const isEndAcceptableWithSelectedStart = !startDate || // we can't compare with start date because it's not yet set
|
|
155
|
+
areDatesValid && ( // it's set and both are valid
|
|
156
|
+
canEndBeSameAsStart && momentValue.diff(startDate, 'days') >= 0 || // >= is valid
|
|
157
|
+
!canEndBeSameAsStart && momentValue.diff(startDate, 'days') > 0); // only > is valid
|
|
158
|
+
|
|
159
|
+
const invalidDate = !isEndDateAcceptable || !isEndAcceptableWithSelectedStart;
|
|
160
|
+
if (endDateBlocked) momentValue = null;
|
|
161
|
+
onChangeEndInput(momentValue);
|
|
162
|
+
this.setState(prevState => ({
|
|
163
|
+
endDate: momentValue,
|
|
164
|
+
endInput: endInputValue,
|
|
165
|
+
primaryEndInput: true,
|
|
166
|
+
startDateError: !isEndDateAcceptable || !prevState.startDateError ? prevState.startDateError : !isEndAcceptableWithSelectedStart,
|
|
167
|
+
endDateError: invalidDate
|
|
168
|
+
}));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
this.handleChangeDate = _ref3 => {
|
|
172
|
+
let {
|
|
173
|
+
startDate: _start,
|
|
174
|
+
endDate
|
|
175
|
+
} = _ref3;
|
|
176
|
+
|
|
177
|
+
if (_start && endDate) {
|
|
178
|
+
this.setState({
|
|
179
|
+
startDate: moment(_start),
|
|
180
|
+
endDate,
|
|
181
|
+
primaryStartInput: false,
|
|
182
|
+
primaryEndInput: false
|
|
183
|
+
});
|
|
184
|
+
} else if (_start) {
|
|
185
|
+
this.setState({
|
|
186
|
+
startDate: moment(_start),
|
|
187
|
+
primaryStartInput: false
|
|
188
|
+
});
|
|
189
|
+
} else if (endDate) {
|
|
190
|
+
this.setState({
|
|
191
|
+
endDate,
|
|
192
|
+
primaryEndInput: false
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
this.state = {
|
|
198
|
+
startDate: props.startDate ? moment(props.startDate) : null,
|
|
199
|
+
endDate: props.endDate ? moment(props.endDate) : null,
|
|
200
|
+
focusedInput: START_DATE,
|
|
201
|
+
showPicker: false,
|
|
202
|
+
startDateError: false,
|
|
203
|
+
endDateError: false
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
componentDidMount() {
|
|
208
|
+
document.addEventListener('keydown', this.handleKeyDown, false);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
componentWillUnmount() {
|
|
212
|
+
document.removeEventListener('keydown', this.handleKeyDown, false);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
render() {
|
|
216
|
+
const {
|
|
217
|
+
startDate,
|
|
218
|
+
endDate,
|
|
219
|
+
focusedInput,
|
|
220
|
+
showPicker,
|
|
221
|
+
startDateError,
|
|
222
|
+
endDateError
|
|
223
|
+
} = this.state;
|
|
224
|
+
const {
|
|
225
|
+
disabled,
|
|
226
|
+
displayFormatDay,
|
|
227
|
+
minimumNights,
|
|
228
|
+
labelFrom,
|
|
229
|
+
labelTo,
|
|
230
|
+
isDayBlocked,
|
|
231
|
+
isDayHighlighted,
|
|
232
|
+
isOutsideRange,
|
|
233
|
+
enableOutsideDays,
|
|
234
|
+
startDateRequired,
|
|
235
|
+
endDateRequired,
|
|
236
|
+
onOutsideClick,
|
|
237
|
+
onNextMonthClick,
|
|
238
|
+
onPrevMonthClick,
|
|
239
|
+
onClose,
|
|
240
|
+
hasError,
|
|
241
|
+
validationMessage
|
|
242
|
+
} = this.props;
|
|
243
|
+
const inputClass = classNameBlock('inputs', 'range-picker');
|
|
244
|
+
const inputClassModifier = '';
|
|
245
|
+
const safeStartInputValue = this.getSafeStartInputValue();
|
|
246
|
+
const safeEndInputValue = this.getSafeEndInputValue();
|
|
247
|
+
return /*#__PURE__*/_jsx("div", {
|
|
248
|
+
className: "".concat(inputClass, " ").concat(inputClassModifier)
|
|
249
|
+
}, void 0, /*#__PURE__*/_jsx("div", {
|
|
250
|
+
className: classNameBlock('wrapper-input-date-range-picker-controller')
|
|
251
|
+
}, void 0, /*#__PURE__*/_jsx(DSFormItemLayout, {
|
|
252
|
+
floatingLabel: true,
|
|
253
|
+
inputComponent: DSInputMask,
|
|
254
|
+
labelText: labelFrom,
|
|
255
|
+
mask: MASK_TYPES.DATE,
|
|
256
|
+
onChange: this.handleChangeStart,
|
|
257
|
+
onFocus: () => this.setState({
|
|
258
|
+
showPicker: false
|
|
259
|
+
}),
|
|
260
|
+
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
261
|
+
value: safeStartInputValue,
|
|
262
|
+
required: startDateRequired,
|
|
263
|
+
hasError: hasError || startDateError,
|
|
264
|
+
placeholder: "MM/DD/YYYY"
|
|
265
|
+
}), /*#__PURE__*/_jsx(DSFormItemLayout, {
|
|
266
|
+
floatingLabel: true,
|
|
267
|
+
inputComponent: DSInputMask,
|
|
268
|
+
labelText: labelTo,
|
|
269
|
+
mask: MASK_TYPES.DATE,
|
|
270
|
+
onChange: this.handleChangeEnd,
|
|
271
|
+
onFocus: () => this.setState({
|
|
272
|
+
showPicker: false
|
|
273
|
+
}),
|
|
274
|
+
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
275
|
+
value: safeEndInputValue,
|
|
276
|
+
required: endDateRequired,
|
|
277
|
+
hasError: hasError || endDateError,
|
|
278
|
+
validationMessage: validationMessage,
|
|
279
|
+
placeholder: "MM/DD/YYYY"
|
|
280
|
+
})), /*#__PURE__*/_jsx("div", {
|
|
281
|
+
className: classNameBlock('wrapper-button-date-range-picker-controller')
|
|
282
|
+
}, void 0, /*#__PURE__*/_jsx(DSPopper, {
|
|
283
|
+
contentComponent: /*#__PURE__*/_jsx("div", {}, void 0, showPicker && /*#__PURE__*/_jsx(DayPickerRangeController, {
|
|
284
|
+
enableOutsideDays: enableOutsideDays,
|
|
285
|
+
isDayBlocked: isDayBlocked,
|
|
286
|
+
isDayHighlighted: isDayHighlighted,
|
|
287
|
+
isOutsideRange: isOutsideRange,
|
|
288
|
+
displayFormatDay: displayFormatDay,
|
|
289
|
+
endDate: endDate,
|
|
290
|
+
focusedInput: focusedInput,
|
|
291
|
+
hideKeyboardShortcutsPanel: true,
|
|
292
|
+
minimumNights: minimumNights,
|
|
293
|
+
onDatesChange: this.onDatesChange,
|
|
294
|
+
onFocusChange: this.onFocusChange,
|
|
295
|
+
onOutsideClick: e => {
|
|
296
|
+
onOutsideClick(e);
|
|
297
|
+
this.setState({
|
|
298
|
+
showPicker: false
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
onNextMonthClick: onNextMonthClick,
|
|
302
|
+
onPrevMonthClick: onPrevMonthClick,
|
|
303
|
+
startDate: startDate,
|
|
304
|
+
renderMonthElement: renderMonthElement
|
|
305
|
+
})),
|
|
306
|
+
isOpen: showPicker && !startDateError && !endDateError,
|
|
307
|
+
onClose: onClose,
|
|
308
|
+
placement: "bottom-end",
|
|
309
|
+
showArrow: false,
|
|
310
|
+
triggerComponent: /*#__PURE__*/_jsx("div", {
|
|
311
|
+
onFocus: () => this.setState({
|
|
312
|
+
showPicker: true
|
|
313
|
+
})
|
|
314
|
+
}, void 0, /*#__PURE__*/_jsx(DatePickerPicker, {
|
|
315
|
+
className: classNameElement('picker'),
|
|
316
|
+
disabled: disabled,
|
|
317
|
+
onClick: () => this.setState({
|
|
318
|
+
showPicker: true
|
|
319
|
+
})
|
|
320
|
+
}), hasError && validationMessage && /*#__PURE__*/_jsx("div", {
|
|
321
|
+
style: {
|
|
322
|
+
height: 15
|
|
323
|
+
}
|
|
324
|
+
}))
|
|
325
|
+
})));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export { END_DATE, START_DATE, DSDateRangePickerImpl as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
const Label = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
className = 'date-picker-label',
|
|
7
|
+
label = ''
|
|
8
|
+
} = _ref;
|
|
9
|
+
return /*#__PURE__*/_jsx("div", {
|
|
10
|
+
className: className
|
|
11
|
+
}, void 0, /*#__PURE__*/_jsx("span", {}, void 0, label));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { Label as default };
|
|
@@ -1,63 +1,75 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
import DSInputMask, { DSInputGroup, MASK_TYPES, MASK_PIPES } from '@elliemae/ds-form';
|
|
6
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
7
|
+
|
|
8
|
+
const blockname = 'date-range-picker';
|
|
9
|
+
const Header = aggregatedClasses('div')(blockname, 'header');
|
|
10
|
+
|
|
11
|
+
const formatDate = date => {
|
|
9
12
|
if (date) {
|
|
10
|
-
return date.format(
|
|
13
|
+
return date.format('MMDDYYYY');
|
|
11
14
|
}
|
|
12
15
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
|
|
17
|
+
const DatePickerRangeHeader = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
placeholderStart = 'Start Date',
|
|
20
|
+
placeholderEnd = 'End Date',
|
|
21
|
+
onStartInputChange = () => null,
|
|
22
|
+
onEndInputChange = () => null,
|
|
23
|
+
selectedStartDate,
|
|
24
|
+
selectedEndDate
|
|
25
|
+
} = _ref;
|
|
26
|
+
const [startValue, setStartValue] = useState(selectedStartDate ? formatDate(selectedStartDate) : '');
|
|
27
|
+
const [endValue, setEndValue] = useState(selectedEndDate ? formatDate(selectedEndDate) : '');
|
|
23
28
|
useEffect(() => {
|
|
24
29
|
const startDate = formatDate(selectedStartDate);
|
|
25
30
|
const endDate = formatDate(selectedEndDate);
|
|
26
31
|
startDate !== startValue && setStartValue(startDate);
|
|
27
32
|
endDate !== endValue && setEndValue(endDate);
|
|
28
33
|
}, [selectedStartDate, selectedEndDate]);
|
|
29
|
-
|
|
34
|
+
|
|
35
|
+
const handleOnChangeStart = e => {
|
|
30
36
|
const newStartValue = e.target.value;
|
|
31
37
|
setStartValue(newStartValue);
|
|
32
38
|
};
|
|
33
|
-
|
|
39
|
+
|
|
40
|
+
const handleOnChangeEnd = e => {
|
|
34
41
|
const newEndValue = e.target.value;
|
|
35
42
|
setEndValue(newEndValue);
|
|
36
43
|
};
|
|
37
|
-
|
|
44
|
+
|
|
45
|
+
const handleOnBlurStart = e => {
|
|
38
46
|
const newStartValue = e.target.value;
|
|
39
47
|
onStartInputChange(moment(newStartValue));
|
|
40
48
|
};
|
|
41
|
-
|
|
49
|
+
|
|
50
|
+
const handleOnBlurEnd = e => {
|
|
42
51
|
const newEndValue = e.target.value;
|
|
43
52
|
onEndInputChange(moment(newEndValue));
|
|
44
53
|
};
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
|
|
55
|
+
const handleOnKeyDownStart = e => {
|
|
56
|
+
if (e.key === 'Enter') {
|
|
47
57
|
const newValue = e.target.value;
|
|
48
58
|
onStartInputChange(moment(newValue));
|
|
49
59
|
e.target.blur();
|
|
50
60
|
}
|
|
51
61
|
};
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
|
|
63
|
+
const handleOnKeyDownEnd = e => {
|
|
64
|
+
if (e.key === 'Enter') {
|
|
54
65
|
const newValue = e.target.value;
|
|
55
66
|
onEndInputChange(moment(newValue));
|
|
56
67
|
e.target.blur();
|
|
57
68
|
}
|
|
58
69
|
};
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
|
|
71
|
+
return /*#__PURE__*/_jsx(Header, {}, void 0, /*#__PURE__*/_jsx(DSInputGroup, {}, void 0, /*#__PURE__*/_jsx(DSInputMask, {
|
|
72
|
+
"aria-label": placeholderStart || 'Date Picker Input Mask',
|
|
61
73
|
mask: MASK_TYPES.DATE,
|
|
62
74
|
onBlur: handleOnBlurStart,
|
|
63
75
|
onChange: handleOnChangeStart,
|
|
@@ -65,8 +77,8 @@ const DatePickerRangeHeader = ({
|
|
|
65
77
|
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
66
78
|
placeholder: placeholderStart,
|
|
67
79
|
value: startValue
|
|
68
|
-
}),
|
|
69
|
-
"aria-label": placeholderEnd ||
|
|
80
|
+
}), /*#__PURE__*/_jsx(DSInputMask, {
|
|
81
|
+
"aria-label": placeholderEnd || 'Date Picker Input Mask',
|
|
70
82
|
mask: MASK_TYPES.DATE,
|
|
71
83
|
onBlur: handleOnBlurEnd,
|
|
72
84
|
onChange: handleOnChangeEnd,
|
|
@@ -76,8 +88,5 @@ const DatePickerRangeHeader = ({
|
|
|
76
88
|
value: endValue
|
|
77
89
|
})));
|
|
78
90
|
};
|
|
79
|
-
|
|
80
|
-
export {
|
|
81
|
-
DatePickerRangeHeader_default as default
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=DatePickerRangeHeader.js.map
|
|
91
|
+
|
|
92
|
+
export { DatePickerRangeHeader as default };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
10
|
+
import { useRef, useEffect } from 'react';
|
|
11
|
+
import { DayPickerRangeController as DayPickerRangeController$1 } from 'react-dates';
|
|
12
|
+
import { DatePickerNavigation, DatePickerDay, renderMonthElement } from '@elliemae/ds-date-picker';
|
|
13
|
+
import { ChevronLeft } from '@elliemae/ds-icons';
|
|
14
|
+
import { convertPropToCssClassName } from '@elliemae/ds-classnames';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
const _excluded = ["endDate", "startDate", "displayFormatDay", "focusedInput", "enableOutsideDays", "onDatesChange", "onFocusChange", "onOutsideClick", "isDayBlocked", "isDayHighlighted", "isOutsideRange", "onNextMonthClick", "onPrevMonthClick"];
|
|
18
|
+
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
+
const {
|
|
23
|
+
classNameElement,
|
|
24
|
+
classNameBlock
|
|
25
|
+
} = convertPropToCssClassName('datepicker-range');
|
|
26
|
+
|
|
27
|
+
const DayPickerRangeController = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
endDate = undefined,
|
|
30
|
+
startDate = undefined,
|
|
31
|
+
displayFormatDay = 'D',
|
|
32
|
+
focusedInput = undefined,
|
|
33
|
+
enableOutsideDays = false,
|
|
34
|
+
onDatesChange = () => null,
|
|
35
|
+
onFocusChange = () => null,
|
|
36
|
+
onOutsideClick = () => null,
|
|
37
|
+
isDayBlocked = () => null,
|
|
38
|
+
isDayHighlighted = () => null,
|
|
39
|
+
isOutsideRange = () => null,
|
|
40
|
+
onNextMonthClick = () => null,
|
|
41
|
+
onPrevMonthClick = () => null
|
|
42
|
+
} = _ref,
|
|
43
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
|
|
45
|
+
const datePickerRef = useRef();
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const handleMouseUp = () => {
|
|
48
|
+
const focusedElement = document.activeElement;
|
|
49
|
+
focusedElement.blur();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleKeyDown = event => {
|
|
53
|
+
const [firstDay, ...restOfDays] = document.getElementsByClassName('CalendarMonthGrid_month__horizontal')[1].getElementsByClassName('CalendarDay');
|
|
54
|
+
const [lastDay] = restOfDays.slice(-1);
|
|
55
|
+
const focusedElement = document.activeElement;
|
|
56
|
+
const [prev, next] = document.getElementsByClassName('DayPickerNavigation_button');
|
|
57
|
+
|
|
58
|
+
switch (event.key) {
|
|
59
|
+
case 'Home':
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
firstDay.focus();
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'End':
|
|
65
|
+
event.stopPropagation();
|
|
66
|
+
lastDay.focus();
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case 'Enter':
|
|
70
|
+
case ' ':
|
|
71
|
+
if (focusedElement === prev) {
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
prev.focus();
|
|
75
|
+
}, 240);
|
|
76
|
+
} else if (focusedElement === next) {
|
|
77
|
+
event.stopPropagation();
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
next === null || next === void 0 ? void 0 : next.focus();
|
|
80
|
+
}, 240);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case 'Tab':
|
|
86
|
+
if (firstDay === focusedElement || restOfDays.includes(focusedElement)) {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
prev.focus();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
datePickerRef.current.addEventListener('mouseup', handleMouseUp, false);
|
|
96
|
+
datePickerRef.current.addEventListener('keydown', handleKeyDown, false);
|
|
97
|
+
return () => {
|
|
98
|
+
if (datePickerRef.current) {
|
|
99
|
+
datePickerRef.current.removeEventListener('mouseup', handleMouseUp, false);
|
|
100
|
+
datePickerRef.current.removeEventListener('keydown', handleKeyDown, false);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}, []);
|
|
104
|
+
return /*#__PURE__*/jsx("div", {
|
|
105
|
+
ref: datePickerRef,
|
|
106
|
+
className: classNameBlock('wrapper-day-picker-single-date-controller'),
|
|
107
|
+
"data-testid": otherProps['data-testid'] || 'date-range-picker-controller',
|
|
108
|
+
children: /*#__PURE__*/jsx(DayPickerRangeController$1, _objectSpread(_objectSpread({}, otherProps), {}, {
|
|
109
|
+
isDayBlocked: isDayBlocked,
|
|
110
|
+
isDayHighlighted: isDayHighlighted,
|
|
111
|
+
isOutsideRange: isOutsideRange,
|
|
112
|
+
enableOutsideDays: enableOutsideDays,
|
|
113
|
+
endDate: endDate,
|
|
114
|
+
focused: true,
|
|
115
|
+
focusedInput: focusedInput,
|
|
116
|
+
hideKeyboardShortcutsPanel: true,
|
|
117
|
+
navNext: /*#__PURE__*/_jsx(DatePickerNavigation, {
|
|
118
|
+
className: classNameElement('navigation-next')
|
|
119
|
+
}),
|
|
120
|
+
navPrev: /*#__PURE__*/_jsx(DatePickerNavigation, {
|
|
121
|
+
className: classNameElement('navigation-prev'),
|
|
122
|
+
icon: ChevronLeft
|
|
123
|
+
}),
|
|
124
|
+
onDatesChange: onDatesChange,
|
|
125
|
+
onFocusChange: onFocusChange,
|
|
126
|
+
onOutsideClick: onOutsideClick,
|
|
127
|
+
onNextMonthClick: onNextMonthClick,
|
|
128
|
+
onPrevMonthClick: onPrevMonthClick,
|
|
129
|
+
renderDayContents: date => /*#__PURE__*/_jsx(DatePickerDay, {
|
|
130
|
+
className: classNameElement('day-contents'),
|
|
131
|
+
date: date.format(displayFormatDay)
|
|
132
|
+
}),
|
|
133
|
+
renderMonthElement: renderMonthElement,
|
|
134
|
+
startDate: startDate
|
|
135
|
+
}))
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export { DayPickerRangeController as default };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable max-params */
|
|
2
|
+
const MAX_YEARS_DIFF = 150; // https://jira.elliemae.io/browse/PUI-4145
|
|
3
|
+
|
|
4
|
+
const isMaxDiffSafe = (startDate, endDate, prevStart, prevEnd) => {
|
|
5
|
+
try {
|
|
6
|
+
const diff = Math.abs(endDate.diff(startDate, 'years'));
|
|
7
|
+
const diffStart = Math.abs(startDate.diff(prevStart, 'years'));
|
|
8
|
+
const diffEnd = Math.abs(endDate.diff(prevEnd, 'years'));
|
|
9
|
+
return diff < MAX_YEARS_DIFF && diffStart < MAX_YEARS_DIFF && diffEnd < MAX_YEARS_DIFF;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { MAX_YEARS_DIFF, isMaxDiffSafe };
|