@elliemae/ds-date-range-picker 2.1.0 → 2.2.0-alpha.3
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 +199 -193
- package/cjs/DSDateRangePicker.js.map +7 -0
- package/cjs/components/DSDateRangePickerImpl.js +172 -222
- package/cjs/components/DSDateRangePickerImpl.js.map +7 -0
- package/cjs/components/DatePickerLabel/DatePickerLabel.js +38 -19
- package/cjs/components/DatePickerLabel/DatePickerLabel.js.map +7 -0
- package/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js +74 -62
- package/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +7 -0
- package/cjs/components/DayPickerRangeController.js +123 -109
- package/cjs/components/DayPickerRangeController.js.map +7 -0
- package/cjs/index.js +36 -15
- package/cjs/index.js.map +7 -0
- package/cjs/isMaxDiffSafe.js +39 -13
- package/cjs/isMaxDiffSafe.js.map +7 -0
- package/esm/DSDateRangePicker.js +143 -150
- package/esm/DSDateRangePicker.js.map +7 -0
- package/esm/components/DSDateRangePickerImpl.js +131 -197
- package/esm/components/DSDateRangePickerImpl.js.map +7 -0
- package/esm/components/DatePickerLabel/DatePickerLabel.js +9 -13
- package/esm/components/DatePickerLabel/DatePickerLabel.js.map +7 -0
- package/esm/components/DatePickerRangeHeader/DatePickerRangeHeader.js +36 -45
- package/esm/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +7 -0
- package/esm/components/DayPickerRangeController.js +92 -99
- package/esm/components/DayPickerRangeController.js.map +7 -0
- package/esm/index.js +7 -3
- package/esm/index.js.map +7 -0
- package/esm/isMaxDiffSafe.js +10 -8
- package/esm/isMaxDiffSafe.js.map +7 -0
- package/package.json +6 -6
|
@@ -1,40 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
const START_DATE =
|
|
12
|
-
const END_DATE =
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
classNameBlock
|
|
16
|
-
} = convertPropToCssClassName('datepicker');
|
|
17
|
-
class DSDateRangePickerImpl extends React.Component {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import moment from "moment";
|
|
5
|
+
import { convertPropToCssClassName } from "@elliemae/ds-classnames";
|
|
6
|
+
import { MASK_TYPES, MASK_PIPES, DSFormItemLayout, DSInputMask } from "@elliemae/ds-form";
|
|
7
|
+
import DSPopper from "@elliemae/ds-popper";
|
|
8
|
+
import { DatePickerPicker, renderMonthElement } from "@elliemae/ds-date-picker";
|
|
9
|
+
import DayPickerRangeController from "./DayPickerRangeController";
|
|
10
|
+
import { isMaxDiffSafe } from "../isMaxDiffSafe";
|
|
11
|
+
const START_DATE = "startDate";
|
|
12
|
+
const END_DATE = "endDate";
|
|
13
|
+
const { classNameElement, classNameBlock } = convertPropToCssClassName("datepicker");
|
|
14
|
+
class DSDateRangePickerImpl extends React2.Component {
|
|
18
15
|
constructor(props) {
|
|
19
16
|
super(props);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let {
|
|
23
|
-
startDate,
|
|
24
|
-
endDate
|
|
25
|
-
} = _ref;
|
|
26
|
-
const {
|
|
27
|
-
onDatesChange
|
|
28
|
-
} = this.props;
|
|
17
|
+
this.onDatesChange = ({ startDate, endDate }) => {
|
|
18
|
+
const { onDatesChange } = this.props;
|
|
29
19
|
onDatesChange(startDate, endDate);
|
|
30
20
|
const safe = isMaxDiffSafe(startDate, endDate, this.state.startDate, this.state.endDate);
|
|
31
|
-
|
|
32
21
|
if (!safe) {
|
|
33
|
-
this.setState({
|
|
34
|
-
showPicker: false
|
|
35
|
-
});
|
|
22
|
+
this.setState({ showPicker: false });
|
|
36
23
|
}
|
|
37
|
-
|
|
38
24
|
this.setState({
|
|
39
25
|
startDate,
|
|
40
26
|
endDate,
|
|
@@ -42,85 +28,55 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
42
28
|
primaryEndInput: false
|
|
43
29
|
});
|
|
44
30
|
};
|
|
45
|
-
|
|
46
31
|
this.onFocusChange = () => {
|
|
47
|
-
this.setState(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = _ref2;
|
|
51
|
-
return {
|
|
52
|
-
focusedInput: focusedInput === START_DATE ? END_DATE : START_DATE
|
|
53
|
-
};
|
|
54
|
-
});
|
|
32
|
+
this.setState(({ focusedInput }) => ({
|
|
33
|
+
focusedInput: focusedInput === START_DATE ? END_DATE : START_DATE
|
|
34
|
+
}));
|
|
55
35
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
showPicker: false
|
|
60
|
-
});
|
|
36
|
+
this.handleKeyDown = (event) => {
|
|
37
|
+
if (event.key === "Escape")
|
|
38
|
+
this.setState({ showPicker: false });
|
|
61
39
|
};
|
|
62
|
-
|
|
63
40
|
this.getSafeStartInputValue = () => {
|
|
64
|
-
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!startDate) return '';
|
|
71
|
-
return startDate.format('MMDDYYYY');
|
|
41
|
+
const { startInput, primaryStartInput, startDate } = this.state;
|
|
42
|
+
if (primaryStartInput && startInput)
|
|
43
|
+
return startInput;
|
|
44
|
+
if (!startDate)
|
|
45
|
+
return "";
|
|
46
|
+
return startDate.format("MMDDYYYY");
|
|
72
47
|
};
|
|
73
|
-
|
|
74
48
|
this.getSafeEndInputValue = () => {
|
|
75
|
-
const {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!endDate) return '';
|
|
82
|
-
return endDate.format('MMDDYYYY');
|
|
49
|
+
const { endInput, primaryEndInput, endDate } = this.state;
|
|
50
|
+
if (primaryEndInput && endInput)
|
|
51
|
+
return endInput;
|
|
52
|
+
if (!endDate)
|
|
53
|
+
return "";
|
|
54
|
+
return endDate.format("MMDDYYYY");
|
|
83
55
|
};
|
|
84
|
-
|
|
85
56
|
this.changeFocus = () => {
|
|
86
|
-
const {
|
|
87
|
-
disabled
|
|
88
|
-
} = this.props;
|
|
89
|
-
|
|
57
|
+
const { disabled } = this.props;
|
|
90
58
|
if (!disabled) {
|
|
91
|
-
this.setState(() => ({
|
|
92
|
-
focusedInput: 'startDate'
|
|
93
|
-
}));
|
|
59
|
+
this.setState(() => ({ focusedInput: "startDate" }));
|
|
94
60
|
}
|
|
95
61
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const {
|
|
101
|
-
onChangeStartInput,
|
|
102
|
-
isDayBlocked,
|
|
103
|
-
minimumNights
|
|
104
|
-
} = this.props;
|
|
105
|
-
const {
|
|
106
|
-
endDate
|
|
107
|
-
} = this.state;
|
|
62
|
+
this.handleChangeStart = (e) => {
|
|
63
|
+
const { onChangeStartInput, isDayBlocked, minimumNights } = this.props;
|
|
64
|
+
const { endDate } = this.state;
|
|
108
65
|
const startInputVal = e.target.value;
|
|
109
66
|
let momentValue = null;
|
|
110
|
-
|
|
111
|
-
if (startInputVal && moment(startInputVal, 'MM/DD/YYYY', true).isValid()) {
|
|
67
|
+
if (startInputVal && moment(startInputVal, "MM/DD/YYYY", true).isValid()) {
|
|
112
68
|
momentValue = moment(startInputVal);
|
|
113
69
|
}
|
|
114
|
-
|
|
115
70
|
const startDateBlocked = isDayBlocked(momentValue);
|
|
116
|
-
const isStartDateAcceptable = !startDateBlocked && momentValue && startInputVal !==
|
|
117
|
-
const areDatesValid = endDate && momentValue &&
|
|
71
|
+
const isStartDateAcceptable = !startDateBlocked && momentValue && startInputVal !== "";
|
|
72
|
+
const areDatesValid = endDate && momentValue && endDate?.isValid() && momentValue?.isValid();
|
|
118
73
|
const canEndBeSameAsStart = minimumNights === 0;
|
|
119
|
-
const isStartAcceptableWithSelectedEnd = !endDate || areDatesValid && (canEndBeSameAsStart && momentValue.diff(endDate,
|
|
74
|
+
const isStartAcceptableWithSelectedEnd = !endDate || areDatesValid && (canEndBeSameAsStart && momentValue.diff(endDate, "days") <= 0 || !canEndBeSameAsStart && momentValue.diff(endDate, "days") < 0);
|
|
120
75
|
const invalidDate = !isStartDateAcceptable || !isStartAcceptableWithSelectedEnd;
|
|
121
|
-
if (startDateBlocked)
|
|
76
|
+
if (startDateBlocked)
|
|
77
|
+
momentValue = null;
|
|
122
78
|
onChangeStartInput(momentValue);
|
|
123
|
-
this.setState(prevState => ({
|
|
79
|
+
this.setState((prevState) => ({
|
|
124
80
|
startDate: momentValue,
|
|
125
81
|
startInput: startInputVal,
|
|
126
82
|
primaryStartInput: true,
|
|
@@ -128,38 +84,24 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
128
84
|
endDateError: !isStartDateAcceptable || !prevState.endDateError ? prevState.endDateError : !isStartAcceptableWithSelectedEnd
|
|
129
85
|
}));
|
|
130
86
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const {
|
|
136
|
-
onChangeEndInput,
|
|
137
|
-
isDayBlocked,
|
|
138
|
-
minimumNights
|
|
139
|
-
} = this.props;
|
|
140
|
-
const {
|
|
141
|
-
startDate
|
|
142
|
-
} = this.state;
|
|
87
|
+
this.handleChangeEnd = (e) => {
|
|
88
|
+
const { onChangeEndInput, isDayBlocked, minimumNights } = this.props;
|
|
89
|
+
const { startDate } = this.state;
|
|
143
90
|
const endInputValue = e.target.value;
|
|
144
91
|
let momentValue = null;
|
|
145
|
-
|
|
146
|
-
if (endInputValue && moment(endInputValue, 'MM/DD/YYYY', true).isValid()) {
|
|
92
|
+
if (endInputValue && moment(endInputValue, "MM/DD/YYYY", true).isValid()) {
|
|
147
93
|
momentValue = moment(endInputValue);
|
|
148
94
|
}
|
|
149
|
-
|
|
150
95
|
const endDateBlocked = isDayBlocked(momentValue);
|
|
151
|
-
const isEndDateAcceptable = !endDateBlocked && momentValue && endInputValue !==
|
|
152
|
-
const areDatesValid = startDate && momentValue &&
|
|
96
|
+
const isEndDateAcceptable = !endDateBlocked && momentValue && endInputValue !== "";
|
|
97
|
+
const areDatesValid = startDate && momentValue && startDate?.isValid() && momentValue?.isValid();
|
|
153
98
|
const canEndBeSameAsStart = minimumNights === 0;
|
|
154
|
-
const isEndAcceptableWithSelectedStart = !startDate ||
|
|
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
|
-
|
|
99
|
+
const isEndAcceptableWithSelectedStart = !startDate || areDatesValid && (canEndBeSameAsStart && momentValue.diff(startDate, "days") >= 0 || !canEndBeSameAsStart && momentValue.diff(startDate, "days") > 0);
|
|
159
100
|
const invalidDate = !isEndDateAcceptable || !isEndAcceptableWithSelectedStart;
|
|
160
|
-
if (endDateBlocked)
|
|
101
|
+
if (endDateBlocked)
|
|
102
|
+
momentValue = null;
|
|
161
103
|
onChangeEndInput(momentValue);
|
|
162
|
-
this.setState(prevState => ({
|
|
104
|
+
this.setState((prevState) => ({
|
|
163
105
|
endDate: momentValue,
|
|
164
106
|
endInput: endInputValue,
|
|
165
107
|
primaryEndInput: true,
|
|
@@ -167,13 +109,7 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
167
109
|
endDateError: invalidDate
|
|
168
110
|
}));
|
|
169
111
|
};
|
|
170
|
-
|
|
171
|
-
this.handleChangeDate = _ref3 => {
|
|
172
|
-
let {
|
|
173
|
-
startDate: _start,
|
|
174
|
-
endDate
|
|
175
|
-
} = _ref3;
|
|
176
|
-
|
|
112
|
+
this.handleChangeDate = ({ startDate: _start, endDate }) => {
|
|
177
113
|
if (_start && endDate) {
|
|
178
114
|
this.setState({
|
|
179
115
|
startDate: moment(_start),
|
|
@@ -182,18 +118,11 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
182
118
|
primaryEndInput: false
|
|
183
119
|
});
|
|
184
120
|
} else if (_start) {
|
|
185
|
-
this.setState({
|
|
186
|
-
startDate: moment(_start),
|
|
187
|
-
primaryStartInput: false
|
|
188
|
-
});
|
|
121
|
+
this.setState({ startDate: moment(_start), primaryStartInput: false });
|
|
189
122
|
} else if (endDate) {
|
|
190
|
-
this.setState({
|
|
191
|
-
endDate,
|
|
192
|
-
primaryEndInput: false
|
|
193
|
-
});
|
|
123
|
+
this.setState({ endDate, primaryEndInput: false });
|
|
194
124
|
}
|
|
195
125
|
};
|
|
196
|
-
|
|
197
126
|
this.state = {
|
|
198
127
|
startDate: props.startDate ? moment(props.startDate) : null,
|
|
199
128
|
endDate: props.endDate ? moment(props.endDate) : null,
|
|
@@ -203,24 +132,14 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
203
132
|
endDateError: false
|
|
204
133
|
};
|
|
205
134
|
}
|
|
206
|
-
|
|
207
135
|
componentDidMount() {
|
|
208
|
-
document.addEventListener(
|
|
136
|
+
document.addEventListener("keydown", this.handleKeyDown, false);
|
|
209
137
|
}
|
|
210
|
-
|
|
211
138
|
componentWillUnmount() {
|
|
212
|
-
document.removeEventListener(
|
|
139
|
+
document.removeEventListener("keydown", this.handleKeyDown, false);
|
|
213
140
|
}
|
|
214
|
-
|
|
215
141
|
render() {
|
|
216
|
-
const {
|
|
217
|
-
startDate,
|
|
218
|
-
endDate,
|
|
219
|
-
focusedInput,
|
|
220
|
-
showPicker,
|
|
221
|
-
startDateError,
|
|
222
|
-
endDateError
|
|
223
|
-
} = this.state;
|
|
142
|
+
const { startDate, endDate, focusedInput, showPicker, startDateError, endDateError } = this.state;
|
|
224
143
|
const {
|
|
225
144
|
disabled,
|
|
226
145
|
displayFormatDay,
|
|
@@ -240,91 +159,106 @@ class DSDateRangePickerImpl extends React.Component {
|
|
|
240
159
|
hasError,
|
|
241
160
|
validationMessage
|
|
242
161
|
} = this.props;
|
|
243
|
-
const inputClass = classNameBlock(
|
|
244
|
-
const inputClassModifier =
|
|
162
|
+
const inputClass = classNameBlock("inputs", "range-picker");
|
|
163
|
+
const inputClassModifier = "";
|
|
245
164
|
const safeStartInputValue = this.getSafeStartInputValue();
|
|
246
165
|
const safeEndInputValue = this.getSafeEndInputValue();
|
|
247
|
-
return
|
|
248
|
-
className:
|
|
249
|
-
},
|
|
250
|
-
className: classNameBlock(
|
|
251
|
-
},
|
|
166
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
167
|
+
className: `${inputClass} ${inputClassModifier}`
|
|
168
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
169
|
+
className: classNameBlock("wrapper-input-date-range-picker-controller")
|
|
170
|
+
}, /* @__PURE__ */ React2.createElement(DSFormItemLayout, {
|
|
252
171
|
floatingLabel: true,
|
|
253
172
|
inputComponent: DSInputMask,
|
|
254
173
|
labelText: labelFrom,
|
|
255
174
|
mask: MASK_TYPES.DATE,
|
|
256
175
|
onChange: this.handleChangeStart,
|
|
257
|
-
onFocus: () => this.setState({
|
|
258
|
-
showPicker: false
|
|
259
|
-
}),
|
|
176
|
+
onFocus: () => this.setState({ showPicker: false }),
|
|
260
177
|
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
261
178
|
value: safeStartInputValue,
|
|
262
179
|
required: startDateRequired,
|
|
263
180
|
hasError: hasError || startDateError,
|
|
264
181
|
placeholder: "MM/DD/YYYY"
|
|
265
|
-
}),
|
|
182
|
+
}), /* @__PURE__ */ React2.createElement(DSFormItemLayout, {
|
|
266
183
|
floatingLabel: true,
|
|
267
184
|
inputComponent: DSInputMask,
|
|
268
185
|
labelText: labelTo,
|
|
269
186
|
mask: MASK_TYPES.DATE,
|
|
270
187
|
onChange: this.handleChangeEnd,
|
|
271
|
-
onFocus: () => this.setState({
|
|
272
|
-
showPicker: false
|
|
273
|
-
}),
|
|
188
|
+
onFocus: () => this.setState({ showPicker: false }),
|
|
274
189
|
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
275
190
|
value: safeEndInputValue,
|
|
276
191
|
required: endDateRequired,
|
|
277
192
|
hasError: hasError || endDateError,
|
|
278
|
-
validationMessage
|
|
193
|
+
validationMessage,
|
|
279
194
|
placeholder: "MM/DD/YYYY"
|
|
280
|
-
})),
|
|
281
|
-
className: classNameBlock(
|
|
282
|
-
},
|
|
283
|
-
contentComponent:
|
|
284
|
-
enableOutsideDays
|
|
285
|
-
isDayBlocked
|
|
286
|
-
isDayHighlighted
|
|
287
|
-
isOutsideRange
|
|
288
|
-
displayFormatDay
|
|
289
|
-
endDate
|
|
290
|
-
focusedInput
|
|
195
|
+
})), /* @__PURE__ */ React2.createElement("div", {
|
|
196
|
+
className: classNameBlock("wrapper-button-date-range-picker-controller")
|
|
197
|
+
}, /* @__PURE__ */ React2.createElement(DSPopper, {
|
|
198
|
+
contentComponent: /* @__PURE__ */ React2.createElement("div", null, showPicker && /* @__PURE__ */ React2.createElement(DayPickerRangeController, {
|
|
199
|
+
enableOutsideDays,
|
|
200
|
+
isDayBlocked,
|
|
201
|
+
isDayHighlighted,
|
|
202
|
+
isOutsideRange,
|
|
203
|
+
displayFormatDay,
|
|
204
|
+
endDate,
|
|
205
|
+
focusedInput,
|
|
291
206
|
hideKeyboardShortcutsPanel: true,
|
|
292
|
-
minimumNights
|
|
207
|
+
minimumNights,
|
|
293
208
|
onDatesChange: this.onDatesChange,
|
|
294
209
|
onFocusChange: this.onFocusChange,
|
|
295
|
-
onOutsideClick: e => {
|
|
210
|
+
onOutsideClick: (e) => {
|
|
296
211
|
onOutsideClick(e);
|
|
297
|
-
this.setState({
|
|
298
|
-
showPicker: false
|
|
299
|
-
});
|
|
212
|
+
this.setState({ showPicker: false });
|
|
300
213
|
},
|
|
301
|
-
onNextMonthClick
|
|
302
|
-
onPrevMonthClick
|
|
303
|
-
startDate
|
|
304
|
-
renderMonthElement
|
|
214
|
+
onNextMonthClick,
|
|
215
|
+
onPrevMonthClick,
|
|
216
|
+
startDate,
|
|
217
|
+
renderMonthElement
|
|
305
218
|
})),
|
|
306
219
|
isOpen: showPicker && !startDateError && !endDateError,
|
|
307
|
-
onClose
|
|
220
|
+
onClose,
|
|
308
221
|
placement: "bottom-end",
|
|
309
222
|
showArrow: false,
|
|
310
|
-
triggerComponent:
|
|
311
|
-
onFocus: () => this.setState({
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
showPicker: true
|
|
319
|
-
})
|
|
320
|
-
}), hasError && validationMessage && /*#__PURE__*/_jsx("div", {
|
|
321
|
-
style: {
|
|
322
|
-
height: 15
|
|
323
|
-
}
|
|
223
|
+
triggerComponent: /* @__PURE__ */ React2.createElement("div", {
|
|
224
|
+
onFocus: () => this.setState({ showPicker: true })
|
|
225
|
+
}, /* @__PURE__ */ React2.createElement(DatePickerPicker, {
|
|
226
|
+
className: classNameElement("picker"),
|
|
227
|
+
disabled,
|
|
228
|
+
onClick: () => this.setState({ showPicker: true })
|
|
229
|
+
}), hasError && validationMessage && /* @__PURE__ */ React2.createElement("div", {
|
|
230
|
+
style: { height: 15 }
|
|
324
231
|
}))
|
|
325
232
|
})));
|
|
326
233
|
}
|
|
327
|
-
|
|
328
234
|
}
|
|
329
|
-
|
|
330
|
-
|
|
235
|
+
DSDateRangePickerImpl.propTypes = {
|
|
236
|
+
startDate: PropTypes.instanceOf(Date, moment),
|
|
237
|
+
endDate: PropTypes.instanceOf(Date, moment),
|
|
238
|
+
onDatesChange: PropTypes.func,
|
|
239
|
+
onChangeStartInput: PropTypes.func,
|
|
240
|
+
onChangeEndInput: PropTypes.func,
|
|
241
|
+
onNextMonthClick: PropTypes.func,
|
|
242
|
+
onPrevMonthClick: PropTypes.func,
|
|
243
|
+
onClose: PropTypes.func,
|
|
244
|
+
onOutsideClick: PropTypes.func,
|
|
245
|
+
disabled: PropTypes.bool,
|
|
246
|
+
displayFormatDay: PropTypes.string,
|
|
247
|
+
minimumNights: PropTypes.number,
|
|
248
|
+
labelTo: PropTypes.string,
|
|
249
|
+
labelFrom: PropTypes.string,
|
|
250
|
+
isDayBlocked: PropTypes.func,
|
|
251
|
+
isDayHighlighted: PropTypes.func,
|
|
252
|
+
isOutsideRange: PropTypes.func,
|
|
253
|
+
enableOutsideDays: PropTypes.bool,
|
|
254
|
+
startDateRequired: PropTypes.bool,
|
|
255
|
+
endDateRequired: PropTypes.bool,
|
|
256
|
+
hasError: PropTypes.bool,
|
|
257
|
+
validationMessage: PropTypes.string
|
|
258
|
+
};
|
|
259
|
+
export {
|
|
260
|
+
END_DATE,
|
|
261
|
+
START_DATE,
|
|
262
|
+
DSDateRangePickerImpl as default
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=DSDateRangePickerImpl.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/components/DSDateRangePickerImpl.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable import/no-unresolved */\n/* eslint-disable max-lines */\nimport React from 'react';\nimport PropTypes from 'prop-types';\nimport moment from 'moment';\nimport { convertPropToCssClassName } from '@elliemae/ds-classnames';\nimport { MASK_TYPES, MASK_PIPES, DSFormItemLayout, DSInputMask } from '@elliemae/ds-form';\nimport DSPopper from '@elliemae/ds-popper';\nimport { DatePickerPicker, renderMonthElement } from '@elliemae/ds-date-picker';\nimport DayPickerRangeController from './DayPickerRangeController';\nimport { isMaxDiffSafe } from '../isMaxDiffSafe';\n\nexport const START_DATE = 'startDate';\nexport const END_DATE = 'endDate';\n\nconst { classNameElement, classNameBlock } = convertPropToCssClassName('datepicker');\n\nexport default class DSDateRangePickerImpl extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n startDate: props.startDate ? moment(props.startDate) : null,\n endDate: props.endDate ? moment(props.endDate) : null,\n focusedInput: START_DATE,\n showPicker: false,\n startDateError: false,\n endDateError: false,\n };\n }\n\n componentDidMount() {\n document.addEventListener('keydown', this.handleKeyDown, false);\n }\n\n componentWillUnmount() {\n document.removeEventListener('keydown', this.handleKeyDown, false);\n }\n\n onDatesChange = ({ startDate, endDate }) => {\n const { onDatesChange } = this.props;\n onDatesChange(startDate, endDate);\n const safe = isMaxDiffSafe(startDate, endDate, this.state.startDate, this.state.endDate);\n if (!safe) {\n this.setState({ showPicker: false });\n }\n this.setState({\n startDate,\n endDate,\n primaryStartInput: false,\n primaryEndInput: false,\n });\n };\n\n onFocusChange = () => {\n this.setState(({ focusedInput }) => ({\n focusedInput: focusedInput === START_DATE ? END_DATE : START_DATE,\n }));\n };\n\n handleKeyDown = (event) => {\n if (event.key === 'Escape') this.setState({ showPicker: false });\n };\n\n getSafeStartInputValue = () => {\n const { startInput, primaryStartInput, startDate } = this.state;\n if (primaryStartInput && startInput) return startInput;\n if (!startDate) return '';\n return startDate.format('MMDDYYYY');\n };\n\n getSafeEndInputValue = () => {\n const { endInput, primaryEndInput, endDate } = this.state;\n if (primaryEndInput && endInput) return endInput;\n if (!endDate) return '';\n return endDate.format('MMDDYYYY');\n };\n\n changeFocus = () => {\n const { disabled } = this.props;\n if (!disabled) {\n this.setState(() => ({ focusedInput: 'startDate' }));\n }\n };\n\n handleChangeStart = (e) => {\n const { onChangeStartInput, isDayBlocked, minimumNights } = this.props;\n const { endDate } = this.state;\n const startInputVal = e.target.value;\n let momentValue = null;\n if (startInputVal && moment(startInputVal, 'MM/DD/YYYY', true).isValid()) {\n momentValue = moment(startInputVal);\n }\n\n const startDateBlocked = isDayBlocked(momentValue);\n\n const isStartDateAcceptable = !startDateBlocked && momentValue && startInputVal !== '';\n const areDatesValid = endDate && momentValue && endDate?.isValid() && momentValue?.isValid();\n\n const canEndBeSameAsStart = minimumNights === 0;\n const isStartAcceptableWithSelectedEnd =\n !endDate ||\n (areDatesValid &&\n ((canEndBeSameAsStart && momentValue.diff(endDate, 'days') <= 0) ||\n (!canEndBeSameAsStart && momentValue.diff(endDate, 'days') < 0)));\n\n const invalidDate = !isStartDateAcceptable || !isStartAcceptableWithSelectedEnd;\n if (startDateBlocked) momentValue = null;\n onChangeStartInput(momentValue);\n this.setState((prevState: { endDateError: boolean }) => ({\n startDate: momentValue,\n startInput: startInputVal,\n primaryStartInput: true,\n startDateError: invalidDate,\n endDateError:\n !isStartDateAcceptable || !prevState.endDateError ? prevState.endDateError : !isStartAcceptableWithSelectedEnd,\n }));\n };\n\n handleChangeEnd = (e) => {\n const { onChangeEndInput, isDayBlocked, minimumNights } = this.props;\n const { startDate } = this.state;\n const endInputValue = e.target.value;\n let momentValue = null;\n if (endInputValue && moment(endInputValue, 'MM/DD/YYYY', true).isValid()) {\n momentValue = moment(endInputValue);\n }\n const endDateBlocked = isDayBlocked(momentValue);\n\n const isEndDateAcceptable = !endDateBlocked && momentValue && endInputValue !== '';\n const areDatesValid = startDate && momentValue && startDate?.isValid() && momentValue?.isValid();\n\n const canEndBeSameAsStart = minimumNights === 0;\n const isEndAcceptableWithSelectedStart =\n !startDate || // we can't compare with start date because it's not yet set\n (areDatesValid && // it's set and both are valid\n ((canEndBeSameAsStart && momentValue.diff(startDate, 'days') >= 0) || // >= is valid\n (!canEndBeSameAsStart && momentValue.diff(startDate, 'days') > 0))); // only > is valid\n\n const invalidDate = !isEndDateAcceptable || !isEndAcceptableWithSelectedStart;\n\n if (endDateBlocked) momentValue = null;\n onChangeEndInput(momentValue);\n this.setState((prevState: { startDateError: boolean }) => ({\n endDate: momentValue,\n endInput: endInputValue,\n primaryEndInput: true,\n startDateError:\n !isEndDateAcceptable || !prevState.startDateError\n ? prevState.startDateError\n : !isEndAcceptableWithSelectedStart,\n endDateError: invalidDate,\n }));\n };\n\n handleChangeDate = ({ startDate: _start, endDate }) => {\n if (_start && endDate) {\n this.setState({\n startDate: moment(_start),\n endDate,\n primaryStartInput: false,\n primaryEndInput: false,\n });\n } else if (_start) {\n this.setState({ startDate: moment(_start), primaryStartInput: false });\n } else if (endDate) {\n this.setState({ endDate, primaryEndInput: false });\n }\n };\n\n render() {\n const { startDate, endDate, focusedInput, showPicker, startDateError, endDateError } = this.state;\n\n const {\n disabled,\n displayFormatDay,\n minimumNights,\n labelFrom,\n labelTo,\n isDayBlocked,\n isDayHighlighted,\n isOutsideRange,\n enableOutsideDays,\n startDateRequired,\n endDateRequired,\n onOutsideClick,\n onNextMonthClick,\n onPrevMonthClick,\n onClose,\n hasError,\n validationMessage,\n } = this.props;\n\n const inputClass = classNameBlock('inputs', 'range-picker');\n const inputClassModifier = '';\n\n const safeStartInputValue = this.getSafeStartInputValue();\n const safeEndInputValue = this.getSafeEndInputValue();\n\n return (\n <div className={`${inputClass} ${inputClassModifier}`}>\n <div className={classNameBlock('wrapper-input-date-range-picker-controller')}>\n <DSFormItemLayout\n floatingLabel\n inputComponent={DSInputMask}\n labelText={labelFrom}\n mask={MASK_TYPES.DATE}\n onChange={this.handleChangeStart}\n onFocus={() => this.setState({ showPicker: false })}\n pipe={MASK_PIPES.AUTO_CORRECT_DATE}\n value={safeStartInputValue}\n required={startDateRequired}\n hasError={hasError || startDateError}\n placeholder=\"MM/DD/YYYY\"\n />\n <DSFormItemLayout\n floatingLabel\n inputComponent={DSInputMask}\n labelText={labelTo}\n mask={MASK_TYPES.DATE}\n onChange={this.handleChangeEnd}\n onFocus={() => this.setState({ showPicker: false })}\n pipe={MASK_PIPES.AUTO_CORRECT_DATE}\n value={safeEndInputValue}\n required={endDateRequired}\n hasError={hasError || endDateError}\n validationMessage={validationMessage}\n placeholder=\"MM/DD/YYYY\"\n />\n </div>\n <div className={classNameBlock('wrapper-button-date-range-picker-controller')}>\n <DSPopper\n contentComponent={\n <div>\n {showPicker && (\n <DayPickerRangeController\n enableOutsideDays={enableOutsideDays}\n isDayBlocked={isDayBlocked}\n isDayHighlighted={isDayHighlighted}\n isOutsideRange={isOutsideRange}\n displayFormatDay={displayFormatDay}\n endDate={endDate}\n focusedInput={focusedInput}\n hideKeyboardShortcutsPanel\n minimumNights={minimumNights}\n onDatesChange={this.onDatesChange}\n onFocusChange={this.onFocusChange}\n onOutsideClick={(e) => {\n onOutsideClick(e);\n this.setState({ showPicker: false });\n }}\n onNextMonthClick={onNextMonthClick}\n onPrevMonthClick={onPrevMonthClick}\n startDate={startDate}\n renderMonthElement={renderMonthElement}\n />\n )}\n </div>\n }\n isOpen={showPicker && !startDateError && !endDateError}\n onClose={onClose}\n placement=\"bottom-end\"\n showArrow={false}\n triggerComponent={\n <div onFocus={() => this.setState({ showPicker: true })}>\n <DatePickerPicker\n className={classNameElement('picker')}\n disabled={disabled}\n onClick={() => this.setState({ showPicker: true })}\n />\n {hasError && validationMessage && <div style={{ height: 15 }} />}\n </div>\n }\n />\n </div>\n </div>\n );\n }\n}\n\nDSDateRangePickerImpl.propTypes = {\n startDate: PropTypes.instanceOf(Date, moment),\n endDate: PropTypes.instanceOf(Date, moment),\n onDatesChange: PropTypes.func,\n onChangeStartInput: PropTypes.func,\n onChangeEndInput: PropTypes.func,\n onNextMonthClick: PropTypes.func,\n onPrevMonthClick: PropTypes.func,\n onClose: PropTypes.func,\n onOutsideClick: PropTypes.func,\n disabled: PropTypes.bool,\n displayFormatDay: PropTypes.string,\n minimumNights: PropTypes.number,\n labelTo: PropTypes.string,\n labelFrom: PropTypes.string,\n isDayBlocked: PropTypes.func,\n isDayHighlighted: PropTypes.func,\n isOutsideRange: PropTypes.func,\n enableOutsideDays: PropTypes.bool,\n startDateRequired: PropTypes.bool,\n endDateRequired: PropTypes.bool,\n hasError: PropTypes.bool,\n validationMessage: PropTypes.string,\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,MAAM,aAAa;AACnB,MAAM,WAAW;AAExB,MAAM,EAAE,kBAAkB,mBAAmB,0BAA0B;AAEvE,oCAAmD,OAAM,UAAU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QACA,SAAS,MAAM,KAAK,SAAS,EAAE,YAAY;AAAA,UAE5C,YAAY,qBAAqB,qCAAC,OAAD;AAAA,QAAK,OAAO,EAAE,QAAQ;AAAA;AAAA;AAAA;AAAA;AAUxE,sBAAsB,YAAY;AAAA,EAChC,WAAW,UAAU,WAAW,MAAM;AAAA,EACtC,SAAS,UAAU,WAAW,MAAM;AAAA,EACpC,eAAe,UAAU;AAAA,EACzB,oBAAoB,UAAU;AAAA,EAC9B,kBAAkB,UAAU;AAAA,EAC5B,kBAAkB,UAAU;AAAA,EAC5B,kBAAkB,UAAU;AAAA,EAC5B,SAAS,UAAU;AAAA,EACnB,gBAAgB,UAAU;AAAA,EAC1B,UAAU,UAAU;AAAA,EACpB,kBAAkB,UAAU;AAAA,EAC5B,eAAe,UAAU;AAAA,EACzB,SAAS,UAAU;AAAA,EACnB,WAAW,UAAU;AAAA,EACrB,cAAc,UAAU;AAAA,EACxB,kBAAkB,UAAU;AAAA,EAC5B,gBAAgB,UAAU;AAAA,EAC1B,mBAAmB,UAAU;AAAA,EAC7B,mBAAmB,UAAU;AAAA,EAC7B,iBAAiB,UAAU;AAAA,EAC3B,UAAU,UAAU;AAAA,EACpB,mBAAmB,UAAU;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return /*#__PURE__*/_jsx("div", {
|
|
10
|
-
className: className
|
|
11
|
-
}, void 0, /*#__PURE__*/_jsx("span", {}, void 0, label));
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
const Label = ({ className = "date-picker-label", label = "" }) => /* @__PURE__ */ React2.createElement("div", {
|
|
4
|
+
className
|
|
5
|
+
}, /* @__PURE__ */ React2.createElement("span", null, label));
|
|
6
|
+
var DatePickerLabel_default = Label;
|
|
7
|
+
export {
|
|
8
|
+
DatePickerLabel_default as default
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
export { Label as default };
|
|
10
|
+
//# sourceMappingURL=DatePickerLabel.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/components/DatePickerLabel/DatePickerLabel.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\n\nconst Label = ({ className = 'date-picker-label', label = '' }) => (\n <div className={className}>\n <span>{label}</span>\n </div>\n);\n\nexport default Label;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAEA,MAAM,QAAQ,CAAC,EAAE,YAAY,qBAAqB,QAAQ,SACxD,qCAAC,OAAD;AAAA,EAAK;AAAA,GACH,qCAAC,QAAD,MAAO;AAIX,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,75 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const Header = aggregatedClasses('div')(blockname, 'header');
|
|
10
|
-
|
|
11
|
-
const formatDate = date => {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useState, useEffect } from "react";
|
|
3
|
+
import moment from "moment";
|
|
4
|
+
import DSInputMask, { DSInputGroup, MASK_TYPES, MASK_PIPES } from "@elliemae/ds-form";
|
|
5
|
+
import { aggregatedClasses } from "@elliemae/ds-classnames";
|
|
6
|
+
const blockname = "date-range-picker";
|
|
7
|
+
const Header = aggregatedClasses("div")(blockname, "header");
|
|
8
|
+
const formatDate = (date) => {
|
|
12
9
|
if (date) {
|
|
13
|
-
return date.format(
|
|
10
|
+
return date.format("MMDDYYYY");
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const [startValue, setStartValue] = useState(selectedStartDate ? formatDate(selectedStartDate) : '');
|
|
27
|
-
const [endValue, setEndValue] = useState(selectedEndDate ? formatDate(selectedEndDate) : '');
|
|
13
|
+
const DatePickerRangeHeader = ({
|
|
14
|
+
placeholderStart = "Start Date",
|
|
15
|
+
placeholderEnd = "End Date",
|
|
16
|
+
onStartInputChange = () => null,
|
|
17
|
+
onEndInputChange = () => null,
|
|
18
|
+
selectedStartDate,
|
|
19
|
+
selectedEndDate
|
|
20
|
+
}) => {
|
|
21
|
+
const [startValue, setStartValue] = useState(selectedStartDate ? formatDate(selectedStartDate) : "");
|
|
22
|
+
const [endValue, setEndValue] = useState(selectedEndDate ? formatDate(selectedEndDate) : "");
|
|
28
23
|
useEffect(() => {
|
|
29
24
|
const startDate = formatDate(selectedStartDate);
|
|
30
25
|
const endDate = formatDate(selectedEndDate);
|
|
31
26
|
startDate !== startValue && setStartValue(startDate);
|
|
32
27
|
endDate !== endValue && setEndValue(endDate);
|
|
33
28
|
}, [selectedStartDate, selectedEndDate]);
|
|
34
|
-
|
|
35
|
-
const handleOnChangeStart = e => {
|
|
29
|
+
const handleOnChangeStart = (e) => {
|
|
36
30
|
const newStartValue = e.target.value;
|
|
37
31
|
setStartValue(newStartValue);
|
|
38
32
|
};
|
|
39
|
-
|
|
40
|
-
const handleOnChangeEnd = e => {
|
|
33
|
+
const handleOnChangeEnd = (e) => {
|
|
41
34
|
const newEndValue = e.target.value;
|
|
42
35
|
setEndValue(newEndValue);
|
|
43
36
|
};
|
|
44
|
-
|
|
45
|
-
const handleOnBlurStart = e => {
|
|
37
|
+
const handleOnBlurStart = (e) => {
|
|
46
38
|
const newStartValue = e.target.value;
|
|
47
39
|
onStartInputChange(moment(newStartValue));
|
|
48
40
|
};
|
|
49
|
-
|
|
50
|
-
const handleOnBlurEnd = e => {
|
|
41
|
+
const handleOnBlurEnd = (e) => {
|
|
51
42
|
const newEndValue = e.target.value;
|
|
52
43
|
onEndInputChange(moment(newEndValue));
|
|
53
44
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (e.key === 'Enter') {
|
|
45
|
+
const handleOnKeyDownStart = (e) => {
|
|
46
|
+
if (e.key === "Enter") {
|
|
57
47
|
const newValue = e.target.value;
|
|
58
48
|
onStartInputChange(moment(newValue));
|
|
59
49
|
e.target.blur();
|
|
60
50
|
}
|
|
61
51
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (e.key === 'Enter') {
|
|
52
|
+
const handleOnKeyDownEnd = (e) => {
|
|
53
|
+
if (e.key === "Enter") {
|
|
65
54
|
const newValue = e.target.value;
|
|
66
55
|
onEndInputChange(moment(newValue));
|
|
67
56
|
e.target.blur();
|
|
68
57
|
}
|
|
69
58
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"aria-label": placeholderStart || 'Date Picker Input Mask',
|
|
59
|
+
return /* @__PURE__ */ React2.createElement(Header, null, /* @__PURE__ */ React2.createElement(DSInputGroup, null, /* @__PURE__ */ React2.createElement(DSInputMask, {
|
|
60
|
+
"aria-label": placeholderStart || "Date Picker Input Mask",
|
|
73
61
|
mask: MASK_TYPES.DATE,
|
|
74
62
|
onBlur: handleOnBlurStart,
|
|
75
63
|
onChange: handleOnChangeStart,
|
|
@@ -77,8 +65,8 @@ const DatePickerRangeHeader = _ref => {
|
|
|
77
65
|
pipe: MASK_PIPES.AUTO_CORRECT_DATE,
|
|
78
66
|
placeholder: placeholderStart,
|
|
79
67
|
value: startValue
|
|
80
|
-
}),
|
|
81
|
-
"aria-label": placeholderEnd ||
|
|
68
|
+
}), /* @__PURE__ */ React2.createElement(DSInputMask, {
|
|
69
|
+
"aria-label": placeholderEnd || "Date Picker Input Mask",
|
|
82
70
|
mask: MASK_TYPES.DATE,
|
|
83
71
|
onBlur: handleOnBlurEnd,
|
|
84
72
|
onChange: handleOnChangeEnd,
|
|
@@ -88,5 +76,8 @@ const DatePickerRangeHeader = _ref => {
|
|
|
88
76
|
value: endValue
|
|
89
77
|
})));
|
|
90
78
|
};
|
|
91
|
-
|
|
92
|
-
export {
|
|
79
|
+
var DatePickerRangeHeader_default = DatePickerRangeHeader;
|
|
80
|
+
export {
|
|
81
|
+
DatePickerRangeHeader_default as default
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=DatePickerRangeHeader.js.map
|