@elliemae/ds-date-range-picker 2.3.0-alpha.9 → 2.3.0-next.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 +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/{dist/types → types}/DSDateRangePicker.d.ts +0 -0
- package/{dist/types → types}/components/DSDateRangePickerImpl.d.ts +0 -0
- package/{dist/types → types}/components/DatePickerLabel/DatePickerLabel.d.ts +0 -0
- package/{dist/types → types}/components/DatePickerRangeHeader/DatePickerRangeHeader.d.ts +0 -0
- package/{dist/types → types}/components/DayPickerRangeController.d.ts +0 -0
- package/{dist/types → types}/index.d.ts +0 -0
- package/{dist/types → types}/isMaxDiffSafe.d.ts +0 -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,204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
11
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
12
|
+
require('react');
|
|
13
|
+
var reactDesc = require('react-desc');
|
|
14
|
+
var dsClassnames = require('@elliemae/ds-classnames');
|
|
15
|
+
var moment = require('moment');
|
|
16
|
+
require('react-dates/initialize');
|
|
17
|
+
var defaultPhrases = require('react-dates/lib/defaultPhrases');
|
|
18
|
+
var DayPickerRangeController = require('./components/DayPickerRangeController.js');
|
|
19
|
+
var DSDateRangePickerImpl = require('./components/DSDateRangePickerImpl.js');
|
|
20
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
+
|
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
25
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
26
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
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__default["default"](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; }
|
|
31
|
+
|
|
32
|
+
const DSDateRangePicker = _ref => {
|
|
33
|
+
let {
|
|
34
|
+
containerProps = {},
|
|
35
|
+
className = '',
|
|
36
|
+
disabled = false,
|
|
37
|
+
required = false,
|
|
38
|
+
startDateRequired = false,
|
|
39
|
+
endDateRequired = false,
|
|
40
|
+
id,
|
|
41
|
+
hasError = false,
|
|
42
|
+
validationMessage = '',
|
|
43
|
+
readOnly = false,
|
|
44
|
+
screenReaderInputMessage = 'Select date',
|
|
45
|
+
initialVisibleMonth = moment__default["default"](),
|
|
46
|
+
firstDayOfWeek = 0,
|
|
47
|
+
keepOpenOnDateSelect = true,
|
|
48
|
+
reopenPickerOnClearDates = false,
|
|
49
|
+
hideKeyboardShortcutsPanel = true,
|
|
50
|
+
onPrevMonthClick = () => null,
|
|
51
|
+
onNextMonthClick = () => null,
|
|
52
|
+
onClose = () => null,
|
|
53
|
+
onOutsideClick = () => null,
|
|
54
|
+
transitionDuration = 0,
|
|
55
|
+
verticalSpacing = 0,
|
|
56
|
+
minimumNights = 0,
|
|
57
|
+
isDayBlocked = () => false,
|
|
58
|
+
isOutsideRange = () => false,
|
|
59
|
+
isDayHighlighted = () => false,
|
|
60
|
+
displayFormat = 'L',
|
|
61
|
+
displayFormatDay = 'D',
|
|
62
|
+
phrases = defaultPhrases.DateRangePickerPhrases,
|
|
63
|
+
startDate,
|
|
64
|
+
endDate,
|
|
65
|
+
startDateId = 'startDateId',
|
|
66
|
+
endDateId = 'endDateId',
|
|
67
|
+
labelFrom = 'From',
|
|
68
|
+
labelTo = 'To',
|
|
69
|
+
enableOutsideDays = true,
|
|
70
|
+
onChangeStartInput = () => null,
|
|
71
|
+
onChangeEndInput = () => null,
|
|
72
|
+
onDatesChange = () => null
|
|
73
|
+
} = _ref;
|
|
74
|
+
const {
|
|
75
|
+
cssClassName,
|
|
76
|
+
prefixBlockName
|
|
77
|
+
} = dsClassnames.convertPropToCssClassName('datepicker', className, {
|
|
78
|
+
hasError,
|
|
79
|
+
readOnly,
|
|
80
|
+
disabled,
|
|
81
|
+
id
|
|
82
|
+
});
|
|
83
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, containerProps), {}, {
|
|
84
|
+
className: "".concat(prefixBlockName, "-range ").concat(cssClassName, " ").concat(prefixBlockName, "-range"),
|
|
85
|
+
children: /*#__PURE__*/_jsx__default["default"](DSDateRangePickerImpl["default"], {
|
|
86
|
+
appendToBody: true,
|
|
87
|
+
disabled: disabled,
|
|
88
|
+
displayFormat: displayFormat,
|
|
89
|
+
displayFormatDay: displayFormatDay,
|
|
90
|
+
enableOutsideDays: enableOutsideDays,
|
|
91
|
+
endDate: endDate,
|
|
92
|
+
endDateId: endDateId,
|
|
93
|
+
firstDayOfWeek: firstDayOfWeek,
|
|
94
|
+
hideKeyboardShortcutsPanel: hideKeyboardShortcutsPanel,
|
|
95
|
+
initialVisibleMonth: () => initialVisibleMonth ? moment__default["default"](initialVisibleMonth) : moment__default["default"](startDate),
|
|
96
|
+
isDayBlocked: isDayBlocked,
|
|
97
|
+
isDayHighlighted: isDayHighlighted,
|
|
98
|
+
isOutsideRange: isOutsideRange === true || isOutsideRange === false ? () => isOutsideRange : isOutsideRange,
|
|
99
|
+
keepOpenOnDateSelect: keepOpenOnDateSelect,
|
|
100
|
+
labelFrom: labelFrom,
|
|
101
|
+
labelTo: labelTo,
|
|
102
|
+
minimumNights: minimumNights,
|
|
103
|
+
onDatesChange: onDatesChange,
|
|
104
|
+
onChangeStartInput: onChangeStartInput,
|
|
105
|
+
onChangeEndInput: onChangeEndInput,
|
|
106
|
+
onClose: onClose,
|
|
107
|
+
onNextMonthClick: onNextMonthClick,
|
|
108
|
+
onPrevMonthClick: onPrevMonthClick,
|
|
109
|
+
onOutsideClick: onOutsideClick,
|
|
110
|
+
phrases: phrases,
|
|
111
|
+
readOnly: readOnly,
|
|
112
|
+
reopenPickerOnClearDates: reopenPickerOnClearDates,
|
|
113
|
+
required: required,
|
|
114
|
+
startDateRequired: startDateRequired,
|
|
115
|
+
endDateRequired: endDateRequired,
|
|
116
|
+
screenReaderInputMessage: screenReaderInputMessage,
|
|
117
|
+
startDate: startDate,
|
|
118
|
+
startDateId: startDateId,
|
|
119
|
+
transitionDuration: transitionDuration,
|
|
120
|
+
verticalSpacing: verticalSpacing,
|
|
121
|
+
hasError: hasError,
|
|
122
|
+
validationMessage: validationMessage
|
|
123
|
+
})
|
|
124
|
+
}));
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const dateRangePickerProps = {
|
|
128
|
+
containerProps: reactDesc.PropTypes.shape({}).description('Set of Properties attached to the main container'),
|
|
129
|
+
className: reactDesc.PropTypes.string.description('html class attribute'),
|
|
130
|
+
disabled: reactDesc.PropTypes.bool.description('disable component or not').defaultValue(false),
|
|
131
|
+
required: reactDesc.PropTypes.bool.description('input is required or not').defaultValue(false),
|
|
132
|
+
startDateRequired: reactDesc.PropTypes.bool.description('start date is required or not').defaultValue(false),
|
|
133
|
+
endDateRequired: reactDesc.PropTypes.bool.description('end date is required or not').defaultValue(false),
|
|
134
|
+
id: reactDesc.PropTypes.string.description('components id'),
|
|
135
|
+
hasError: reactDesc.PropTypes.bool.description('set error state').defaultValue(false),
|
|
136
|
+
validationMessage: reactDesc.PropTypes.string.description('validation message'),
|
|
137
|
+
readOnly: reactDesc.PropTypes.bool.description('component is read only or not').description(false),
|
|
138
|
+
screenReaderInputMessage: reactDesc.PropTypes.string.description('message to be anounced by screen reader').defaultValue('select date'),
|
|
139
|
+
initialVisibleMonth: reactDesc.PropTypes.instanceOf(Date, moment__default["default"]).description('initial visible month'),
|
|
140
|
+
firstDayOfWeek: reactDesc.PropTypes.number.description('first day of week').defaultValue(0),
|
|
141
|
+
keepOpenOnDateSelect: reactDesc.PropTypes.bool.description('keep picker open when a date is selected').defaultValue(true),
|
|
142
|
+
reopenPickerOnClearDates: reactDesc.PropTypes.bool.description('reopen picker when clearing dates').defaultValue(false),
|
|
143
|
+
hideKeyboardShortcutsPanel: reactDesc.PropTypes.bool.description('hide keyabord shortcut panel or not'),
|
|
144
|
+
onPrevMonthClick: reactDesc.PropTypes.func.description('function executed when clicking on prev month button'),
|
|
145
|
+
onNextMonthClick: reactDesc.PropTypes.func.description('function executed when clicking on next month button'),
|
|
146
|
+
onClose: reactDesc.PropTypes.func.description('function executed when component closes'),
|
|
147
|
+
transitionDuration: reactDesc.PropTypes.number.description('transition duration').defaultValue(0),
|
|
148
|
+
verticalSpacing: reactDesc.PropTypes.number.description('vertical spacing'),
|
|
149
|
+
isDayBlocked: reactDesc.PropTypes.func.description('function that returns each day and disables desired dates'),
|
|
150
|
+
isOutsideRange: reactDesc.PropTypes.func.description('function that returns each day and disables outisde range dates'),
|
|
151
|
+
isDayHighlighted: reactDesc.PropTypes.func.description('function that returns each day and higlights desired dates'),
|
|
152
|
+
minimumNights: 0,
|
|
153
|
+
displayFormat: reactDesc.PropTypes.string.description('display format').defaultValue('L'),
|
|
154
|
+
displayFormatDay: reactDesc.PropTypes.string.description('display format day').defaultValue('D'),
|
|
155
|
+
phrases: reactDesc.PropTypes.shape({
|
|
156
|
+
calendarLabel: reactDesc.PropTypes.string,
|
|
157
|
+
closeDatePicker: reactDesc.PropTypes.string,
|
|
158
|
+
clearDates: reactDesc.PropTypes.string,
|
|
159
|
+
focusStartDate: reactDesc.PropTypes.string,
|
|
160
|
+
jumpToPrevMonth: reactDesc.PropTypes.string,
|
|
161
|
+
jumpToNextMonth: reactDesc.PropTypes.string,
|
|
162
|
+
keyboardShortcuts: reactDesc.PropTypes.string,
|
|
163
|
+
showKeyboardShortcutsPanel: reactDesc.PropTypes.string,
|
|
164
|
+
hideKeyboardShortcutsPanel: reactDesc.PropTypes.string,
|
|
165
|
+
openThisPanel: reactDesc.PropTypes.string,
|
|
166
|
+
enterKey: reactDesc.PropTypes.string,
|
|
167
|
+
leftArrowRightArrow: reactDesc.PropTypes.string,
|
|
168
|
+
upArrowDownArrow: reactDesc.PropTypes.string,
|
|
169
|
+
pageUpPageDown: reactDesc.PropTypes.string,
|
|
170
|
+
homeEnd: reactDesc.PropTypes.string,
|
|
171
|
+
escape: reactDesc.PropTypes.string,
|
|
172
|
+
questionMark: reactDesc.PropTypes.string,
|
|
173
|
+
selectFocusedDate: reactDesc.PropTypes.string,
|
|
174
|
+
moveFocusByOneDay: reactDesc.PropTypes.string,
|
|
175
|
+
moveFocusByOneWeek: reactDesc.PropTypes.string,
|
|
176
|
+
moveFocusByOneMonth: reactDesc.PropTypes.string,
|
|
177
|
+
moveFocustoStartAndEndOfWeek: reactDesc.PropTypes.string,
|
|
178
|
+
returnFocusToInput: reactDesc.PropTypes.string,
|
|
179
|
+
keyboardNavigationInstructions: reactDesc.PropTypes.string,
|
|
180
|
+
chooseAvailableStartDate: reactDesc.PropTypes.func,
|
|
181
|
+
chooseAvailableEndDate: reactDesc.PropTypes.func,
|
|
182
|
+
dateIsUnavailable: reactDesc.PropTypes.func,
|
|
183
|
+
dateIsSelected: reactDesc.PropTypes.func
|
|
184
|
+
}).description('react-dates phrases'),
|
|
185
|
+
startDate: reactDesc.PropTypes.instanceOf(Date, moment__default["default"]).description('start date value'),
|
|
186
|
+
endDate: reactDesc.PropTypes.instanceOf(Date, moment__default["default"]).description('end date value'),
|
|
187
|
+
startDateId: reactDesc.PropTypes.string.description('start date id'),
|
|
188
|
+
endDateId: reactDesc.PropTypes.string.description('end date id'),
|
|
189
|
+
labelFrom: reactDesc.PropTypes.string.description('label of start date input'),
|
|
190
|
+
labelTo: reactDesc.PropTypes.string.description('label of end date input'),
|
|
191
|
+
enableOutsideDays: reactDesc.PropTypes.bool.description('enable days outside current month').defaultValue('true'),
|
|
192
|
+
onDatesChange: reactDesc.PropTypes.func.description('function executed when dates change'),
|
|
193
|
+
onChangeStartInput: reactDesc.PropTypes.func.description('function executed when start date input changes'),
|
|
194
|
+
onChangeEndInput: reactDesc.PropTypes.func.description('function executed when end date input changes'),
|
|
195
|
+
onOutsideClick: reactDesc.PropTypes.func.description('function executed when clicking outside component')
|
|
196
|
+
};
|
|
197
|
+
const DateRangePickerWithSchema = reactDesc.describe(DSDateRangePicker);
|
|
198
|
+
DateRangePickerWithSchema.propTypes = dateRangePickerProps;
|
|
199
|
+
|
|
200
|
+
exports.DayPickerRangeController = DayPickerRangeController;
|
|
201
|
+
exports.END_DATE = DSDateRangePickerImpl.END_DATE;
|
|
202
|
+
exports.START_DATE = DSDateRangePickerImpl.START_DATE;
|
|
203
|
+
exports.DateRangePickerWithSchema = DateRangePickerWithSchema;
|
|
204
|
+
exports["default"] = DSDateRangePicker;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var moment = require('moment');
|
|
8
|
+
var dsClassnames = require('@elliemae/ds-classnames');
|
|
9
|
+
var DSInputMask = require('@elliemae/ds-form');
|
|
10
|
+
var DSPopper = require('@elliemae/ds-popper');
|
|
11
|
+
var dsDatePicker = require('@elliemae/ds-date-picker');
|
|
12
|
+
var DayPickerRangeController = require('./DayPickerRangeController.js');
|
|
13
|
+
var isMaxDiffSafe = require('../isMaxDiffSafe.js');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
18
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
19
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
20
|
+
var DSPopper__default = /*#__PURE__*/_interopDefaultLegacy(DSPopper);
|
|
21
|
+
|
|
22
|
+
const START_DATE = 'startDate';
|
|
23
|
+
const END_DATE = 'endDate';
|
|
24
|
+
const {
|
|
25
|
+
classNameElement,
|
|
26
|
+
classNameBlock
|
|
27
|
+
} = dsClassnames.convertPropToCssClassName('datepicker');
|
|
28
|
+
class DSDateRangePickerImpl extends React__default["default"].Component {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
|
|
32
|
+
this.onDatesChange = _ref => {
|
|
33
|
+
let {
|
|
34
|
+
startDate,
|
|
35
|
+
endDate
|
|
36
|
+
} = _ref;
|
|
37
|
+
const {
|
|
38
|
+
onDatesChange
|
|
39
|
+
} = this.props;
|
|
40
|
+
onDatesChange(startDate, endDate);
|
|
41
|
+
const safe = isMaxDiffSafe.isMaxDiffSafe(startDate, endDate, this.state.startDate, this.state.endDate);
|
|
42
|
+
|
|
43
|
+
if (!safe) {
|
|
44
|
+
this.setState({
|
|
45
|
+
showPicker: false
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.setState({
|
|
50
|
+
startDate,
|
|
51
|
+
endDate,
|
|
52
|
+
primaryStartInput: false,
|
|
53
|
+
primaryEndInput: false
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.onFocusChange = () => {
|
|
58
|
+
this.setState(_ref2 => {
|
|
59
|
+
let {
|
|
60
|
+
focusedInput
|
|
61
|
+
} = _ref2;
|
|
62
|
+
return {
|
|
63
|
+
focusedInput: focusedInput === START_DATE ? END_DATE : START_DATE
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
this.handleKeyDown = event => {
|
|
69
|
+
if (event.key === 'Escape') this.setState({
|
|
70
|
+
showPicker: false
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
this.getSafeStartInputValue = () => {
|
|
75
|
+
const {
|
|
76
|
+
startInput,
|
|
77
|
+
primaryStartInput,
|
|
78
|
+
startDate
|
|
79
|
+
} = this.state;
|
|
80
|
+
if (primaryStartInput && startInput) return startInput;
|
|
81
|
+
if (!startDate) return '';
|
|
82
|
+
return startDate.format('MMDDYYYY');
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
this.getSafeEndInputValue = () => {
|
|
86
|
+
const {
|
|
87
|
+
endInput,
|
|
88
|
+
primaryEndInput,
|
|
89
|
+
endDate
|
|
90
|
+
} = this.state;
|
|
91
|
+
if (primaryEndInput && endInput) return endInput;
|
|
92
|
+
if (!endDate) return '';
|
|
93
|
+
return endDate.format('MMDDYYYY');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
this.changeFocus = () => {
|
|
97
|
+
const {
|
|
98
|
+
disabled
|
|
99
|
+
} = this.props;
|
|
100
|
+
|
|
101
|
+
if (!disabled) {
|
|
102
|
+
this.setState(() => ({
|
|
103
|
+
focusedInput: 'startDate'
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.handleChangeStart = e => {
|
|
109
|
+
var _momentValue;
|
|
110
|
+
|
|
111
|
+
const {
|
|
112
|
+
onChangeStartInput,
|
|
113
|
+
isDayBlocked,
|
|
114
|
+
minimumNights
|
|
115
|
+
} = this.props;
|
|
116
|
+
const {
|
|
117
|
+
endDate
|
|
118
|
+
} = this.state;
|
|
119
|
+
const startInputVal = e.target.value;
|
|
120
|
+
let momentValue = null;
|
|
121
|
+
|
|
122
|
+
if (startInputVal && moment__default["default"](startInputVal, 'MM/DD/YYYY', true).isValid()) {
|
|
123
|
+
momentValue = moment__default["default"](startInputVal);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const startDateBlocked = isDayBlocked(momentValue);
|
|
127
|
+
const isStartDateAcceptable = !startDateBlocked && momentValue && startInputVal !== '';
|
|
128
|
+
const areDatesValid = endDate && momentValue && (endDate === null || endDate === void 0 ? void 0 : endDate.isValid()) && ((_momentValue = momentValue) === null || _momentValue === void 0 ? void 0 : _momentValue.isValid());
|
|
129
|
+
const canEndBeSameAsStart = minimumNights === 0;
|
|
130
|
+
const isStartAcceptableWithSelectedEnd = !endDate || areDatesValid && (canEndBeSameAsStart && momentValue.diff(endDate, 'days') <= 0 || !canEndBeSameAsStart && momentValue.diff(endDate, 'days') < 0);
|
|
131
|
+
const invalidDate = !isStartDateAcceptable || !isStartAcceptableWithSelectedEnd;
|
|
132
|
+
if (startDateBlocked) momentValue = null;
|
|
133
|
+
onChangeStartInput(momentValue);
|
|
134
|
+
this.setState(prevState => ({
|
|
135
|
+
startDate: momentValue,
|
|
136
|
+
startInput: startInputVal,
|
|
137
|
+
primaryStartInput: true,
|
|
138
|
+
startDateError: invalidDate,
|
|
139
|
+
endDateError: !isStartDateAcceptable || !prevState.endDateError ? prevState.endDateError : !isStartAcceptableWithSelectedEnd
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
this.handleChangeEnd = e => {
|
|
144
|
+
var _momentValue2;
|
|
145
|
+
|
|
146
|
+
const {
|
|
147
|
+
onChangeEndInput,
|
|
148
|
+
isDayBlocked,
|
|
149
|
+
minimumNights
|
|
150
|
+
} = this.props;
|
|
151
|
+
const {
|
|
152
|
+
startDate
|
|
153
|
+
} = this.state;
|
|
154
|
+
const endInputValue = e.target.value;
|
|
155
|
+
let momentValue = null;
|
|
156
|
+
|
|
157
|
+
if (endInputValue && moment__default["default"](endInputValue, 'MM/DD/YYYY', true).isValid()) {
|
|
158
|
+
momentValue = moment__default["default"](endInputValue);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const endDateBlocked = isDayBlocked(momentValue);
|
|
162
|
+
const isEndDateAcceptable = !endDateBlocked && momentValue && endInputValue !== '';
|
|
163
|
+
const areDatesValid = startDate && momentValue && (startDate === null || startDate === void 0 ? void 0 : startDate.isValid()) && ((_momentValue2 = momentValue) === null || _momentValue2 === void 0 ? void 0 : _momentValue2.isValid());
|
|
164
|
+
const canEndBeSameAsStart = minimumNights === 0;
|
|
165
|
+
const isEndAcceptableWithSelectedStart = !startDate || // we can't compare with start date because it's not yet set
|
|
166
|
+
areDatesValid && ( // it's set and both are valid
|
|
167
|
+
canEndBeSameAsStart && momentValue.diff(startDate, 'days') >= 0 || // >= is valid
|
|
168
|
+
!canEndBeSameAsStart && momentValue.diff(startDate, 'days') > 0); // only > is valid
|
|
169
|
+
|
|
170
|
+
const invalidDate = !isEndDateAcceptable || !isEndAcceptableWithSelectedStart;
|
|
171
|
+
if (endDateBlocked) momentValue = null;
|
|
172
|
+
onChangeEndInput(momentValue);
|
|
173
|
+
this.setState(prevState => ({
|
|
174
|
+
endDate: momentValue,
|
|
175
|
+
endInput: endInputValue,
|
|
176
|
+
primaryEndInput: true,
|
|
177
|
+
startDateError: !isEndDateAcceptable || !prevState.startDateError ? prevState.startDateError : !isEndAcceptableWithSelectedStart,
|
|
178
|
+
endDateError: invalidDate
|
|
179
|
+
}));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
this.handleChangeDate = _ref3 => {
|
|
183
|
+
let {
|
|
184
|
+
startDate: _start,
|
|
185
|
+
endDate
|
|
186
|
+
} = _ref3;
|
|
187
|
+
|
|
188
|
+
if (_start && endDate) {
|
|
189
|
+
this.setState({
|
|
190
|
+
startDate: moment__default["default"](_start),
|
|
191
|
+
endDate,
|
|
192
|
+
primaryStartInput: false,
|
|
193
|
+
primaryEndInput: false
|
|
194
|
+
});
|
|
195
|
+
} else if (_start) {
|
|
196
|
+
this.setState({
|
|
197
|
+
startDate: moment__default["default"](_start),
|
|
198
|
+
primaryStartInput: false
|
|
199
|
+
});
|
|
200
|
+
} else if (endDate) {
|
|
201
|
+
this.setState({
|
|
202
|
+
endDate,
|
|
203
|
+
primaryEndInput: false
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
this.state = {
|
|
209
|
+
startDate: props.startDate ? moment__default["default"](props.startDate) : null,
|
|
210
|
+
endDate: props.endDate ? moment__default["default"](props.endDate) : null,
|
|
211
|
+
focusedInput: START_DATE,
|
|
212
|
+
showPicker: false,
|
|
213
|
+
startDateError: false,
|
|
214
|
+
endDateError: false
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
componentDidMount() {
|
|
219
|
+
document.addEventListener('keydown', this.handleKeyDown, false);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
componentWillUnmount() {
|
|
223
|
+
document.removeEventListener('keydown', this.handleKeyDown, false);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
render() {
|
|
227
|
+
const {
|
|
228
|
+
startDate,
|
|
229
|
+
endDate,
|
|
230
|
+
focusedInput,
|
|
231
|
+
showPicker,
|
|
232
|
+
startDateError,
|
|
233
|
+
endDateError
|
|
234
|
+
} = this.state;
|
|
235
|
+
const {
|
|
236
|
+
disabled,
|
|
237
|
+
displayFormatDay,
|
|
238
|
+
minimumNights,
|
|
239
|
+
labelFrom,
|
|
240
|
+
labelTo,
|
|
241
|
+
isDayBlocked,
|
|
242
|
+
isDayHighlighted,
|
|
243
|
+
isOutsideRange,
|
|
244
|
+
enableOutsideDays,
|
|
245
|
+
startDateRequired,
|
|
246
|
+
endDateRequired,
|
|
247
|
+
onOutsideClick,
|
|
248
|
+
onNextMonthClick,
|
|
249
|
+
onPrevMonthClick,
|
|
250
|
+
onClose,
|
|
251
|
+
hasError,
|
|
252
|
+
validationMessage
|
|
253
|
+
} = this.props;
|
|
254
|
+
const inputClass = classNameBlock('inputs', 'range-picker');
|
|
255
|
+
const inputClassModifier = '';
|
|
256
|
+
const safeStartInputValue = this.getSafeStartInputValue();
|
|
257
|
+
const safeEndInputValue = this.getSafeEndInputValue();
|
|
258
|
+
return /*#__PURE__*/_jsx__default["default"]("div", {
|
|
259
|
+
className: "".concat(inputClass, " ").concat(inputClassModifier)
|
|
260
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"]("div", {
|
|
261
|
+
className: classNameBlock('wrapper-input-date-range-picker-controller')
|
|
262
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"](DSInputMask.DSFormItemLayout, {
|
|
263
|
+
floatingLabel: true,
|
|
264
|
+
inputComponent: DSInputMask.DSInputMask,
|
|
265
|
+
labelText: labelFrom,
|
|
266
|
+
mask: DSInputMask.MASK_TYPES.DATE,
|
|
267
|
+
onChange: this.handleChangeStart,
|
|
268
|
+
onFocus: () => this.setState({
|
|
269
|
+
showPicker: false
|
|
270
|
+
}),
|
|
271
|
+
pipe: DSInputMask.MASK_PIPES.AUTO_CORRECT_DATE,
|
|
272
|
+
value: safeStartInputValue,
|
|
273
|
+
required: startDateRequired,
|
|
274
|
+
hasError: hasError || startDateError,
|
|
275
|
+
placeholder: "MM/DD/YYYY"
|
|
276
|
+
}), /*#__PURE__*/_jsx__default["default"](DSInputMask.DSFormItemLayout, {
|
|
277
|
+
floatingLabel: true,
|
|
278
|
+
inputComponent: DSInputMask.DSInputMask,
|
|
279
|
+
labelText: labelTo,
|
|
280
|
+
mask: DSInputMask.MASK_TYPES.DATE,
|
|
281
|
+
onChange: this.handleChangeEnd,
|
|
282
|
+
onFocus: () => this.setState({
|
|
283
|
+
showPicker: false
|
|
284
|
+
}),
|
|
285
|
+
pipe: DSInputMask.MASK_PIPES.AUTO_CORRECT_DATE,
|
|
286
|
+
value: safeEndInputValue,
|
|
287
|
+
required: endDateRequired,
|
|
288
|
+
hasError: hasError || endDateError,
|
|
289
|
+
validationMessage: validationMessage,
|
|
290
|
+
placeholder: "MM/DD/YYYY"
|
|
291
|
+
})), /*#__PURE__*/_jsx__default["default"]("div", {
|
|
292
|
+
className: classNameBlock('wrapper-button-date-range-picker-controller')
|
|
293
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"](DSPopper__default["default"], {
|
|
294
|
+
contentComponent: /*#__PURE__*/_jsx__default["default"]("div", {}, void 0, showPicker && /*#__PURE__*/_jsx__default["default"](DayPickerRangeController, {
|
|
295
|
+
enableOutsideDays: enableOutsideDays,
|
|
296
|
+
isDayBlocked: isDayBlocked,
|
|
297
|
+
isDayHighlighted: isDayHighlighted,
|
|
298
|
+
isOutsideRange: isOutsideRange,
|
|
299
|
+
displayFormatDay: displayFormatDay,
|
|
300
|
+
endDate: endDate,
|
|
301
|
+
focusedInput: focusedInput,
|
|
302
|
+
hideKeyboardShortcutsPanel: true,
|
|
303
|
+
minimumNights: minimumNights,
|
|
304
|
+
onDatesChange: this.onDatesChange,
|
|
305
|
+
onFocusChange: this.onFocusChange,
|
|
306
|
+
onOutsideClick: e => {
|
|
307
|
+
onOutsideClick(e);
|
|
308
|
+
this.setState({
|
|
309
|
+
showPicker: false
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
onNextMonthClick: onNextMonthClick,
|
|
313
|
+
onPrevMonthClick: onPrevMonthClick,
|
|
314
|
+
startDate: startDate,
|
|
315
|
+
renderMonthElement: dsDatePicker.renderMonthElement
|
|
316
|
+
})),
|
|
317
|
+
isOpen: showPicker && !startDateError && !endDateError,
|
|
318
|
+
onClose: onClose,
|
|
319
|
+
placement: "bottom-end",
|
|
320
|
+
showArrow: false,
|
|
321
|
+
triggerComponent: /*#__PURE__*/_jsx__default["default"]("div", {
|
|
322
|
+
onFocus: () => this.setState({
|
|
323
|
+
showPicker: true
|
|
324
|
+
})
|
|
325
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"](dsDatePicker.DatePickerPicker, {
|
|
326
|
+
className: classNameElement('picker'),
|
|
327
|
+
disabled: disabled,
|
|
328
|
+
onClick: () => this.setState({
|
|
329
|
+
showPicker: true
|
|
330
|
+
})
|
|
331
|
+
}), hasError && validationMessage && /*#__PURE__*/_jsx__default["default"]("div", {
|
|
332
|
+
style: {
|
|
333
|
+
height: 15
|
|
334
|
+
}
|
|
335
|
+
}))
|
|
336
|
+
})));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
exports.END_DATE = END_DATE;
|
|
342
|
+
exports.START_DATE = START_DATE;
|
|
343
|
+
exports["default"] = DSDateRangePickerImpl;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
4
|
+
require('react');
|
|
5
|
+
|
|
6
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
9
|
+
|
|
10
|
+
const Label = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
className = 'date-picker-label',
|
|
13
|
+
label = ''
|
|
14
|
+
} = _ref;
|
|
15
|
+
return /*#__PURE__*/_jsx__default["default"]("div", {
|
|
16
|
+
className: className
|
|
17
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"]("span", {}, void 0, label));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = Label;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
4
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var moment = require('moment');
|
|
7
|
+
var DSInputMask = require('@elliemae/ds-form');
|
|
8
|
+
var dsClassnames = require('@elliemae/ds-classnames');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
13
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
14
|
+
var DSInputMask__default = /*#__PURE__*/_interopDefaultLegacy(DSInputMask);
|
|
15
|
+
|
|
16
|
+
const blockname = 'date-range-picker';
|
|
17
|
+
const Header = dsClassnames.aggregatedClasses('div')(blockname, 'header');
|
|
18
|
+
|
|
19
|
+
const formatDate = date => {
|
|
20
|
+
if (date) {
|
|
21
|
+
return date.format('MMDDYYYY');
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DatePickerRangeHeader = _ref => {
|
|
26
|
+
let {
|
|
27
|
+
placeholderStart = 'Start Date',
|
|
28
|
+
placeholderEnd = 'End Date',
|
|
29
|
+
onStartInputChange = () => null,
|
|
30
|
+
onEndInputChange = () => null,
|
|
31
|
+
selectedStartDate,
|
|
32
|
+
selectedEndDate
|
|
33
|
+
} = _ref;
|
|
34
|
+
const [startValue, setStartValue] = React.useState(selectedStartDate ? formatDate(selectedStartDate) : '');
|
|
35
|
+
const [endValue, setEndValue] = React.useState(selectedEndDate ? formatDate(selectedEndDate) : '');
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
const startDate = formatDate(selectedStartDate);
|
|
38
|
+
const endDate = formatDate(selectedEndDate);
|
|
39
|
+
startDate !== startValue && setStartValue(startDate);
|
|
40
|
+
endDate !== endValue && setEndValue(endDate);
|
|
41
|
+
}, [selectedStartDate, selectedEndDate]);
|
|
42
|
+
|
|
43
|
+
const handleOnChangeStart = e => {
|
|
44
|
+
const newStartValue = e.target.value;
|
|
45
|
+
setStartValue(newStartValue);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleOnChangeEnd = e => {
|
|
49
|
+
const newEndValue = e.target.value;
|
|
50
|
+
setEndValue(newEndValue);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleOnBlurStart = e => {
|
|
54
|
+
const newStartValue = e.target.value;
|
|
55
|
+
onStartInputChange(moment__default["default"](newStartValue));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleOnBlurEnd = e => {
|
|
59
|
+
const newEndValue = e.target.value;
|
|
60
|
+
onEndInputChange(moment__default["default"](newEndValue));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleOnKeyDownStart = e => {
|
|
64
|
+
if (e.key === 'Enter') {
|
|
65
|
+
const newValue = e.target.value;
|
|
66
|
+
onStartInputChange(moment__default["default"](newValue));
|
|
67
|
+
e.target.blur();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleOnKeyDownEnd = e => {
|
|
72
|
+
if (e.key === 'Enter') {
|
|
73
|
+
const newValue = e.target.value;
|
|
74
|
+
onEndInputChange(moment__default["default"](newValue));
|
|
75
|
+
e.target.blur();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return /*#__PURE__*/_jsx__default["default"](Header, {}, void 0, /*#__PURE__*/_jsx__default["default"](DSInputMask.DSInputGroup, {}, void 0, /*#__PURE__*/_jsx__default["default"](DSInputMask__default["default"], {
|
|
80
|
+
"aria-label": placeholderStart || 'Date Picker Input Mask',
|
|
81
|
+
mask: DSInputMask.MASK_TYPES.DATE,
|
|
82
|
+
onBlur: handleOnBlurStart,
|
|
83
|
+
onChange: handleOnChangeStart,
|
|
84
|
+
onKeyDown: handleOnKeyDownStart,
|
|
85
|
+
pipe: DSInputMask.MASK_PIPES.AUTO_CORRECT_DATE,
|
|
86
|
+
placeholder: placeholderStart,
|
|
87
|
+
value: startValue
|
|
88
|
+
}), /*#__PURE__*/_jsx__default["default"](DSInputMask__default["default"], {
|
|
89
|
+
"aria-label": placeholderEnd || 'Date Picker Input Mask',
|
|
90
|
+
mask: DSInputMask.MASK_TYPES.DATE,
|
|
91
|
+
onBlur: handleOnBlurEnd,
|
|
92
|
+
onChange: handleOnChangeEnd,
|
|
93
|
+
onKeyDown: handleOnKeyDownEnd,
|
|
94
|
+
pipe: DSInputMask.MASK_PIPES.AUTO_CORRECT_DATE,
|
|
95
|
+
placeholder: placeholderEnd,
|
|
96
|
+
value: endValue
|
|
97
|
+
})));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
module.exports = DatePickerRangeHeader;
|