@elliemae/ds-date-picker 2.2.0-alpha.4 → 3.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/DSDatePicker.js +221 -219
- package/cjs/components/DSDatePickerImpl.js +208 -128
- package/cjs/components/DatePickerController/DatePickerController.js +242 -204
- package/cjs/components/DatePickerDay/DatePickerDay.js +23 -48
- package/cjs/components/DatePickerDropdown.js +54 -74
- package/cjs/components/DatePickerHeader/DatePickerHeader.js +44 -62
- package/cjs/components/DatePickerNavigation/DatePickerNavigation.js +31 -62
- package/cjs/components/DatePickerPicker/DatePickerPicker.js +71 -82
- package/cjs/components/DatePickerRange/DatePickerRange.js +93 -84
- package/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js +97 -91
- package/cjs/components/DatePickerRenderMonth/DatePickerRenderMonth.js +45 -60
- package/cjs/components/DatePickerSingleDate/DatePickerSingleDate.js +77 -88
- package/cjs/components/SingleRangeDateSwitcher/SingleRangeDateSwitcher.js +48 -69
- package/cjs/components/index.js +27 -53
- package/cjs/defaultPhrases.js +92 -77
- package/cjs/index.js +35 -38
- package/esm/DSDatePicker.js +169 -171
- package/esm/components/DSDatePickerImpl.js +189 -88
- package/esm/components/DatePickerController/DatePickerController.js +198 -141
- package/esm/components/DatePickerDay/DatePickerDay.js +17 -19
- package/esm/components/DatePickerDropdown.js +46 -45
- package/esm/components/DatePickerHeader/DatePickerHeader.js +35 -31
- package/esm/components/DatePickerNavigation/DatePickerNavigation.js +24 -36
- package/esm/components/DatePickerPicker/DatePickerPicker.js +48 -44
- package/esm/components/DatePickerRange/DatePickerRange.js +79 -49
- package/esm/components/DatePickerRangeHeader/DatePickerRangeHeader.js +78 -50
- package/esm/components/DatePickerRenderMonth/DatePickerRenderMonth.js +37 -31
- package/esm/components/DatePickerSingleDate/DatePickerSingleDate.js +66 -56
- package/esm/components/SingleRangeDateSwitcher/SingleRangeDateSwitcher.js +42 -40
- package/esm/components/index.js +10 -24
- package/esm/defaultPhrases.js +80 -48
- package/esm/index.js +13 -9
- package/package.json +10 -10
- package/types/components/DSDatePickerImpl.d.ts +1 -2
- package/types/components/DatePickerController/DatePickerController.d.ts +1 -1
- package/types/components/DatePickerDay/DatePickerDay.d.ts +0 -1
- package/types/components/DatePickerDropdown.d.ts +0 -1
- package/types/components/DatePickerHeader/DatePickerHeader.d.ts +0 -1
- package/types/components/DatePickerNavigation/DatePickerNavigation.d.ts +3 -4
- package/types/components/DatePickerPicker/DatePickerPicker.d.ts +1 -2
- package/types/components/DatePickerRange/DatePickerRange.d.ts +0 -1
- package/types/components/DatePickerRangeHeader/DatePickerRangeHeader.d.ts +0 -1
- package/types/components/DatePickerSingleDate/DatePickerSingleDate.d.ts +0 -1
- package/types/components/SingleRangeDateSwitcher/SingleRangeDateSwitcher.d.ts +0 -1
- package/cjs/DSDatePicker.js.map +0 -7
- package/cjs/components/DSDatePickerImpl.js.map +0 -7
- package/cjs/components/DatePickerController/DatePickerController.js.map +0 -7
- package/cjs/components/DatePickerDay/DatePickerDay.js.map +0 -7
- package/cjs/components/DatePickerDropdown.js.map +0 -7
- package/cjs/components/DatePickerHeader/DatePickerHeader.js.map +0 -7
- package/cjs/components/DatePickerNavigation/DatePickerNavigation.js.map +0 -7
- package/cjs/components/DatePickerPicker/DatePickerPicker.js.map +0 -7
- package/cjs/components/DatePickerRange/DatePickerRange.js.map +0 -7
- package/cjs/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +0 -7
- package/cjs/components/DatePickerRenderMonth/DatePickerRenderMonth.js.map +0 -7
- package/cjs/components/DatePickerSingleDate/DatePickerSingleDate.js.map +0 -7
- package/cjs/components/SingleRangeDateSwitcher/SingleRangeDateSwitcher.js.map +0 -7
- package/cjs/components/index.js.map +0 -7
- package/cjs/defaultPhrases.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/esm/DSDatePicker.js.map +0 -7
- package/esm/components/DSDatePickerImpl.js.map +0 -7
- package/esm/components/DatePickerController/DatePickerController.js.map +0 -7
- package/esm/components/DatePickerDay/DatePickerDay.js.map +0 -7
- package/esm/components/DatePickerDropdown.js.map +0 -7
- package/esm/components/DatePickerHeader/DatePickerHeader.js.map +0 -7
- package/esm/components/DatePickerNavigation/DatePickerNavigation.js.map +0 -7
- package/esm/components/DatePickerPicker/DatePickerPicker.js.map +0 -7
- package/esm/components/DatePickerRange/DatePickerRange.js.map +0 -7
- package/esm/components/DatePickerRangeHeader/DatePickerRangeHeader.js.map +0 -7
- package/esm/components/DatePickerRenderMonth/DatePickerRenderMonth.js.map +0 -7
- package/esm/components/DatePickerSingleDate/DatePickerSingleDate.js.map +0 -7
- package/esm/components/SingleRangeDateSwitcher/SingleRangeDateSwitcher.js.map +0 -7
- package/esm/components/index.js.map +0 -7
- package/esm/defaultPhrases.js.map +0 -7
- package/esm/index.js.map +0 -7
|
@@ -1,61 +1,105 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
import { DSInputGroup, DSDateInputV2 } from '@elliemae/ds-form';
|
|
6
|
+
import DSDatePickerController from './DatePickerController/DatePickerController.js';
|
|
7
|
+
import DatePickerDropdown from './DatePickerDropdown.js';
|
|
8
|
+
|
|
9
|
+
const FORMAT = 'MMDDYYYY';
|
|
10
|
+
class DSdatePickerImpl extends React.Component {
|
|
9
11
|
constructor(props) {
|
|
10
12
|
super(props);
|
|
13
|
+
|
|
11
14
|
this.onClickPicker = () => {
|
|
12
|
-
this.setState({
|
|
15
|
+
this.setState({
|
|
16
|
+
inputFocused: true
|
|
17
|
+
});
|
|
13
18
|
};
|
|
19
|
+
|
|
14
20
|
this.getSafeValue = () => {
|
|
15
|
-
const {
|
|
16
|
-
|
|
21
|
+
const {
|
|
22
|
+
value,
|
|
23
|
+
date,
|
|
24
|
+
defaultValue
|
|
25
|
+
} = this.props;
|
|
26
|
+
const {
|
|
27
|
+
selectedDate
|
|
28
|
+
} = this.state;
|
|
29
|
+
|
|
17
30
|
if (value) {
|
|
18
31
|
return moment(value, FORMAT, true);
|
|
19
32
|
}
|
|
33
|
+
|
|
20
34
|
if (date) {
|
|
21
35
|
return moment(date, FORMAT, true);
|
|
22
36
|
}
|
|
37
|
+
|
|
23
38
|
if (defaultValue) {
|
|
24
39
|
return moment(defaultValue, FORMAT, true);
|
|
25
40
|
}
|
|
41
|
+
|
|
26
42
|
if (selectedDate) {
|
|
27
43
|
return selectedDate;
|
|
28
44
|
}
|
|
45
|
+
|
|
29
46
|
return null;
|
|
30
47
|
};
|
|
48
|
+
|
|
31
49
|
this.getSafeInputValue = () => {
|
|
32
50
|
const safeValue = this.getSafeValue();
|
|
51
|
+
|
|
33
52
|
if (safeValue && safeValue.isValid()) {
|
|
34
53
|
return safeValue.format(FORMAT);
|
|
35
54
|
}
|
|
36
|
-
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
dataInput
|
|
58
|
+
} = this.state;
|
|
37
59
|
return dataInput;
|
|
38
60
|
};
|
|
61
|
+
|
|
39
62
|
this.isControlled = () => {
|
|
40
|
-
const {
|
|
63
|
+
const {
|
|
64
|
+
value,
|
|
65
|
+
date
|
|
66
|
+
} = this.props;
|
|
41
67
|
return Boolean(value) || Boolean(date);
|
|
42
68
|
};
|
|
69
|
+
|
|
43
70
|
this.handleDateChange = (date, event) => {
|
|
44
|
-
const {
|
|
71
|
+
const {
|
|
72
|
+
readOnly,
|
|
73
|
+
onDateChange,
|
|
74
|
+
keepOpenOnDateSelect,
|
|
75
|
+
onChange,
|
|
76
|
+
onBlur
|
|
77
|
+
} = this.props;
|
|
78
|
+
|
|
45
79
|
if (!readOnly) {
|
|
46
80
|
if (!this.isControlled()) {
|
|
47
|
-
this.setState({
|
|
81
|
+
this.setState({
|
|
82
|
+
dataInput: date.format(FORMAT),
|
|
83
|
+
selectedDate: date
|
|
84
|
+
});
|
|
48
85
|
}
|
|
86
|
+
|
|
49
87
|
onChange(date.format(FORMAT), date);
|
|
50
88
|
onDateChange(date);
|
|
51
|
-
|
|
52
|
-
|
|
89
|
+
|
|
90
|
+
if (!keepOpenOnDateSelect || event.key === 'Enter') {
|
|
91
|
+
this.setState({
|
|
92
|
+
inputFocused: false
|
|
93
|
+
});
|
|
53
94
|
onBlur(date.format(FORMAT), date);
|
|
54
95
|
}
|
|
55
96
|
}
|
|
56
97
|
};
|
|
98
|
+
|
|
57
99
|
this.handleInputChange = (dataInput, newDate) => {
|
|
58
|
-
const {
|
|
100
|
+
const {
|
|
101
|
+
onChange
|
|
102
|
+
} = this.props;
|
|
59
103
|
const newState = {
|
|
60
104
|
dataInput,
|
|
61
105
|
selectedDate: newDate
|
|
@@ -63,71 +107,117 @@ class DSDatePickerImpl extends React2.Component {
|
|
|
63
107
|
this.setState(() => newState);
|
|
64
108
|
onChange(dataInput, newDate);
|
|
65
109
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const {
|
|
110
|
+
|
|
111
|
+
this.handleChange = newDate => {
|
|
112
|
+
if (!newDate) return;
|
|
113
|
+
const {
|
|
114
|
+
onDateChange
|
|
115
|
+
} = this.props;
|
|
70
116
|
const momentValue = moment(newDate, FORMAT, true);
|
|
71
|
-
if (!momentValue.isValid())
|
|
72
|
-
|
|
73
|
-
|
|
117
|
+
if (!momentValue.isValid()) return;
|
|
118
|
+
this.setState({
|
|
119
|
+
selectedDate: momentValue
|
|
120
|
+
});
|
|
74
121
|
onDateChange(momentValue);
|
|
75
122
|
};
|
|
76
|
-
|
|
77
|
-
|
|
123
|
+
|
|
124
|
+
this.handleFocus = _ref => {
|
|
125
|
+
let {
|
|
126
|
+
focused
|
|
127
|
+
} = _ref;
|
|
128
|
+
this.setState({
|
|
129
|
+
inputFocused: focused
|
|
130
|
+
});
|
|
78
131
|
};
|
|
132
|
+
|
|
79
133
|
this.handleCalendarClose = () => {
|
|
80
|
-
const {
|
|
81
|
-
|
|
134
|
+
const {
|
|
135
|
+
onClose
|
|
136
|
+
} = this.props;
|
|
137
|
+
this.setState({
|
|
138
|
+
inputFocused: false
|
|
139
|
+
});
|
|
82
140
|
this.handleOnBlur();
|
|
83
141
|
onClose();
|
|
84
142
|
};
|
|
143
|
+
|
|
85
144
|
this.handleClickEscape = () => {
|
|
86
|
-
const {
|
|
87
|
-
|
|
145
|
+
const {
|
|
146
|
+
onClose
|
|
147
|
+
} = this.props;
|
|
148
|
+
this.setState({
|
|
149
|
+
inputFocused: false
|
|
150
|
+
});
|
|
88
151
|
this.handleOnBlur();
|
|
89
152
|
onClose();
|
|
90
153
|
};
|
|
154
|
+
|
|
91
155
|
this.handleOnBlur = () => {
|
|
92
156
|
setTimeout(() => {
|
|
93
|
-
const {
|
|
94
|
-
|
|
157
|
+
const {
|
|
158
|
+
onBlur,
|
|
159
|
+
autoClear
|
|
160
|
+
} = this.props;
|
|
161
|
+
const {
|
|
162
|
+
dataInput,
|
|
163
|
+
selectedDate
|
|
164
|
+
} = this.state;
|
|
165
|
+
|
|
95
166
|
if (moment(selectedDate, FORMAT, true).isValid()) {
|
|
96
167
|
onBlur(dataInput, selectedDate);
|
|
97
168
|
} else {
|
|
98
169
|
if (autoClear) {
|
|
99
|
-
this.setState({
|
|
170
|
+
this.setState({
|
|
171
|
+
dataInput: undefined
|
|
172
|
+
});
|
|
100
173
|
}
|
|
174
|
+
|
|
101
175
|
onBlur(dataInput, null);
|
|
102
176
|
}
|
|
103
177
|
});
|
|
104
178
|
};
|
|
105
|
-
|
|
106
|
-
|
|
179
|
+
|
|
180
|
+
this.handleInputFocus = dataInput => {
|
|
181
|
+
const {
|
|
182
|
+
onFocus
|
|
183
|
+
} = this.props;
|
|
107
184
|
onFocus(dataInput);
|
|
108
185
|
};
|
|
186
|
+
|
|
109
187
|
this.state = {
|
|
110
|
-
pickerRef:
|
|
111
|
-
dataInput:
|
|
188
|
+
pickerRef: /*#__PURE__*/React.createRef(),
|
|
189
|
+
dataInput: '',
|
|
112
190
|
selectedDate: null,
|
|
113
191
|
inputFocused: false
|
|
114
192
|
};
|
|
115
193
|
}
|
|
194
|
+
|
|
116
195
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
117
|
-
const {
|
|
118
|
-
|
|
196
|
+
const {
|
|
197
|
+
dataInput: prevVal,
|
|
198
|
+
selectedDate: prevDate
|
|
199
|
+
} = prevState || {};
|
|
200
|
+
const {
|
|
201
|
+
value: nextVal,
|
|
202
|
+
date: nextDate
|
|
203
|
+
} = nextProps;
|
|
119
204
|
const isPrevValMoment = prevVal instanceof moment;
|
|
120
205
|
const isPrevDateMoment = prevDate instanceof moment;
|
|
121
|
-
const prevValAsString = isPrevValMoment ? prevVal.format(FORMAT) : prevVal;
|
|
206
|
+
const prevValAsString = isPrevValMoment ? prevVal.format(FORMAT) : prevVal; // if users wants to clear, we use '==' to catch both undefined AND null
|
|
207
|
+
|
|
122
208
|
if (nextVal == null && nextDate == null) {
|
|
123
209
|
return {
|
|
124
|
-
dataInput:
|
|
210
|
+
dataInput: '',
|
|
125
211
|
selectedDate: null
|
|
126
212
|
};
|
|
127
|
-
}
|
|
128
|
-
|
|
213
|
+
} // when val is an incomplete state, we don't want to mess with the state
|
|
214
|
+
// it's incomplete when length is not the full mmddyyyy (length === 8)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if ((prevValAsString === null || prevValAsString === void 0 ? void 0 : prevValAsString.length) < 8) {
|
|
129
218
|
return null;
|
|
130
219
|
}
|
|
220
|
+
|
|
131
221
|
const prevDateAsString = isPrevDateMoment ? prevDate.format(FORMAT) : prevDate;
|
|
132
222
|
const isNextValMoment = nextVal instanceof moment;
|
|
133
223
|
const isNextDateMoment = nextDate instanceof moment;
|
|
@@ -138,23 +228,31 @@ class DSDatePickerImpl extends React2.Component {
|
|
|
138
228
|
const hasValChanged = nextValAsString !== prevValAsString;
|
|
139
229
|
const hasDateChanged = nextDateAsString !== prevDateAsString;
|
|
140
230
|
const newState = {};
|
|
141
|
-
let skipStateChange = true;
|
|
231
|
+
let skipStateChange = true; // value has priority over date, if both date and value change we take date
|
|
232
|
+
// as such, order of condition is meaningful
|
|
233
|
+
|
|
142
234
|
if (hasDateChanged) {
|
|
143
235
|
skipStateChange = false;
|
|
144
236
|
newState.dataInput = nextDateAsString;
|
|
145
237
|
newState.selectedDate = nextDateAsMoment;
|
|
146
238
|
}
|
|
239
|
+
|
|
147
240
|
if (hasValChanged) {
|
|
148
241
|
skipStateChange = false;
|
|
149
242
|
newState.dataInput = nextValAsString;
|
|
150
243
|
newState.selectedDate = nextValAsMoment;
|
|
151
244
|
}
|
|
152
|
-
|
|
153
|
-
|
|
245
|
+
|
|
246
|
+
if (skipStateChange) return null;
|
|
154
247
|
return newState;
|
|
155
248
|
}
|
|
249
|
+
|
|
156
250
|
render() {
|
|
157
|
-
|
|
251
|
+
var _this = this;
|
|
252
|
+
|
|
253
|
+
const {
|
|
254
|
+
inputFocused
|
|
255
|
+
} = this.state;
|
|
158
256
|
const {
|
|
159
257
|
disabled,
|
|
160
258
|
numberOfMonths,
|
|
@@ -182,64 +280,67 @@ class DSDatePickerImpl extends React2.Component {
|
|
|
182
280
|
const safedate = this.getSafeValue();
|
|
183
281
|
const safeInputValue = this.getSafeInputValue();
|
|
184
282
|
const hasSelectedDate = !!safedate;
|
|
185
|
-
return
|
|
186
|
-
rightAddon:
|
|
283
|
+
return /*#__PURE__*/_jsx(DSInputGroup, {
|
|
284
|
+
rightAddon: /*#__PURE__*/_jsx(DatePickerDropdown, {
|
|
187
285
|
pickerRef: this.state.pickerRef,
|
|
188
|
-
disabled,
|
|
286
|
+
disabled: disabled,
|
|
189
287
|
isOpen: inputFocused,
|
|
190
|
-
menu:
|
|
191
|
-
style: {
|
|
192
|
-
|
|
288
|
+
menu: /*#__PURE__*/_jsx("div", {
|
|
289
|
+
style: {
|
|
290
|
+
minHeight: '310px',
|
|
291
|
+
zIndex: 1
|
|
292
|
+
},
|
|
293
|
+
className: hasSelectedDate ? 'has-selected-date' : 'without-selected-date',
|
|
193
294
|
"data-testid": "date-picker-portal-wrapper"
|
|
194
|
-
},
|
|
295
|
+
}, void 0, /*#__PURE__*/_jsx(DSDatePickerController, {
|
|
195
296
|
date: safedate,
|
|
196
|
-
displayFormatDay,
|
|
197
|
-
enableOutsideDays,
|
|
198
|
-
firstDayOfWeek,
|
|
199
|
-
hideKeyboardShortcutsPanel,
|
|
200
|
-
isDayBlocked,
|
|
201
|
-
isDayHighlighted,
|
|
202
|
-
isOutsideRange,
|
|
203
|
-
keepOpenOnDateSelect,
|
|
204
|
-
numberOfMonths,
|
|
297
|
+
displayFormatDay: displayFormatDay,
|
|
298
|
+
enableOutsideDays: enableOutsideDays,
|
|
299
|
+
firstDayOfWeek: firstDayOfWeek,
|
|
300
|
+
hideKeyboardShortcutsPanel: hideKeyboardShortcutsPanel,
|
|
301
|
+
isDayBlocked: isDayBlocked,
|
|
302
|
+
isDayHighlighted: isDayHighlighted,
|
|
303
|
+
isOutsideRange: isOutsideRange,
|
|
304
|
+
keepOpenOnDateSelect: keepOpenOnDateSelect,
|
|
305
|
+
numberOfMonths: numberOfMonths,
|
|
205
306
|
onClickEscape: this.handleClickEscape,
|
|
206
|
-
onClose: (
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
307
|
+
onClose: function () {
|
|
308
|
+
if (_this.state.pickerRef.current) _this.state.pickerRef.current.focus();
|
|
309
|
+
onClose(...arguments);
|
|
310
|
+
|
|
311
|
+
_this.setState({
|
|
312
|
+
inputFocused: false
|
|
313
|
+
});
|
|
211
314
|
},
|
|
212
315
|
onDateChange: this.handleDateChange,
|
|
213
316
|
onFocusChange: this.handleFocus,
|
|
214
|
-
onNextMonthClick,
|
|
317
|
+
onNextMonthClick: onNextMonthClick,
|
|
215
318
|
onOutsideClick: this.handleCalendarClose,
|
|
216
|
-
onPrevMonthClick,
|
|
217
|
-
phrases,
|
|
218
|
-
transitionDuration,
|
|
219
|
-
calendarProps,
|
|
220
|
-
focusCurrentDate
|
|
319
|
+
onPrevMonthClick: onPrevMonthClick,
|
|
320
|
+
phrases: phrases,
|
|
321
|
+
transitionDuration: transitionDuration,
|
|
322
|
+
calendarProps: calendarProps,
|
|
323
|
+
focusCurrentDate: focusCurrentDate
|
|
221
324
|
})),
|
|
222
325
|
onClick: this.onClickPicker,
|
|
223
|
-
readOnly,
|
|
224
|
-
zIndex,
|
|
225
|
-
pickerProps
|
|
326
|
+
readOnly: readOnly,
|
|
327
|
+
zIndex: zIndex,
|
|
328
|
+
pickerProps: pickerProps
|
|
226
329
|
})
|
|
227
|
-
},
|
|
330
|
+
}, void 0, /*#__PURE__*/_jsx(DSDateInputV2, {
|
|
228
331
|
"data-testid": "datepicker-input",
|
|
229
|
-
"aria-label": placeholder ||
|
|
230
|
-
disabled,
|
|
332
|
+
"aria-label": placeholder || 'Date Picker Input',
|
|
333
|
+
disabled: disabled,
|
|
231
334
|
onBlur: this.handleOnBlur,
|
|
232
335
|
onChange: this.handleInputChange,
|
|
233
336
|
onDateChange: this.handleChange,
|
|
234
337
|
onFocus: this.handleInputFocus,
|
|
235
|
-
placeholder,
|
|
236
|
-
tabIndex,
|
|
338
|
+
placeholder: placeholder,
|
|
339
|
+
tabIndex: tabIndex,
|
|
237
340
|
value: safeInputValue
|
|
238
341
|
}));
|
|
239
342
|
}
|
|
343
|
+
|
|
240
344
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
DSDatePickerImpl as default
|
|
244
|
-
};
|
|
245
|
-
//# sourceMappingURL=DSDatePickerImpl.js.map
|
|
345
|
+
|
|
346
|
+
export { DSdatePickerImpl as default };
|