1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DateRangePicker = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var classnames_1 = tslib_1.__importDefault(require("classnames"));
|
21 | var React = tslib_1.__importStar(require("react"));
|
22 | var react_day_picker_1 = tslib_1.__importDefault(require("react-day-picker"));
|
23 | var core_1 = require("@blueprintjs/core");
|
24 | var DateClasses = tslib_1.__importStar(require("./common/classes"));
|
25 | var DateUtils = tslib_1.__importStar(require("./common/dateUtils"));
|
26 | var Errors = tslib_1.__importStar(require("./common/errors"));
|
27 | var monthAndYear_1 = require("./common/monthAndYear");
|
28 | var datePickerCaption_1 = require("./datePickerCaption");
|
29 | var datePickerCore_1 = require("./datePickerCore");
|
30 | var datePickerNavbar_1 = require("./datePickerNavbar");
|
31 | var dateRangeSelectionStrategy_1 = require("./dateRangeSelectionStrategy");
|
32 | var shortcuts_1 = require("./shortcuts");
|
33 | var timePicker_1 = require("./timePicker");
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var DateRangePicker = (function (_super) {
|
40 | tslib_1.__extends(DateRangePicker, _super);
|
41 | function DateRangePicker(props, context) {
|
42 | var _a;
|
43 | var _this = _super.call(this, props, context) || this;
|
44 |
|
45 | _this.modifiers = (_a = {},
|
46 | _a[datePickerCore_1.SELECTED_RANGE_MODIFIER] = function (day) {
|
47 | var value = _this.state.value;
|
48 | return value[0] != null && value[1] != null && DateUtils.isDayInRange(day, value, true);
|
49 | },
|
50 | _a["".concat(datePickerCore_1.SELECTED_RANGE_MODIFIER, "-start")] = function (day) { return DateUtils.areSameDay(_this.state.value[0], day); },
|
51 | _a["".concat(datePickerCore_1.SELECTED_RANGE_MODIFIER, "-end")] = function (day) { return DateUtils.areSameDay(_this.state.value[1], day); },
|
52 | _a[datePickerCore_1.HOVERED_RANGE_MODIFIER] = function (day) {
|
53 | var _a = _this.state, hoverValue = _a.hoverValue, _b = _a.value, selectedStart = _b[0], selectedEnd = _b[1];
|
54 | if (selectedStart == null && selectedEnd == null) {
|
55 | return false;
|
56 | }
|
57 | if (hoverValue == null || hoverValue[0] == null || hoverValue[1] == null) {
|
58 | return false;
|
59 | }
|
60 | return DateUtils.isDayInRange(day, hoverValue, true);
|
61 | },
|
62 | _a["".concat(datePickerCore_1.HOVERED_RANGE_MODIFIER, "-start")] = function (day) {
|
63 | var hoverValue = _this.state.hoverValue;
|
64 | if (hoverValue == null || hoverValue[0] == null) {
|
65 | return false;
|
66 | }
|
67 | return DateUtils.areSameDay(hoverValue[0], day);
|
68 | },
|
69 | _a["".concat(datePickerCore_1.HOVERED_RANGE_MODIFIER, "-end")] = function (day) {
|
70 | var hoverValue = _this.state.hoverValue;
|
71 | if (hoverValue == null || hoverValue[1] == null) {
|
72 | return false;
|
73 | }
|
74 | return DateUtils.areSameDay(hoverValue[1], day);
|
75 | },
|
76 | _a);
|
77 | _this.shouldHighlightCurrentDay = function (date) {
|
78 | var highlightCurrentDay = _this.props.highlightCurrentDay;
|
79 | return highlightCurrentDay && DateUtils.isToday(date);
|
80 | };
|
81 | _this.getDateRangePickerModifiers = function () {
|
82 | var modifiers = _this.props.modifiers;
|
83 | return (0, datePickerCore_1.combineModifiers)(_this.modifiers, tslib_1.__assign({ isToday: _this.shouldHighlightCurrentDay }, modifiers));
|
84 | };
|
85 | _this.renderDay = function (day) {
|
86 | var date = day.getDate();
|
87 | return React.createElement("div", { className: DateClasses.DATEPICKER_DAY_WRAPPER }, date);
|
88 | };
|
89 | _this.disabledDays = function (day) { return !DateUtils.isDayInRange(day, [_this.props.minDate, _this.props.maxDate]); };
|
90 | _this.getDisabledDaysModifier = function () {
|
91 | var disabledDays = _this.props.dayPickerProps.disabledDays;
|
92 | return disabledDays instanceof Array ? tslib_1.__spreadArray([_this.disabledDays], disabledDays, true) : [_this.disabledDays, disabledDays];
|
93 | };
|
94 | _this.handleTimeChange = function (newTime, dateIndex) {
|
95 | var _a, _b, _c, _d;
|
96 | (_b = (_a = _this.props.timePickerProps) === null || _a === void 0 ? void 0 : _a.onChange) === null || _b === void 0 ? void 0 : _b.call(_a, newTime);
|
97 | var _e = _this.state, value = _e.value, time = _e.time;
|
98 | var newValue = DateUtils.getDateTime(value[dateIndex] != null ? DateUtils.clone(value[dateIndex]) : new Date(), newTime);
|
99 | var newDateRange = [value[0], value[1]];
|
100 | newDateRange[dateIndex] = newValue;
|
101 | var newTimeRange = [time[0], time[1]];
|
102 | newTimeRange[dateIndex] = newTime;
|
103 | (_d = (_c = _this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, newDateRange);
|
104 | _this.setState({ value: newDateRange, time: newTimeRange });
|
105 | };
|
106 | _this.handleTimeChangeLeftCalendar = function (time) {
|
107 | _this.handleTimeChange(time, 0);
|
108 | };
|
109 | _this.handleTimeChangeRightCalendar = function (time) {
|
110 | _this.handleTimeChange(time, 1);
|
111 | };
|
112 | _this.renderSingleNavbar = function (navbarProps) { return (React.createElement(datePickerNavbar_1.DatePickerNavbar, tslib_1.__assign({}, navbarProps, { maxDate: _this.props.maxDate, minDate: _this.props.minDate }))); };
|
113 | _this.renderLeftNavbar = function (navbarProps) { return (React.createElement(datePickerNavbar_1.DatePickerNavbar, tslib_1.__assign({}, navbarProps, { hideRightNavButton: _this.props.contiguousCalendarMonths, maxDate: _this.props.maxDate, minDate: _this.props.minDate }))); };
|
114 | _this.renderRightNavbar = function (navbarProps) { return (React.createElement(datePickerNavbar_1.DatePickerNavbar, tslib_1.__assign({}, navbarProps, { hideLeftNavButton: _this.props.contiguousCalendarMonths, maxDate: _this.props.maxDate, minDate: _this.props.minDate }))); };
|
115 | _this.renderSingleCaption = function (captionProps) { return (React.createElement(datePickerCaption_1.DatePickerCaption, tslib_1.__assign({}, captionProps, { maxDate: _this.props.maxDate, minDate: _this.props.minDate, onMonthChange: _this.handleLeftMonthSelectChange, onYearChange: _this.handleLeftYearSelectChange, reverseMonthAndYearMenus: _this.props.reverseMonthAndYearMenus }))); };
|
116 | _this.renderLeftCaption = function (captionProps) { return (React.createElement(datePickerCaption_1.DatePickerCaption, tslib_1.__assign({}, captionProps, { maxDate: DateUtils.getDatePreviousMonth(_this.props.maxDate), minDate: _this.props.minDate, onMonthChange: _this.handleLeftMonthSelectChange, onYearChange: _this.handleLeftYearSelectChange, reverseMonthAndYearMenus: _this.props.reverseMonthAndYearMenus }))); };
|
117 | _this.renderRightCaption = function (captionProps) { return (React.createElement(datePickerCaption_1.DatePickerCaption, tslib_1.__assign({}, captionProps, { maxDate: _this.props.maxDate, minDate: DateUtils.getDateNextMonth(_this.props.minDate), onMonthChange: _this.handleRightMonthSelectChange, onYearChange: _this.handleRightYearSelectChange, reverseMonthAndYearMenus: _this.props.reverseMonthAndYearMenus }))); };
|
118 | _this.handleDayMouseEnter = function (day, modifiers, e) {
|
119 | var _a, _b, _c, _d;
|
120 | (_b = (_a = _this.props.dayPickerProps).onDayMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, day, modifiers, e);
|
121 | if (modifiers.disabled) {
|
122 | return;
|
123 | }
|
124 | var _e = dateRangeSelectionStrategy_1.DateRangeSelectionStrategy.getNextState(_this.state.value, day, _this.props.allowSingleDayRange, _this.props.boundaryToModify), dateRange = _e.dateRange, boundary = _e.boundary;
|
125 | _this.setState({ hoverValue: dateRange });
|
126 | (_d = (_c = _this.props).onHoverChange) === null || _d === void 0 ? void 0 : _d.call(_c, dateRange, day, boundary);
|
127 | };
|
128 | _this.handleDayMouseLeave = function (day, modifiers, e) {
|
129 | var _a, _b, _c, _d;
|
130 | (_b = (_a = _this.props.dayPickerProps).onDayMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, day, modifiers, e);
|
131 | if (modifiers.disabled) {
|
132 | return;
|
133 | }
|
134 | _this.setState({ hoverValue: undefined });
|
135 | (_d = (_c = _this.props).onHoverChange) === null || _d === void 0 ? void 0 : _d.call(_c, undefined, day, undefined);
|
136 | };
|
137 | _this.handleDayClick = function (day, modifiers, e) {
|
138 | var _a, _b;
|
139 | (_b = (_a = _this.props.dayPickerProps).onDayClick) === null || _b === void 0 ? void 0 : _b.call(_a, day, modifiers, e);
|
140 | if (modifiers.disabled) {
|
141 |
|
142 | _this.forceUpdate();
|
143 | return;
|
144 | }
|
145 | var nextValue = dateRangeSelectionStrategy_1.DateRangeSelectionStrategy.getNextState(_this.state.value, day, _this.props.allowSingleDayRange, _this.props.boundaryToModify).dateRange;
|
146 |
|
147 |
|
148 | _this.handleDayMouseEnter(day, modifiers, e);
|
149 | _this.handleNextState(nextValue);
|
150 | };
|
151 | _this.handleShortcutClick = function (shortcut, selectedShortcutIndex) {
|
152 | var _a = _this.props, onChange = _a.onChange, contiguousCalendarMonths = _a.contiguousCalendarMonths, onShortcutChange = _a.onShortcutChange;
|
153 | var dateRange = shortcut.dateRange, includeTime = shortcut.includeTime;
|
154 | if (includeTime) {
|
155 | var newDateRange = [dateRange[0], dateRange[1]];
|
156 | var newTimeRange = [dateRange[0], dateRange[1]];
|
157 | var nextState = getStateChange(_this.state.value, dateRange, _this.state, contiguousCalendarMonths);
|
158 | _this.setState(tslib_1.__assign(tslib_1.__assign({}, nextState), { time: newTimeRange }));
|
159 | onChange === null || onChange === void 0 ? void 0 : onChange(newDateRange);
|
160 | }
|
161 | else {
|
162 | _this.handleNextState(dateRange);
|
163 | }
|
164 | if (_this.props.selectedShortcutIndex === undefined) {
|
165 | _this.setState({ selectedShortcutIndex: selectedShortcutIndex });
|
166 | }
|
167 | onShortcutChange === null || onShortcutChange === void 0 ? void 0 : onShortcutChange(shortcut, selectedShortcutIndex);
|
168 | };
|
169 | _this.handleNextState = function (nextValue) {
|
170 | var _a, _b;
|
171 | var value = _this.state.value;
|
172 | nextValue[0] = DateUtils.getDateTime(nextValue[0], _this.state.time[0]);
|
173 | nextValue[1] = DateUtils.getDateTime(nextValue[1], _this.state.time[1]);
|
174 | var nextState = getStateChange(value, nextValue, _this.state, _this.props.contiguousCalendarMonths);
|
175 | if (_this.props.value == null) {
|
176 | _this.setState(nextState);
|
177 | }
|
178 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, nextValue);
|
179 | };
|
180 | _this.handleLeftMonthChange = function (newDate) {
|
181 | var _a, _b;
|
182 | var leftView = monthAndYear_1.MonthAndYear.fromDate(newDate);
|
183 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, leftView.getFullDate());
|
184 | _this.updateLeftView(leftView);
|
185 | };
|
186 | _this.handleRightMonthChange = function (newDate) {
|
187 | var _a, _b;
|
188 | var rightView = monthAndYear_1.MonthAndYear.fromDate(newDate);
|
189 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, rightView.getFullDate());
|
190 | _this.updateRightView(rightView);
|
191 | };
|
192 | _this.handleLeftMonthSelectChange = function (leftMonth) {
|
193 | var _a, _b;
|
194 | var leftView = new monthAndYear_1.MonthAndYear(leftMonth, _this.state.leftView.getYear());
|
195 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, leftView.getFullDate());
|
196 | _this.updateLeftView(leftView);
|
197 | };
|
198 | _this.handleRightMonthSelectChange = function (rightMonth) {
|
199 | var _a, _b;
|
200 | var rightView = new monthAndYear_1.MonthAndYear(rightMonth, _this.state.rightView.getYear());
|
201 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, rightView.getFullDate());
|
202 | _this.updateRightView(rightView);
|
203 | };
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | _this.handleLeftYearSelectChange = function (leftDisplayYear) {
|
212 | var _a, _b;
|
213 | var leftView = new monthAndYear_1.MonthAndYear(_this.state.leftView.getMonth(), leftDisplayYear);
|
214 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, leftView.getFullDate());
|
215 | var _c = _this.props, minDate = _c.minDate, maxDate = _c.maxDate;
|
216 | var adjustedMaxDate = DateUtils.getDatePreviousMonth(maxDate);
|
217 | var minMonthAndYear = new monthAndYear_1.MonthAndYear(minDate.getMonth(), minDate.getFullYear());
|
218 | var maxMonthAndYear = new monthAndYear_1.MonthAndYear(adjustedMaxDate.getMonth(), adjustedMaxDate.getFullYear());
|
219 | if (leftView.isBefore(minMonthAndYear)) {
|
220 | leftView = minMonthAndYear;
|
221 | }
|
222 | else if (leftView.isAfter(maxMonthAndYear)) {
|
223 | leftView = maxMonthAndYear;
|
224 | }
|
225 | var rightView = _this.state.rightView.clone();
|
226 | if (!leftView.isBefore(rightView) || _this.props.contiguousCalendarMonths) {
|
227 | rightView = leftView.getNextMonth();
|
228 | }
|
229 | _this.setViews(leftView, rightView);
|
230 | };
|
231 | _this.handleRightYearSelectChange = function (rightDisplayYear) {
|
232 | var _a, _b;
|
233 | var rightView = new monthAndYear_1.MonthAndYear(_this.state.rightView.getMonth(), rightDisplayYear);
|
234 | (_b = (_a = _this.props.dayPickerProps).onMonthChange) === null || _b === void 0 ? void 0 : _b.call(_a, rightView.getFullDate());
|
235 | var _c = _this.props, minDate = _c.minDate, maxDate = _c.maxDate;
|
236 | var adjustedMinDate = DateUtils.getDateNextMonth(minDate);
|
237 | var minMonthAndYear = monthAndYear_1.MonthAndYear.fromDate(adjustedMinDate);
|
238 | var maxMonthAndYear = monthAndYear_1.MonthAndYear.fromDate(maxDate);
|
239 | if (rightView.isBefore(minMonthAndYear)) {
|
240 | rightView = minMonthAndYear;
|
241 | }
|
242 | else if (rightView.isAfter(maxMonthAndYear)) {
|
243 | rightView = maxMonthAndYear;
|
244 | }
|
245 | var leftView = _this.state.leftView.clone();
|
246 | if (!rightView.isAfter(leftView) || _this.props.contiguousCalendarMonths) {
|
247 | leftView = rightView.getPreviousMonth();
|
248 | }
|
249 | _this.setViews(leftView, rightView);
|
250 | };
|
251 | var value = getInitialValue(props);
|
252 | var time = value;
|
253 | var initialMonth = getInitialMonth(props, value);
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | var initialMonthEqualsMinMonth = DateUtils.areSameMonth(initialMonth, props.minDate);
|
259 | var initalMonthEqualsMaxMonth = DateUtils.areSameMonth(initialMonth, props.maxDate);
|
260 | if (!props.singleMonthOnly && !initialMonthEqualsMinMonth && initalMonthEqualsMaxMonth) {
|
261 | initialMonth.setMonth(initialMonth.getMonth() - 1);
|
262 | }
|
263 |
|
264 |
|
265 |
|
266 | var leftView = monthAndYear_1.MonthAndYear.fromDate(initialMonth);
|
267 | var rightDate = value[1];
|
268 | var rightView = !props.contiguousCalendarMonths && rightDate != null && !DateUtils.areSameMonth(initialMonth, rightDate)
|
269 | ? monthAndYear_1.MonthAndYear.fromDate(rightDate)
|
270 | : leftView.getNextMonth();
|
271 | _this.state = {
|
272 | hoverValue: [null, null],
|
273 | leftView: leftView,
|
274 | rightView: rightView,
|
275 | selectedShortcutIndex: _this.props.selectedShortcutIndex !== undefined ? _this.props.selectedShortcutIndex : -1,
|
276 | time: time,
|
277 | value: value,
|
278 | };
|
279 | return _this;
|
280 | }
|
281 | DateRangePicker.prototype.render = function () {
|
282 | var _a;
|
283 | var _b = this.props, className = _b.className, contiguousCalendarMonths = _b.contiguousCalendarMonths, singleMonthOnly = _b.singleMonthOnly, footerElement = _b.footerElement;
|
284 | var isShowingOneMonth = singleMonthOnly || DateUtils.areSameMonth(this.props.minDate, this.props.maxDate);
|
285 | var classes = (0, classnames_1.default)(DateClasses.DATEPICKER, DateClasses.DATERANGEPICKER, className, (_a = {},
|
286 | _a[DateClasses.DATERANGEPICKER_CONTIGUOUS] = contiguousCalendarMonths,
|
287 | _a[DateClasses.DATERANGEPICKER_SINGLE_MONTH] = isShowingOneMonth,
|
288 | _a));
|
289 |
|
290 | return (React.createElement("div", { className: classes },
|
291 | this.maybeRenderShortcuts(),
|
292 | React.createElement("div", { className: DateClasses.DATEPICKER_CONTENT },
|
293 | this.renderCalendars(isShowingOneMonth),
|
294 | this.maybeRenderTimePickers(isShowingOneMonth),
|
295 | footerElement)));
|
296 | };
|
297 | DateRangePicker.prototype.componentDidUpdate = function (prevProps, prevState) {
|
298 | _super.prototype.componentDidUpdate.call(this, prevProps, prevState);
|
299 | if (!DateUtils.areRangesEqual(prevProps.value, this.props.value) ||
|
300 | prevProps.contiguousCalendarMonths !== this.props.contiguousCalendarMonths) {
|
301 | var nextState = getStateChange(prevProps.value, this.props.value, this.state, prevProps.contiguousCalendarMonths);
|
302 | this.setState(nextState);
|
303 | }
|
304 | if (this.props.selectedShortcutIndex !== prevProps.selectedShortcutIndex) {
|
305 | this.setState({ selectedShortcutIndex: this.props.selectedShortcutIndex });
|
306 | }
|
307 | };
|
308 | DateRangePicker.prototype.validateProps = function (props) {
|
309 | var defaultValue = props.defaultValue, initialMonth = props.initialMonth, maxDate = props.maxDate, minDate = props.minDate, boundaryToModify = props.boundaryToModify, value = props.value;
|
310 | var dateRange = [minDate, maxDate];
|
311 | if (defaultValue != null && !DateUtils.isDayRangeInRange(defaultValue, dateRange)) {
|
312 | console.error(Errors.DATERANGEPICKER_DEFAULT_VALUE_INVALID);
|
313 | }
|
314 | if (initialMonth != null && !DateUtils.isMonthInRange(initialMonth, dateRange)) {
|
315 | console.error(Errors.DATERANGEPICKER_INITIAL_MONTH_INVALID);
|
316 | }
|
317 | if (maxDate != null && minDate != null && maxDate < minDate && !DateUtils.areSameDay(maxDate, minDate)) {
|
318 | console.error(Errors.DATERANGEPICKER_MAX_DATE_INVALID);
|
319 | }
|
320 | if (value != null && !DateUtils.isDayRangeInRange(value, dateRange)) {
|
321 | console.error(Errors.DATERANGEPICKER_VALUE_INVALID);
|
322 | }
|
323 | if (boundaryToModify != null && boundaryToModify !== core_1.Boundary.START && boundaryToModify !== core_1.Boundary.END) {
|
324 | console.error(Errors.DATERANGEPICKER_PREFERRED_BOUNDARY_TO_MODIFY_INVALID);
|
325 | }
|
326 | };
|
327 | DateRangePicker.prototype.maybeRenderShortcuts = function () {
|
328 | var shortcuts = this.props.shortcuts;
|
329 | if (shortcuts == null || shortcuts === false) {
|
330 | return null;
|
331 | }
|
332 | var selectedShortcutIndex = this.state.selectedShortcutIndex;
|
333 | var _a = this.props, allowSingleDayRange = _a.allowSingleDayRange, maxDate = _a.maxDate, minDate = _a.minDate, timePrecision = _a.timePrecision;
|
334 | return [
|
335 | React.createElement(shortcuts_1.Shortcuts, tslib_1.__assign({ key: "shortcuts" }, {
|
336 | allowSingleDayRange: allowSingleDayRange,
|
337 | maxDate: maxDate,
|
338 | minDate: minDate,
|
339 | selectedShortcutIndex: selectedShortcutIndex,
|
340 | shortcuts: shortcuts,
|
341 | timePrecision: timePrecision,
|
342 | }, { onShortcutClick: this.handleShortcutClick })),
|
343 | React.createElement(core_1.Divider, { key: "div" }),
|
344 | ];
|
345 | };
|
346 | DateRangePicker.prototype.maybeRenderTimePickers = function (isShowingOneMonth) {
|
347 | var _a = this.props, timePrecision = _a.timePrecision, timePickerProps = _a.timePickerProps;
|
348 | if (timePrecision == null && timePickerProps === DateRangePicker.defaultProps.timePickerProps) {
|
349 | return null;
|
350 | }
|
351 | if (isShowingOneMonth) {
|
352 | return (React.createElement(timePicker_1.TimePicker, tslib_1.__assign({ precision: timePrecision }, timePickerProps, { onChange: this.handleTimeChangeLeftCalendar, value: this.state.time[0] })));
|
353 | }
|
354 | else {
|
355 | return (React.createElement("div", { className: DateClasses.DATERANGEPICKER_TIMEPICKERS },
|
356 | React.createElement(timePicker_1.TimePicker, tslib_1.__assign({ precision: timePrecision }, timePickerProps, { onChange: this.handleTimeChangeLeftCalendar, value: this.state.time[0] })),
|
357 | React.createElement(timePicker_1.TimePicker, tslib_1.__assign({ precision: timePrecision }, timePickerProps, { onChange: this.handleTimeChangeRightCalendar, value: this.state.time[1] }))));
|
358 | }
|
359 | };
|
360 | DateRangePicker.prototype.renderCalendars = function (isShowingOneMonth) {
|
361 | var _a, _b, _c;
|
362 | var _d = this.props, dayPickerProps = _d.dayPickerProps, locale = _d.locale, localeUtils = _d.localeUtils, maxDate = _d.maxDate, minDate = _d.minDate;
|
363 | var dayPickerBaseProps = tslib_1.__assign(tslib_1.__assign({ locale: locale, localeUtils: localeUtils, modifiers: this.getDateRangePickerModifiers(), showOutsideDays: true }, dayPickerProps), { disabledDays: this.getDisabledDaysModifier(), onDayClick: this.handleDayClick, onDayMouseEnter: this.handleDayMouseEnter, onDayMouseLeave: this.handleDayMouseLeave, selectedDays: this.state.value });
|
364 | if (isShowingOneMonth) {
|
365 | return (React.createElement(react_day_picker_1.default, tslib_1.__assign({}, dayPickerBaseProps, { captionElement: this.renderSingleCaption, navbarElement: this.renderSingleNavbar, fromMonth: minDate, month: this.state.leftView.getFullDate(), numberOfMonths: 1, onMonthChange: this.handleLeftMonthChange, toMonth: maxDate, renderDay: (_a = dayPickerProps === null || dayPickerProps === void 0 ? void 0 : dayPickerProps.renderDay) !== null && _a !== void 0 ? _a : this.renderDay })));
|
366 | }
|
367 | else {
|
368 | return (React.createElement("div", { className: DateClasses.DATERANGEPICKER_CALENDARS },
|
369 | React.createElement(react_day_picker_1.default, tslib_1.__assign({ key: "left" }, dayPickerBaseProps, { canChangeMonth: true, captionElement: this.renderLeftCaption, navbarElement: this.renderLeftNavbar, fromMonth: minDate, month: this.state.leftView.getFullDate(), numberOfMonths: 1, onMonthChange: this.handleLeftMonthChange, toMonth: DateUtils.getDatePreviousMonth(maxDate), renderDay: (_b = dayPickerProps === null || dayPickerProps === void 0 ? void 0 : dayPickerProps.renderDay) !== null && _b !== void 0 ? _b : this.renderDay })),
|
370 | React.createElement(react_day_picker_1.default, tslib_1.__assign({ key: "right" }, dayPickerBaseProps, { canChangeMonth: true, captionElement: this.renderRightCaption, navbarElement: this.renderRightNavbar, fromMonth: DateUtils.getDateNextMonth(minDate), month: this.state.rightView.getFullDate(), numberOfMonths: 1, onMonthChange: this.handleRightMonthChange, toMonth: maxDate, renderDay: (_c = dayPickerProps === null || dayPickerProps === void 0 ? void 0 : dayPickerProps.renderDay) !== null && _c !== void 0 ? _c : this.renderDay }))));
|
371 | }
|
372 | };
|
373 | DateRangePicker.prototype.updateLeftView = function (leftView) {
|
374 | var rightView = this.state.rightView.clone();
|
375 | if (!leftView.isBefore(rightView) || this.props.contiguousCalendarMonths) {
|
376 | rightView = leftView.getNextMonth();
|
377 | }
|
378 | this.setViews(leftView, rightView);
|
379 | };
|
380 | DateRangePicker.prototype.updateRightView = function (rightView) {
|
381 | var leftView = this.state.leftView.clone();
|
382 | if (!rightView.isAfter(leftView) || this.props.contiguousCalendarMonths) {
|
383 | leftView = rightView.getPreviousMonth();
|
384 | }
|
385 | this.setViews(leftView, rightView);
|
386 | };
|
387 | DateRangePicker.prototype.setViews = function (leftView, rightView) {
|
388 | this.setState({ leftView: leftView, rightView: rightView });
|
389 | };
|
390 | DateRangePicker.defaultProps = {
|
391 | allowSingleDayRange: false,
|
392 | contiguousCalendarMonths: true,
|
393 | dayPickerProps: {},
|
394 | maxDate: (0, datePickerCore_1.getDefaultMaxDate)(),
|
395 | minDate: (0, datePickerCore_1.getDefaultMinDate)(),
|
396 | reverseMonthAndYearMenus: false,
|
397 | shortcuts: true,
|
398 | singleMonthOnly: false,
|
399 | timePickerProps: {},
|
400 | };
|
401 | DateRangePicker.displayName = "".concat(core_1.DISPLAYNAME_PREFIX, ".DateRangePicker");
|
402 | return DateRangePicker;
|
403 | }(core_1.AbstractPureComponent2));
|
404 | exports.DateRangePicker = DateRangePicker;
|
405 | function getStateChange(value, nextValue, state, contiguousCalendarMonths) {
|
406 | if (value != null && nextValue == null) {
|
407 | return { value: [null, null] };
|
408 | }
|
409 | else if (nextValue != null) {
|
410 | var leftView = state.leftView.clone();
|
411 | var rightView = state.rightView.clone();
|
412 | var nextValueStartView = monthAndYear_1.MonthAndYear.fromDate(nextValue[0]);
|
413 | var nextValueEndView = monthAndYear_1.MonthAndYear.fromDate(nextValue[1]);
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | if (nextValueStartView == null && nextValueEndView != null) {
|
419 | if (!nextValueEndView.isSame(leftView) && !nextValueEndView.isSame(rightView)) {
|
420 | rightView = nextValueEndView;
|
421 | if (!leftView.isBefore(rightView)) {
|
422 | leftView = rightView.getPreviousMonth();
|
423 | }
|
424 | }
|
425 | }
|
426 | else if (nextValueStartView != null && nextValueEndView == null) {
|
427 |
|
428 |
|
429 |
|
430 |
|
431 | if (!nextValueStartView.isSame(leftView) && !nextValueStartView.isSame(rightView)) {
|
432 | leftView = nextValueStartView;
|
433 | if (!rightView.isAfter(leftView)) {
|
434 | rightView = leftView.getNextMonth();
|
435 | }
|
436 | }
|
437 | }
|
438 | else if (nextValueStartView != null && nextValueEndView != null) {
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | if (nextValueStartView.isSame(nextValueEndView)) {
|
444 | if (leftView.isSame(nextValueStartView) || rightView.isSame(nextValueStartView)) {
|
445 |
|
446 | }
|
447 | else {
|
448 | leftView = nextValueStartView;
|
449 | rightView = nextValueStartView.getNextMonth();
|
450 | }
|
451 | }
|
452 | else {
|
453 |
|
454 | if (!leftView.isSame(nextValueStartView)) {
|
455 | leftView = nextValueStartView;
|
456 | rightView = nextValueStartView.getNextMonth();
|
457 | }
|
458 | if (contiguousCalendarMonths === false && !rightView.isSame(nextValueEndView)) {
|
459 | rightView = nextValueEndView;
|
460 | }
|
461 | }
|
462 | }
|
463 | return {
|
464 | leftView: leftView,
|
465 | rightView: rightView,
|
466 | value: nextValue,
|
467 | };
|
468 | }
|
469 | else if (contiguousCalendarMonths === true) {
|
470 |
|
471 |
|
472 | if (!state.leftView.getNextMonth().isSameMonth(state.rightView)) {
|
473 | var nextRightView = state.leftView.getNextMonth();
|
474 | return { rightView: nextRightView };
|
475 | }
|
476 | }
|
477 | return {};
|
478 | }
|
479 | function getInitialValue(props) {
|
480 | if (props.value != null) {
|
481 | return props.value;
|
482 | }
|
483 | if (props.defaultValue != null) {
|
484 | return props.defaultValue;
|
485 | }
|
486 | return [null, null];
|
487 | }
|
488 | function getInitialMonth(props, value) {
|
489 | var today = new Date();
|
490 |
|
491 | if (props.initialMonth != null) {
|
492 | return props.initialMonth;
|
493 | }
|
494 | else if (value[0] != null) {
|
495 | return DateUtils.clone(value[0]);
|
496 | }
|
497 | else if (value[1] != null) {
|
498 | var month = DateUtils.clone(value[1]);
|
499 | if (!DateUtils.areSameMonth(month, props.minDate)) {
|
500 | month.setMonth(month.getMonth() - 1);
|
501 | }
|
502 | return month;
|
503 | }
|
504 | else if (DateUtils.isDayInRange(today, [props.minDate, props.maxDate])) {
|
505 | return today;
|
506 | }
|
507 | else {
|
508 | return DateUtils.getDateBetween([props.minDate, props.maxDate]);
|
509 | }
|
510 | }
|
511 |
|
\ | No newline at end of file |