@birdnet/advanced-react-dates 0.0.0-stage → 1.0.0
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/.babelrc +67 -0
- package/.eslintrc +66 -0
- package/.nvmrc +1 -0
- package/.nyc_output/4d8efcd220c2aec1f2b4ffd49d875001.json +1 -0
- package/.nyc_output/66d34779498a5d49bcf9d757dfc7fdb5.json +1 -0
- package/.nyc_output/8ca7e04140934515928bc7d4ae476b73.json +1 -0
- package/.nyc_output/afc270bb597bfc50e690436959c2ae54.json +1 -0
- package/.nycrc +19 -0
- package/.travis.yml +13 -0
- package/CHANGELOG.md +665 -0
- package/CLAUDE.md +56 -0
- package/INTHEWILD.md +9 -0
- package/LICENSE +21 -0
- package/README.md +421 -2
- package/constants.js +2 -0
- package/esm/components/CalendarDay.js +321 -0
- package/esm/components/CalendarIcon.js +11 -0
- package/esm/components/CalendarMonth.js +254 -0
- package/esm/components/CalendarMonthGrid.js +365 -0
- package/esm/components/CalendarWeek.js +11 -0
- package/esm/components/ChevronDown.js +11 -0
- package/esm/components/ChevronUp.js +11 -0
- package/esm/components/CloseButton.js +12 -0
- package/esm/components/CustomizableCalendarDay.js +341 -0
- package/esm/components/DateInput.js +344 -0
- package/esm/components/DateRangePicker.js +647 -0
- package/esm/components/DateRangePickerInput.js +341 -0
- package/esm/components/DateRangePickerInputController.js +348 -0
- package/esm/components/DayPicker.js +1167 -0
- package/esm/components/DayPickerKeyboardShortcuts.js +364 -0
- package/esm/components/DayPickerNavigation.js +314 -0
- package/esm/components/DayPickerRangeController.js +1202 -0
- package/esm/components/DayPickerSingleDateController.js +690 -0
- package/esm/components/KeyboardShortcutRow.js +69 -0
- package/esm/components/LeftArrow.js +11 -0
- package/esm/components/RightArrow.js +11 -0
- package/esm/components/SingleDatePicker.js +605 -0
- package/esm/components/SingleDatePickerInput.js +264 -0
- package/esm/components/SingleDatePickerInputController.js +260 -0
- package/esm/constants.js +28 -0
- package/esm/defaultPhrases.js +225 -0
- package/esm/index.js +20 -0
- package/esm/initialize.js +2 -0
- package/esm/shapes/AnchorDirectionShape.js +3 -0
- package/esm/shapes/CalendarInfoPositionShape.js +3 -0
- package/esm/shapes/DateRangePickerShape.js +101 -0
- package/esm/shapes/DayOfWeekShape.js +3 -0
- package/esm/shapes/DisabledShape.js +3 -0
- package/esm/shapes/FocusedInputShape.js +3 -0
- package/esm/shapes/IconPositionShape.js +3 -0
- package/esm/shapes/ModifiersShape.js +18 -0
- package/esm/shapes/NavPositionShape.js +3 -0
- package/esm/shapes/OpenDirectionShape.js +3 -0
- package/esm/shapes/OrientationShape.js +3 -0
- package/esm/shapes/ScrollableOrientationShape.js +3 -0
- package/esm/shapes/SingleDatePickerShape.js +90 -0
- package/esm/theme/DefaultTheme.js +176 -0
- package/esm/utils/calculateDimension.js +28 -0
- package/esm/utils/disableScroll.js +67 -0
- package/esm/utils/getActiveElement.js +3 -0
- package/esm/utils/getCalendarDaySettings.js +48 -0
- package/esm/utils/getCalendarMonthWeeks.js +37 -0
- package/esm/utils/getCalendarMonthWidth.js +4 -0
- package/esm/utils/getDetachedContainerStyles.js +36 -0
- package/esm/utils/getInputHeight.js +42 -0
- package/esm/utils/getNumberOfCalendarMonthWeeks.js +11 -0
- package/esm/utils/getPhrase.js +7 -0
- package/esm/utils/getPhrasePropTypes.js +9 -0
- package/esm/utils/getPooledMoment.js +8 -0
- package/esm/utils/getPreviousMonthMemoLast.js +9 -0
- package/esm/utils/getResponsiveContainerStyles.js +8 -0
- package/esm/utils/getSelectedDateOffset.js +8 -0
- package/esm/utils/getTransformStyles.js +8 -0
- package/esm/utils/getVisibleDays.js +42 -0
- package/esm/utils/isAfterDay.js +7 -0
- package/esm/utils/isBeforeDay.js +13 -0
- package/esm/utils/isDayVisible.js +38 -0
- package/esm/utils/isInclusivelyAfterDay.js +6 -0
- package/esm/utils/isInclusivelyBeforeDay.js +6 -0
- package/esm/utils/isNextDay.js +7 -0
- package/esm/utils/isNextMonth.js +6 -0
- package/esm/utils/isPrevMonth.js +6 -0
- package/esm/utils/isPreviousDay.js +7 -0
- package/esm/utils/isSameDay.js +7 -0
- package/esm/utils/isSameMonth.js +7 -0
- package/esm/utils/isTransitionEndSupported.js +3 -0
- package/esm/utils/modifiers.js +94 -0
- package/esm/utils/noflip.js +10 -0
- package/esm/utils/registerCSSInterfaceWithDefaultTheme.js +5 -0
- package/esm/utils/registerInterfaceWithDefaultTheme.js +6 -0
- package/esm/utils/toISODateString.js +12 -0
- package/esm/utils/toISOMonthString.js +12 -0
- package/esm/utils/toLocalizedDateString.js +8 -0
- package/esm/utils/toMomentObject.js +7 -0
- package/index.js +2 -0
- package/initialize.js +2 -0
- package/karma.conf.js +82 -0
- package/lib/components/CalendarDay.js +327 -0
- package/lib/components/CalendarIcon.js +18 -0
- package/lib/components/CalendarMonth.js +259 -0
- package/lib/components/CalendarMonthGrid.js +372 -0
- package/lib/components/CalendarWeek.js +18 -0
- package/lib/components/ChevronDown.js +18 -0
- package/lib/components/ChevronUp.js +18 -0
- package/lib/components/CloseButton.js +19 -0
- package/lib/components/CustomizableCalendarDay.js +347 -0
- package/lib/components/DateInput.js +351 -0
- package/lib/components/DateRangePicker.js +653 -0
- package/lib/components/DateRangePickerInput.js +348 -0
- package/lib/components/DateRangePickerInputController.js +354 -0
- package/lib/components/DayPicker.js +1175 -0
- package/lib/components/DayPickerKeyboardShortcuts.js +371 -0
- package/lib/components/DayPickerNavigation.js +321 -0
- package/lib/components/DayPickerRangeController.js +1208 -0
- package/lib/components/DayPickerSingleDateController.js +695 -0
- package/lib/components/KeyboardShortcutRow.js +76 -0
- package/lib/components/LeftArrow.js +18 -0
- package/lib/components/RightArrow.js +18 -0
- package/lib/components/SingleDatePicker.js +611 -0
- package/lib/components/SingleDatePickerInput.js +271 -0
- package/lib/components/SingleDatePickerInputController.js +266 -0
- package/lib/constants.js +34 -0
- package/lib/css/_datepicker.css +886 -0
- package/lib/defaultPhrases.js +231 -0
- package/lib/index.js +146 -0
- package/lib/initialize.js +5 -0
- package/lib/shapes/AnchorDirectionShape.js +10 -0
- package/lib/shapes/CalendarInfoPositionShape.js +10 -0
- package/lib/shapes/DateRangePickerShape.js +108 -0
- package/lib/shapes/DayOfWeekShape.js +10 -0
- package/lib/shapes/DisabledShape.js +10 -0
- package/lib/shapes/FocusedInputShape.js +10 -0
- package/lib/shapes/IconPositionShape.js +10 -0
- package/lib/shapes/ModifiersShape.js +25 -0
- package/lib/shapes/NavPositionShape.js +10 -0
- package/lib/shapes/OpenDirectionShape.js +10 -0
- package/lib/shapes/OrientationShape.js +10 -0
- package/lib/shapes/ScrollableOrientationShape.js +10 -0
- package/lib/shapes/SingleDatePickerShape.js +97 -0
- package/lib/theme/DefaultTheme.js +182 -0
- package/lib/utils/calculateDimension.js +34 -0
- package/lib/utils/disableScroll.js +75 -0
- package/lib/utils/getActiveElement.js +9 -0
- package/lib/utils/getCalendarDaySettings.js +55 -0
- package/lib/utils/getCalendarMonthWeeks.js +44 -0
- package/lib/utils/getCalendarMonthWidth.js +10 -0
- package/lib/utils/getDetachedContainerStyles.js +41 -0
- package/lib/utils/getInputHeight.js +48 -0
- package/lib/utils/getNumberOfCalendarMonthWeeks.js +18 -0
- package/lib/utils/getPhrase.js +13 -0
- package/lib/utils/getPhrasePropTypes.js +16 -0
- package/lib/utils/getPooledMoment.js +15 -0
- package/lib/utils/getPreviousMonthMemoLast.js +15 -0
- package/lib/utils/getResponsiveContainerStyles.js +15 -0
- package/lib/utils/getSelectedDateOffset.js +14 -0
- package/lib/utils/getTransformStyles.js +14 -0
- package/lib/utils/getVisibleDays.js +49 -0
- package/lib/utils/isAfterDay.js +14 -0
- package/lib/utils/isBeforeDay.js +20 -0
- package/lib/utils/isDayVisible.js +45 -0
- package/lib/utils/isInclusivelyAfterDay.js +13 -0
- package/lib/utils/isInclusivelyBeforeDay.js +13 -0
- package/lib/utils/isNextDay.js +14 -0
- package/lib/utils/isNextMonth.js +13 -0
- package/lib/utils/isPrevMonth.js +13 -0
- package/lib/utils/isPreviousDay.js +14 -0
- package/lib/utils/isSameDay.js +14 -0
- package/lib/utils/isSameMonth.js +14 -0
- package/lib/utils/isTransitionEndSupported.js +9 -0
- package/lib/utils/modifiers.js +102 -0
- package/lib/utils/noflip.js +16 -0
- package/lib/utils/registerCSSInterfaceWithDefaultTheme.js +12 -0
- package/lib/utils/registerInterfaceWithDefaultTheme.js +13 -0
- package/lib/utils/toISODateString.js +19 -0
- package/lib/utils/toISOMonthString.js +19 -0
- package/lib/utils/toLocalizedDateString.js +15 -0
- package/lib/utils/toMomentObject.js +14 -0
- package/package.json +141 -4
- package/scripts/.eslintrc +7 -0
- package/scripts/buildCSS.js +37 -0
- package/scripts/pure-component-fallback.js +70 -0
- package/scripts/renderAllComponents.jsx +25 -0
- package/src/components/CalendarDay.jsx +366 -0
- package/src/components/CalendarIcon.jsx +3 -0
- package/src/components/CalendarMonth.jsx +300 -0
- package/src/components/CalendarMonthGrid.jsx +427 -0
- package/src/components/CalendarWeek.jsx +17 -0
- package/src/components/ChevronDown.jsx +3 -0
- package/src/components/ChevronUp.jsx +3 -0
- package/src/components/CloseButton.jsx +3 -0
- package/src/components/CustomizableCalendarDay.jsx +382 -0
- package/src/components/DateInput.jsx +401 -0
- package/src/components/DateRangePicker.jsx +777 -0
- package/src/components/DateRangePickerInput.jsx +434 -0
- package/src/components/DateRangePickerInputController.jsx +379 -0
- package/src/components/DayPicker.jsx +1407 -0
- package/src/components/DayPickerKeyboardShortcuts.jsx +443 -0
- package/src/components/DayPickerNavigation.jsx +445 -0
- package/src/components/DayPickerRangeController.jsx +1409 -0
- package/src/components/DayPickerSingleDateController.jsx +769 -0
- package/src/components/KeyboardShortcutRow.jsx +93 -0
- package/src/components/LeftArrow.jsx +3 -0
- package/src/components/RightArrow.jsx +3 -0
- package/src/components/SingleDatePicker.jsx +731 -0
- package/src/components/SingleDatePickerInput.jsx +329 -0
- package/src/components/SingleDatePickerInputController.jsx +280 -0
- package/src/constants.js +37 -0
- package/src/defaultPhrases.js +215 -0
- package/src/index.js +20 -0
- package/src/initialize.js +3 -0
- package/src/shapes/AnchorDirectionShape.js +8 -0
- package/src/shapes/CalendarInfoPositionShape.js +15 -0
- package/src/shapes/DateRangePickerShape.js +111 -0
- package/src/shapes/DayOfWeekShape.js +5 -0
- package/src/shapes/DisabledShape.js +5 -0
- package/src/shapes/FocusedInputShape.js +8 -0
- package/src/shapes/IconPositionShape.js +8 -0
- package/src/shapes/ModifiersShape.js +20 -0
- package/src/shapes/NavPositionShape.js +8 -0
- package/src/shapes/OpenDirectionShape.js +8 -0
- package/src/shapes/OrientationShape.js +8 -0
- package/src/shapes/ScrollableOrientationShape.js +13 -0
- package/src/shapes/SingleDatePickerShape.js +100 -0
- package/src/svg/arrow-left.svg +1 -0
- package/src/svg/arrow-right.svg +1 -0
- package/src/svg/calendar.svg +1 -0
- package/src/svg/chevron-down.svg +1 -0
- package/src/svg/chevron-up.svg +1 -0
- package/src/svg/close.svg +1 -0
- package/src/theme/DefaultTheme.js +196 -0
- package/src/utils/calculateDimension.js +32 -0
- package/src/utils/disableScroll.js +65 -0
- package/src/utils/getActiveElement.js +3 -0
- package/src/utils/getCalendarDaySettings.js +61 -0
- package/src/utils/getCalendarMonthWeeks.js +49 -0
- package/src/utils/getCalendarMonthWidth.js +3 -0
- package/src/utils/getDetachedContainerStyles.js +39 -0
- package/src/utils/getInputHeight.js +67 -0
- package/src/utils/getNumberOfCalendarMonthWeeks.js +15 -0
- package/src/utils/getPhrase.jsx +9 -0
- package/src/utils/getPhrasePropTypes.js +9 -0
- package/src/utils/getPooledMoment.js +10 -0
- package/src/utils/getPreviousMonthMemoLast.js +11 -0
- package/src/utils/getResponsiveContainerStyles.js +18 -0
- package/src/utils/getSelectedDateOffset.js +6 -0
- package/src/utils/getTransformStyles.js +8 -0
- package/src/utils/getVisibleDays.js +54 -0
- package/src/utils/isAfterDay.js +9 -0
- package/src/utils/isBeforeDay.js +18 -0
- package/src/utils/isDayVisible.js +57 -0
- package/src/utils/isInclusivelyAfterDay.js +8 -0
- package/src/utils/isInclusivelyBeforeDay.js +8 -0
- package/src/utils/isNextDay.js +9 -0
- package/src/utils/isNextMonth.js +8 -0
- package/src/utils/isPrevMonth.js +8 -0
- package/src/utils/isPreviousDay.js +9 -0
- package/src/utils/isSameDay.js +10 -0
- package/src/utils/isSameMonth.js +9 -0
- package/src/utils/isTransitionEndSupported.js +3 -0
- package/src/utils/modifiers.js +116 -0
- package/src/utils/noflip.js +11 -0
- package/src/utils/registerCSSInterfaceWithDefaultTheme.js +7 -0
- package/src/utils/registerInterfaceWithDefaultTheme.js +7 -0
- package/src/utils/toISODateString.js +14 -0
- package/src/utils/toISOMonthString.js +14 -0
- package/src/utils/toLocalizedDateString.js +12 -0
- package/src/utils/toMomentObject.js +12 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
|
|
5
|
+
import momentPropTypes from 'react-moment-proptypes';
|
|
6
|
+
import { forbidExtraProps, nonNegativeInteger } from 'airbnb-prop-types';
|
|
7
|
+
import openDirectionShape from '../shapes/OpenDirectionShape';
|
|
8
|
+
|
|
9
|
+
import { DateRangePickerInputPhrases } from '../defaultPhrases';
|
|
10
|
+
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
|
|
11
|
+
|
|
12
|
+
import DateRangePickerInput from './DateRangePickerInput';
|
|
13
|
+
|
|
14
|
+
import IconPositionShape from '../shapes/IconPositionShape';
|
|
15
|
+
import DisabledShape from '../shapes/DisabledShape';
|
|
16
|
+
|
|
17
|
+
import toMomentObject from '../utils/toMomentObject';
|
|
18
|
+
import toLocalizedDateString from '../utils/toLocalizedDateString';
|
|
19
|
+
|
|
20
|
+
import isInclusivelyAfterDay from '../utils/isInclusivelyAfterDay';
|
|
21
|
+
import isBeforeDay from '../utils/isBeforeDay';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
START_DATE,
|
|
25
|
+
END_DATE,
|
|
26
|
+
ICON_BEFORE_POSITION,
|
|
27
|
+
OPEN_DOWN,
|
|
28
|
+
} from '../constants';
|
|
29
|
+
|
|
30
|
+
const propTypes = forbidExtraProps({
|
|
31
|
+
children: PropTypes.node,
|
|
32
|
+
|
|
33
|
+
startDate: momentPropTypes.momentObj,
|
|
34
|
+
startDateId: PropTypes.string,
|
|
35
|
+
startDatePlaceholderText: PropTypes.string,
|
|
36
|
+
isStartDateFocused: PropTypes.bool,
|
|
37
|
+
startDateAriaLabel: PropTypes.string,
|
|
38
|
+
startDateTitleText: PropTypes.string,
|
|
39
|
+
|
|
40
|
+
endDate: momentPropTypes.momentObj,
|
|
41
|
+
endDateId: PropTypes.string,
|
|
42
|
+
endDatePlaceholderText: PropTypes.string,
|
|
43
|
+
isEndDateFocused: PropTypes.bool,
|
|
44
|
+
endDateAriaLabel: PropTypes.string,
|
|
45
|
+
endDateTitleText: PropTypes.string,
|
|
46
|
+
|
|
47
|
+
screenReaderMessage: PropTypes.string,
|
|
48
|
+
showClearDates: PropTypes.bool,
|
|
49
|
+
showCaret: PropTypes.bool,
|
|
50
|
+
showDefaultInputIcon: PropTypes.bool,
|
|
51
|
+
inputIconPosition: IconPositionShape,
|
|
52
|
+
disabled: DisabledShape,
|
|
53
|
+
required: PropTypes.bool,
|
|
54
|
+
readOnly: PropTypes.bool,
|
|
55
|
+
openDirection: openDirectionShape,
|
|
56
|
+
noBorder: PropTypes.bool,
|
|
57
|
+
block: PropTypes.bool,
|
|
58
|
+
small: PropTypes.bool,
|
|
59
|
+
regular: PropTypes.bool,
|
|
60
|
+
verticalSpacing: nonNegativeInteger,
|
|
61
|
+
autoComplete: PropTypes.string,
|
|
62
|
+
|
|
63
|
+
keepOpenOnDateSelect: PropTypes.bool,
|
|
64
|
+
reopenPickerOnClearDates: PropTypes.bool,
|
|
65
|
+
withFullScreenPortal: PropTypes.bool,
|
|
66
|
+
minimumNights: nonNegativeInteger,
|
|
67
|
+
isOutsideRange: PropTypes.func,
|
|
68
|
+
isDayBlocked: PropTypes.func,
|
|
69
|
+
displayFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
70
|
+
|
|
71
|
+
onFocusChange: PropTypes.func,
|
|
72
|
+
onClose: PropTypes.func,
|
|
73
|
+
onDatesChange: PropTypes.func,
|
|
74
|
+
onKeyDownArrowDown: PropTypes.func,
|
|
75
|
+
onKeyDownQuestionMark: PropTypes.func,
|
|
76
|
+
|
|
77
|
+
customInputIcon: PropTypes.node,
|
|
78
|
+
customArrowIcon: PropTypes.node,
|
|
79
|
+
customCloseIcon: PropTypes.node,
|
|
80
|
+
|
|
81
|
+
// accessibility
|
|
82
|
+
isFocused: PropTypes.bool,
|
|
83
|
+
|
|
84
|
+
// i18n
|
|
85
|
+
phrases: PropTypes.shape(getPhrasePropTypes(DateRangePickerInputPhrases)),
|
|
86
|
+
|
|
87
|
+
isRTL: PropTypes.bool,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const defaultProps = {
|
|
91
|
+
children: null,
|
|
92
|
+
|
|
93
|
+
startDate: null,
|
|
94
|
+
startDateId: START_DATE,
|
|
95
|
+
startDatePlaceholderText: 'Start Date',
|
|
96
|
+
isStartDateFocused: false,
|
|
97
|
+
startDateAriaLabel: undefined,
|
|
98
|
+
startDateTitleText: undefined,
|
|
99
|
+
|
|
100
|
+
endDate: null,
|
|
101
|
+
endDateId: END_DATE,
|
|
102
|
+
endDatePlaceholderText: 'End Date',
|
|
103
|
+
isEndDateFocused: false,
|
|
104
|
+
endDateAriaLabel: undefined,
|
|
105
|
+
endDateTitleText: undefined,
|
|
106
|
+
|
|
107
|
+
screenReaderMessage: '',
|
|
108
|
+
showClearDates: false,
|
|
109
|
+
showCaret: false,
|
|
110
|
+
showDefaultInputIcon: false,
|
|
111
|
+
inputIconPosition: ICON_BEFORE_POSITION,
|
|
112
|
+
disabled: false,
|
|
113
|
+
required: false,
|
|
114
|
+
readOnly: false,
|
|
115
|
+
openDirection: OPEN_DOWN,
|
|
116
|
+
noBorder: false,
|
|
117
|
+
block: false,
|
|
118
|
+
small: false,
|
|
119
|
+
regular: false,
|
|
120
|
+
verticalSpacing: undefined,
|
|
121
|
+
autoComplete: 'off',
|
|
122
|
+
|
|
123
|
+
keepOpenOnDateSelect: false,
|
|
124
|
+
reopenPickerOnClearDates: false,
|
|
125
|
+
withFullScreenPortal: false,
|
|
126
|
+
minimumNights: 1,
|
|
127
|
+
isOutsideRange: (day) => !isInclusivelyAfterDay(day, moment()),
|
|
128
|
+
isDayBlocked: () => false,
|
|
129
|
+
displayFormat: () => moment.localeData().longDateFormat('L'),
|
|
130
|
+
|
|
131
|
+
onFocusChange() {},
|
|
132
|
+
onClose() {},
|
|
133
|
+
onDatesChange() {},
|
|
134
|
+
onKeyDownArrowDown() {},
|
|
135
|
+
onKeyDownQuestionMark() {},
|
|
136
|
+
|
|
137
|
+
customInputIcon: null,
|
|
138
|
+
customArrowIcon: null,
|
|
139
|
+
customCloseIcon: null,
|
|
140
|
+
|
|
141
|
+
// accessibility
|
|
142
|
+
isFocused: false,
|
|
143
|
+
|
|
144
|
+
// i18n
|
|
145
|
+
phrases: DateRangePickerInputPhrases,
|
|
146
|
+
|
|
147
|
+
isRTL: false,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default class DateRangePickerInputController extends React.PureComponent {
|
|
151
|
+
constructor(props) {
|
|
152
|
+
super(props);
|
|
153
|
+
|
|
154
|
+
this.onClearFocus = this.onClearFocus.bind(this);
|
|
155
|
+
this.onStartDateChange = this.onStartDateChange.bind(this);
|
|
156
|
+
this.onStartDateFocus = this.onStartDateFocus.bind(this);
|
|
157
|
+
this.onEndDateChange = this.onEndDateChange.bind(this);
|
|
158
|
+
this.onEndDateFocus = this.onEndDateFocus.bind(this);
|
|
159
|
+
this.clearDates = this.clearDates.bind(this);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
onClearFocus() {
|
|
163
|
+
const {
|
|
164
|
+
onFocusChange,
|
|
165
|
+
onClose,
|
|
166
|
+
startDate,
|
|
167
|
+
endDate,
|
|
168
|
+
} = this.props;
|
|
169
|
+
|
|
170
|
+
onFocusChange(null);
|
|
171
|
+
onClose({ startDate, endDate });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
onEndDateChange(endDateString) {
|
|
175
|
+
const {
|
|
176
|
+
startDate,
|
|
177
|
+
isOutsideRange,
|
|
178
|
+
isDayBlocked,
|
|
179
|
+
minimumNights,
|
|
180
|
+
keepOpenOnDateSelect,
|
|
181
|
+
onDatesChange,
|
|
182
|
+
onClose,
|
|
183
|
+
onFocusChange,
|
|
184
|
+
} = this.props;
|
|
185
|
+
|
|
186
|
+
const endDate = toMomentObject(endDateString, this.getDisplayFormat());
|
|
187
|
+
|
|
188
|
+
const isEndDateValid = endDate
|
|
189
|
+
&& !isOutsideRange(endDate) && !isDayBlocked(endDate)
|
|
190
|
+
&& !(startDate && isBeforeDay(endDate, startDate.clone().add(minimumNights, 'days')));
|
|
191
|
+
if (isEndDateValid) {
|
|
192
|
+
onDatesChange({ startDate, endDate });
|
|
193
|
+
if (!keepOpenOnDateSelect) {
|
|
194
|
+
onFocusChange(null);
|
|
195
|
+
onClose({ startDate, endDate });
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
onDatesChange({
|
|
199
|
+
startDate,
|
|
200
|
+
endDate: null,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
onEndDateFocus() {
|
|
206
|
+
const {
|
|
207
|
+
startDate,
|
|
208
|
+
onFocusChange,
|
|
209
|
+
withFullScreenPortal,
|
|
210
|
+
disabled,
|
|
211
|
+
} = this.props;
|
|
212
|
+
|
|
213
|
+
if (!startDate && withFullScreenPortal && (!disabled || disabled === END_DATE)) {
|
|
214
|
+
// When the datepicker is full screen, we never want to focus the end date first
|
|
215
|
+
// because there's no indication that that is the case once the datepicker is open and it
|
|
216
|
+
// might confuse the user
|
|
217
|
+
onFocusChange(START_DATE);
|
|
218
|
+
} else if (!disabled || disabled === START_DATE) {
|
|
219
|
+
onFocusChange(END_DATE);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
onStartDateChange(startDateString) {
|
|
224
|
+
let { endDate } = this.props;
|
|
225
|
+
const {
|
|
226
|
+
isOutsideRange,
|
|
227
|
+
isDayBlocked,
|
|
228
|
+
minimumNights,
|
|
229
|
+
onDatesChange,
|
|
230
|
+
onFocusChange,
|
|
231
|
+
disabled,
|
|
232
|
+
} = this.props;
|
|
233
|
+
|
|
234
|
+
const startDate = toMomentObject(startDateString, this.getDisplayFormat());
|
|
235
|
+
const isEndDateBeforeStartDate = startDate
|
|
236
|
+
&& isBeforeDay(endDate, startDate.clone().add(minimumNights, 'days'));
|
|
237
|
+
const isStartDateValid = startDate
|
|
238
|
+
&& !isOutsideRange(startDate) && !isDayBlocked(startDate)
|
|
239
|
+
&& !(disabled === END_DATE && isEndDateBeforeStartDate);
|
|
240
|
+
|
|
241
|
+
if (isStartDateValid) {
|
|
242
|
+
if (isEndDateBeforeStartDate) {
|
|
243
|
+
endDate = null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
onDatesChange({ startDate, endDate });
|
|
247
|
+
onFocusChange(END_DATE);
|
|
248
|
+
} else {
|
|
249
|
+
onDatesChange({
|
|
250
|
+
startDate: null,
|
|
251
|
+
endDate,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
onStartDateFocus() {
|
|
257
|
+
const { disabled, onFocusChange } = this.props;
|
|
258
|
+
|
|
259
|
+
if (!disabled || disabled === END_DATE) {
|
|
260
|
+
onFocusChange(START_DATE);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
getDisplayFormat() {
|
|
265
|
+
const { displayFormat } = this.props;
|
|
266
|
+
return typeof displayFormat === 'string' ? displayFormat : displayFormat();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
getDateString(date) {
|
|
270
|
+
const displayFormat = this.getDisplayFormat();
|
|
271
|
+
if (date && displayFormat) {
|
|
272
|
+
return date && date.format(displayFormat);
|
|
273
|
+
}
|
|
274
|
+
return toLocalizedDateString(date);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
clearDates() {
|
|
278
|
+
const { onDatesChange, reopenPickerOnClearDates, onFocusChange } = this.props;
|
|
279
|
+
onDatesChange({ startDate: null, endDate: null });
|
|
280
|
+
if (reopenPickerOnClearDates) {
|
|
281
|
+
onFocusChange(START_DATE);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
render() {
|
|
286
|
+
const {
|
|
287
|
+
children,
|
|
288
|
+
startDate,
|
|
289
|
+
startDateId,
|
|
290
|
+
startDatePlaceholderText,
|
|
291
|
+
isStartDateFocused,
|
|
292
|
+
startDateAriaLabel,
|
|
293
|
+
startDateTitleText,
|
|
294
|
+
endDate,
|
|
295
|
+
endDateId,
|
|
296
|
+
endDatePlaceholderText,
|
|
297
|
+
endDateAriaLabel,
|
|
298
|
+
endDateTitleText,
|
|
299
|
+
isEndDateFocused,
|
|
300
|
+
screenReaderMessage,
|
|
301
|
+
showClearDates,
|
|
302
|
+
showCaret,
|
|
303
|
+
showDefaultInputIcon,
|
|
304
|
+
inputIconPosition,
|
|
305
|
+
customInputIcon,
|
|
306
|
+
customArrowIcon,
|
|
307
|
+
customCloseIcon,
|
|
308
|
+
disabled,
|
|
309
|
+
required,
|
|
310
|
+
readOnly,
|
|
311
|
+
openDirection,
|
|
312
|
+
isFocused,
|
|
313
|
+
phrases,
|
|
314
|
+
onKeyDownArrowDown,
|
|
315
|
+
onKeyDownQuestionMark,
|
|
316
|
+
isRTL,
|
|
317
|
+
noBorder,
|
|
318
|
+
block,
|
|
319
|
+
small,
|
|
320
|
+
regular,
|
|
321
|
+
verticalSpacing,
|
|
322
|
+
autoComplete,
|
|
323
|
+
} = this.props;
|
|
324
|
+
|
|
325
|
+
const startDateString = this.getDateString(startDate);
|
|
326
|
+
const endDateString = this.getDateString(endDate);
|
|
327
|
+
|
|
328
|
+
return (
|
|
329
|
+
<DateRangePickerInput
|
|
330
|
+
startDate={startDateString}
|
|
331
|
+
startDateId={startDateId}
|
|
332
|
+
startDatePlaceholderText={startDatePlaceholderText}
|
|
333
|
+
isStartDateFocused={isStartDateFocused}
|
|
334
|
+
startDateAriaLabel={startDateAriaLabel}
|
|
335
|
+
startDateTitleText={startDateTitleText}
|
|
336
|
+
endDate={endDateString}
|
|
337
|
+
endDateId={endDateId}
|
|
338
|
+
endDatePlaceholderText={endDatePlaceholderText}
|
|
339
|
+
isEndDateFocused={isEndDateFocused}
|
|
340
|
+
endDateAriaLabel={endDateAriaLabel}
|
|
341
|
+
endDateTitleText={endDateTitleText}
|
|
342
|
+
isFocused={isFocused}
|
|
343
|
+
disabled={disabled}
|
|
344
|
+
required={required}
|
|
345
|
+
readOnly={readOnly}
|
|
346
|
+
openDirection={openDirection}
|
|
347
|
+
showCaret={showCaret}
|
|
348
|
+
showDefaultInputIcon={showDefaultInputIcon}
|
|
349
|
+
inputIconPosition={inputIconPosition}
|
|
350
|
+
customInputIcon={customInputIcon}
|
|
351
|
+
customArrowIcon={customArrowIcon}
|
|
352
|
+
customCloseIcon={customCloseIcon}
|
|
353
|
+
phrases={phrases}
|
|
354
|
+
onStartDateChange={this.onStartDateChange}
|
|
355
|
+
onStartDateFocus={this.onStartDateFocus}
|
|
356
|
+
onStartDateShiftTab={this.onClearFocus}
|
|
357
|
+
onEndDateChange={this.onEndDateChange}
|
|
358
|
+
onEndDateFocus={this.onEndDateFocus}
|
|
359
|
+
showClearDates={showClearDates}
|
|
360
|
+
onClearDates={this.clearDates}
|
|
361
|
+
screenReaderMessage={screenReaderMessage}
|
|
362
|
+
onKeyDownArrowDown={onKeyDownArrowDown}
|
|
363
|
+
onKeyDownQuestionMark={onKeyDownQuestionMark}
|
|
364
|
+
isRTL={isRTL}
|
|
365
|
+
noBorder={noBorder}
|
|
366
|
+
block={block}
|
|
367
|
+
small={small}
|
|
368
|
+
regular={regular}
|
|
369
|
+
verticalSpacing={verticalSpacing}
|
|
370
|
+
autoComplete={autoComplete}
|
|
371
|
+
>
|
|
372
|
+
{children}
|
|
373
|
+
</DateRangePickerInput>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
DateRangePickerInputController.propTypes = propTypes;
|
|
379
|
+
DateRangePickerInputController.defaultProps = defaultProps;
|