@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,427 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import momentPropTypes from 'react-moment-proptypes';
|
|
4
|
+
import { forbidExtraProps, mutuallyExclusiveProps, nonNegativeInteger } from 'airbnb-prop-types';
|
|
5
|
+
import { withStyles, withStylesPropTypes } from 'react-with-styles';
|
|
6
|
+
import moment from 'moment';
|
|
7
|
+
import { addEventListener } from 'consolidated-events';
|
|
8
|
+
|
|
9
|
+
import { CalendarDayPhrases } from '../defaultPhrases';
|
|
10
|
+
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
|
|
11
|
+
import noflip from '../utils/noflip';
|
|
12
|
+
|
|
13
|
+
import CalendarMonth from './CalendarMonth';
|
|
14
|
+
|
|
15
|
+
import isTransitionEndSupported from '../utils/isTransitionEndSupported';
|
|
16
|
+
import getTransformStyles from '../utils/getTransformStyles';
|
|
17
|
+
import getCalendarMonthWidth from '../utils/getCalendarMonthWidth';
|
|
18
|
+
import toISOMonthString from '../utils/toISOMonthString';
|
|
19
|
+
import isPrevMonth from '../utils/isPrevMonth';
|
|
20
|
+
import isNextMonth from '../utils/isNextMonth';
|
|
21
|
+
|
|
22
|
+
import ModifiersShape from '../shapes/ModifiersShape';
|
|
23
|
+
import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
|
|
24
|
+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
HORIZONTAL_ORIENTATION,
|
|
28
|
+
VERTICAL_ORIENTATION,
|
|
29
|
+
VERTICAL_SCROLLABLE,
|
|
30
|
+
DAY_SIZE,
|
|
31
|
+
} from '../constants';
|
|
32
|
+
|
|
33
|
+
const propTypes = forbidExtraProps({
|
|
34
|
+
...withStylesPropTypes,
|
|
35
|
+
enableOutsideDays: PropTypes.bool,
|
|
36
|
+
firstVisibleMonthIndex: PropTypes.number,
|
|
37
|
+
horizontalMonthPadding: nonNegativeInteger,
|
|
38
|
+
initialMonth: momentPropTypes.momentObj,
|
|
39
|
+
isAnimating: PropTypes.bool,
|
|
40
|
+
numberOfMonths: PropTypes.number,
|
|
41
|
+
modifiers: PropTypes.objectOf(PropTypes.objectOf(ModifiersShape)),
|
|
42
|
+
orientation: ScrollableOrientationShape,
|
|
43
|
+
onDayClick: PropTypes.func,
|
|
44
|
+
onDayMouseEnter: PropTypes.func,
|
|
45
|
+
onDayMouseLeave: PropTypes.func,
|
|
46
|
+
onMonthTransitionEnd: PropTypes.func,
|
|
47
|
+
onMonthChange: PropTypes.func,
|
|
48
|
+
onYearChange: PropTypes.func,
|
|
49
|
+
renderMonthText: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'),
|
|
50
|
+
renderCalendarDay: PropTypes.func,
|
|
51
|
+
renderDayContents: PropTypes.func,
|
|
52
|
+
translationValue: PropTypes.number,
|
|
53
|
+
renderMonthElement: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'),
|
|
54
|
+
daySize: nonNegativeInteger,
|
|
55
|
+
focusedDate: momentPropTypes.momentObj, // indicates focusable day
|
|
56
|
+
isFocused: PropTypes.bool, // indicates whether or not to move focus to focusable day
|
|
57
|
+
firstDayOfWeek: DayOfWeekShape,
|
|
58
|
+
setMonthTitleHeight: PropTypes.func,
|
|
59
|
+
isRTL: PropTypes.bool,
|
|
60
|
+
transitionDuration: nonNegativeInteger,
|
|
61
|
+
verticalBorderSpacing: nonNegativeInteger,
|
|
62
|
+
|
|
63
|
+
// i18n
|
|
64
|
+
monthFormat: PropTypes.string,
|
|
65
|
+
phrases: PropTypes.shape(getPhrasePropTypes(CalendarDayPhrases)),
|
|
66
|
+
dayAriaLabelFormat: PropTypes.string,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const defaultProps = {
|
|
70
|
+
enableOutsideDays: false,
|
|
71
|
+
firstVisibleMonthIndex: 0,
|
|
72
|
+
horizontalMonthPadding: 13,
|
|
73
|
+
initialMonth: moment(),
|
|
74
|
+
isAnimating: false,
|
|
75
|
+
numberOfMonths: 1,
|
|
76
|
+
modifiers: {},
|
|
77
|
+
orientation: HORIZONTAL_ORIENTATION,
|
|
78
|
+
onDayClick() {},
|
|
79
|
+
onDayMouseEnter() {},
|
|
80
|
+
onDayMouseLeave() {},
|
|
81
|
+
onMonthChange() {},
|
|
82
|
+
onYearChange() {},
|
|
83
|
+
onMonthTransitionEnd() {},
|
|
84
|
+
renderMonthText: null,
|
|
85
|
+
renderCalendarDay: undefined,
|
|
86
|
+
renderDayContents: null,
|
|
87
|
+
translationValue: null,
|
|
88
|
+
renderMonthElement: null,
|
|
89
|
+
daySize: DAY_SIZE,
|
|
90
|
+
focusedDate: null,
|
|
91
|
+
isFocused: false,
|
|
92
|
+
firstDayOfWeek: null,
|
|
93
|
+
setMonthTitleHeight: null,
|
|
94
|
+
isRTL: false,
|
|
95
|
+
transitionDuration: 200,
|
|
96
|
+
verticalBorderSpacing: undefined,
|
|
97
|
+
|
|
98
|
+
// i18n
|
|
99
|
+
monthFormat: 'MMMM YYYY', // english locale
|
|
100
|
+
phrases: CalendarDayPhrases,
|
|
101
|
+
dayAriaLabelFormat: undefined,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function getMonths(initialMonth, numberOfMonths, withoutTransitionMonths) {
|
|
105
|
+
let month = initialMonth.clone();
|
|
106
|
+
if (!withoutTransitionMonths) month = month.subtract(1, 'month');
|
|
107
|
+
|
|
108
|
+
const months = [];
|
|
109
|
+
for (let i = 0; i < (withoutTransitionMonths ? numberOfMonths : numberOfMonths + 2); i += 1) {
|
|
110
|
+
months.push(month);
|
|
111
|
+
month = month.clone().add(1, 'month');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return months;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class CalendarMonthGrid extends React.PureComponent {
|
|
118
|
+
constructor(props) {
|
|
119
|
+
super(props);
|
|
120
|
+
const withoutTransitionMonths = props.orientation === VERTICAL_SCROLLABLE;
|
|
121
|
+
this.state = {
|
|
122
|
+
months: getMonths(props.initialMonth, props.numberOfMonths, withoutTransitionMonths),
|
|
123
|
+
initialMonth: props.initialMonth,
|
|
124
|
+
numberOfMonths: props.numberOfMonths,
|
|
125
|
+
locale: moment.locale(),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
this.isTransitionEndSupported = isTransitionEndSupported();
|
|
129
|
+
this.onTransitionEnd = this.onTransitionEnd.bind(this);
|
|
130
|
+
this.setContainerRef = this.setContainerRef.bind(this);
|
|
131
|
+
|
|
132
|
+
this.onMonthSelect = this.onMonthSelect.bind(this);
|
|
133
|
+
this.onYearSelect = this.onYearSelect.bind(this);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
componentDidMount() {
|
|
137
|
+
this.removeEventListener = addEventListener(
|
|
138
|
+
this.container,
|
|
139
|
+
'transitionend',
|
|
140
|
+
this.onTransitionEnd,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static getDerivedStateFromProps(props, state) {
|
|
145
|
+
const { initialMonth, numberOfMonths, orientation } = props;
|
|
146
|
+
const {
|
|
147
|
+
months,
|
|
148
|
+
initialMonth: prevInitialMonth,
|
|
149
|
+
numberOfMonths: prevNumberOfMonths,
|
|
150
|
+
locale: prevLocale,
|
|
151
|
+
} = state;
|
|
152
|
+
|
|
153
|
+
const hasMonthChanged = !prevInitialMonth.isSame(initialMonth, 'month');
|
|
154
|
+
const hasNumberOfMonthsChanged = prevNumberOfMonths !== numberOfMonths;
|
|
155
|
+
let newMonths = months;
|
|
156
|
+
|
|
157
|
+
if (hasMonthChanged || hasNumberOfMonthsChanged) {
|
|
158
|
+
if (hasMonthChanged && !hasNumberOfMonthsChanged) {
|
|
159
|
+
if (isNextMonth(prevInitialMonth, initialMonth)) {
|
|
160
|
+
newMonths = months.slice(1);
|
|
161
|
+
newMonths.push(months[months.length - 1].clone().add(1, 'month'));
|
|
162
|
+
} else if (isPrevMonth(prevInitialMonth, initialMonth)) {
|
|
163
|
+
newMonths = months.slice(0, months.length - 1);
|
|
164
|
+
newMonths.unshift(months[0].clone().subtract(1, 'month'));
|
|
165
|
+
} else {
|
|
166
|
+
const withoutTransitionMonths = orientation === VERTICAL_SCROLLABLE;
|
|
167
|
+
newMonths = getMonths(initialMonth, numberOfMonths, withoutTransitionMonths);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (hasNumberOfMonthsChanged) {
|
|
172
|
+
const withoutTransitionMonths = orientation === VERTICAL_SCROLLABLE;
|
|
173
|
+
newMonths = getMonths(initialMonth, numberOfMonths, withoutTransitionMonths);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const momentLocale = moment.locale();
|
|
177
|
+
let locale = prevLocale;
|
|
178
|
+
if (locale !== momentLocale) {
|
|
179
|
+
locale = momentLocale;
|
|
180
|
+
newMonths = newMonths.map((m) => m.locale(locale));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
months: newMonths,
|
|
185
|
+
initialMonth,
|
|
186
|
+
numberOfMonths,
|
|
187
|
+
locale,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
componentDidUpdate() {
|
|
195
|
+
const {
|
|
196
|
+
isAnimating,
|
|
197
|
+
transitionDuration,
|
|
198
|
+
onMonthTransitionEnd,
|
|
199
|
+
} = this.props;
|
|
200
|
+
|
|
201
|
+
// For IE9, immediately call onMonthTransitionEnd instead of
|
|
202
|
+
// waiting for the animation to complete. Similarly, if transitionDuration
|
|
203
|
+
// is set to 0, also immediately invoke the onMonthTransitionEnd callback
|
|
204
|
+
if ((!this.isTransitionEndSupported || !transitionDuration) && isAnimating) {
|
|
205
|
+
onMonthTransitionEnd();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
componentWillUnmount() {
|
|
210
|
+
if (this.removeEventListener) this.removeEventListener();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
onTransitionEnd() {
|
|
214
|
+
const { onMonthTransitionEnd } = this.props;
|
|
215
|
+
onMonthTransitionEnd();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
onMonthSelect(currentMonth, newMonthVal) {
|
|
219
|
+
const newMonth = currentMonth.clone();
|
|
220
|
+
const { onMonthChange, orientation } = this.props;
|
|
221
|
+
const { months } = this.state;
|
|
222
|
+
const withoutTransitionMonths = orientation === VERTICAL_SCROLLABLE;
|
|
223
|
+
let initialMonthSubtraction = months.indexOf(currentMonth);
|
|
224
|
+
if (!withoutTransitionMonths) {
|
|
225
|
+
initialMonthSubtraction -= 1;
|
|
226
|
+
}
|
|
227
|
+
newMonth.set('month', newMonthVal).subtract(initialMonthSubtraction, 'months');
|
|
228
|
+
onMonthChange(newMonth);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
onYearSelect(currentMonth, newYearVal) {
|
|
232
|
+
const newMonth = currentMonth.clone();
|
|
233
|
+
const { onYearChange, orientation } = this.props;
|
|
234
|
+
const { months } = this.state;
|
|
235
|
+
const withoutTransitionMonths = orientation === VERTICAL_SCROLLABLE;
|
|
236
|
+
let initialMonthSubtraction = months.indexOf(currentMonth);
|
|
237
|
+
if (!withoutTransitionMonths) {
|
|
238
|
+
initialMonthSubtraction -= 1;
|
|
239
|
+
}
|
|
240
|
+
newMonth.set('year', newYearVal).subtract(initialMonthSubtraction, 'months');
|
|
241
|
+
onYearChange(newMonth);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
setContainerRef(ref) {
|
|
245
|
+
this.container = ref;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
render() {
|
|
249
|
+
const {
|
|
250
|
+
enableOutsideDays,
|
|
251
|
+
firstVisibleMonthIndex,
|
|
252
|
+
horizontalMonthPadding,
|
|
253
|
+
isAnimating,
|
|
254
|
+
modifiers,
|
|
255
|
+
numberOfMonths,
|
|
256
|
+
monthFormat,
|
|
257
|
+
orientation,
|
|
258
|
+
translationValue,
|
|
259
|
+
daySize,
|
|
260
|
+
onDayMouseEnter,
|
|
261
|
+
onDayMouseLeave,
|
|
262
|
+
onDayClick,
|
|
263
|
+
renderMonthText,
|
|
264
|
+
renderCalendarDay,
|
|
265
|
+
renderDayContents,
|
|
266
|
+
renderMonthElement,
|
|
267
|
+
onMonthTransitionEnd,
|
|
268
|
+
firstDayOfWeek,
|
|
269
|
+
focusedDate,
|
|
270
|
+
isFocused,
|
|
271
|
+
isRTL,
|
|
272
|
+
css,
|
|
273
|
+
styles,
|
|
274
|
+
phrases,
|
|
275
|
+
dayAriaLabelFormat,
|
|
276
|
+
transitionDuration,
|
|
277
|
+
verticalBorderSpacing,
|
|
278
|
+
setMonthTitleHeight,
|
|
279
|
+
} = this.props;
|
|
280
|
+
|
|
281
|
+
const { months } = this.state;
|
|
282
|
+
const isVertical = orientation === VERTICAL_ORIENTATION;
|
|
283
|
+
const isVerticalScrollable = orientation === VERTICAL_SCROLLABLE;
|
|
284
|
+
const isHorizontal = orientation === HORIZONTAL_ORIENTATION;
|
|
285
|
+
|
|
286
|
+
const calendarMonthWidth = getCalendarMonthWidth(
|
|
287
|
+
daySize,
|
|
288
|
+
horizontalMonthPadding,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const width = isVertical || isVerticalScrollable
|
|
292
|
+
? calendarMonthWidth
|
|
293
|
+
: (numberOfMonths + 2) * calendarMonthWidth;
|
|
294
|
+
|
|
295
|
+
const transformType = (isVertical || isVerticalScrollable) ? 'translateY' : 'translateX';
|
|
296
|
+
const transformValue = `${transformType}(${translationValue}px)`;
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<div
|
|
300
|
+
{...css(
|
|
301
|
+
styles.CalendarMonthGrid,
|
|
302
|
+
isHorizontal && styles.CalendarMonthGrid__horizontal,
|
|
303
|
+
isVertical && styles.CalendarMonthGrid__vertical,
|
|
304
|
+
isVerticalScrollable && styles.CalendarMonthGrid__vertical_scrollable,
|
|
305
|
+
isAnimating && styles.CalendarMonthGrid__animating,
|
|
306
|
+
isAnimating && transitionDuration && {
|
|
307
|
+
transition: `transform ${transitionDuration}ms ease-in-out 0.1s`,
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
...getTransformStyles(transformValue),
|
|
311
|
+
width,
|
|
312
|
+
},
|
|
313
|
+
)}
|
|
314
|
+
ref={this.setContainerRef}
|
|
315
|
+
onTransitionEnd={onMonthTransitionEnd}
|
|
316
|
+
>
|
|
317
|
+
{months.map((month, i) => {
|
|
318
|
+
const isVisible = (i >= firstVisibleMonthIndex)
|
|
319
|
+
&& (i < firstVisibleMonthIndex + numberOfMonths);
|
|
320
|
+
const hideForAnimation = i === 0 && !isVisible;
|
|
321
|
+
const showForAnimation = i === 0 && isAnimating && isVisible;
|
|
322
|
+
const monthString = toISOMonthString(month);
|
|
323
|
+
return (
|
|
324
|
+
<div
|
|
325
|
+
key={monthString}
|
|
326
|
+
{...css(
|
|
327
|
+
isHorizontal && styles.CalendarMonthGrid_month__horizontal,
|
|
328
|
+
hideForAnimation && styles.CalendarMonthGrid_month__hideForAnimation,
|
|
329
|
+
showForAnimation && !isVertical && !isRTL && {
|
|
330
|
+
position: 'absolute',
|
|
331
|
+
left: -calendarMonthWidth,
|
|
332
|
+
},
|
|
333
|
+
showForAnimation && !isVertical && isRTL && {
|
|
334
|
+
position: 'absolute',
|
|
335
|
+
right: 0,
|
|
336
|
+
},
|
|
337
|
+
showForAnimation && isVertical && {
|
|
338
|
+
position: 'absolute',
|
|
339
|
+
top: -translationValue,
|
|
340
|
+
},
|
|
341
|
+
!isVisible && !isAnimating && styles.CalendarMonthGrid_month__hidden,
|
|
342
|
+
)}
|
|
343
|
+
>
|
|
344
|
+
<CalendarMonth
|
|
345
|
+
month={month}
|
|
346
|
+
isVisible={isVisible}
|
|
347
|
+
enableOutsideDays={enableOutsideDays}
|
|
348
|
+
modifiers={modifiers[monthString]}
|
|
349
|
+
monthFormat={monthFormat}
|
|
350
|
+
orientation={orientation}
|
|
351
|
+
onDayMouseEnter={onDayMouseEnter}
|
|
352
|
+
onDayMouseLeave={onDayMouseLeave}
|
|
353
|
+
onDayClick={onDayClick}
|
|
354
|
+
onMonthSelect={this.onMonthSelect}
|
|
355
|
+
onYearSelect={this.onYearSelect}
|
|
356
|
+
renderMonthText={renderMonthText}
|
|
357
|
+
renderCalendarDay={renderCalendarDay}
|
|
358
|
+
renderDayContents={renderDayContents}
|
|
359
|
+
renderMonthElement={renderMonthElement}
|
|
360
|
+
firstDayOfWeek={firstDayOfWeek}
|
|
361
|
+
daySize={daySize}
|
|
362
|
+
focusedDate={isVisible ? focusedDate : null}
|
|
363
|
+
isFocused={isFocused}
|
|
364
|
+
phrases={phrases}
|
|
365
|
+
setMonthTitleHeight={setMonthTitleHeight}
|
|
366
|
+
dayAriaLabelFormat={dayAriaLabelFormat}
|
|
367
|
+
verticalBorderSpacing={verticalBorderSpacing}
|
|
368
|
+
horizontalMonthPadding={horizontalMonthPadding}
|
|
369
|
+
/>
|
|
370
|
+
</div>
|
|
371
|
+
);
|
|
372
|
+
})}
|
|
373
|
+
</div>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
CalendarMonthGrid.propTypes = propTypes;
|
|
379
|
+
CalendarMonthGrid.defaultProps = defaultProps;
|
|
380
|
+
|
|
381
|
+
export default withStyles(({
|
|
382
|
+
reactDates: {
|
|
383
|
+
color,
|
|
384
|
+
spacing,
|
|
385
|
+
zIndex,
|
|
386
|
+
},
|
|
387
|
+
}) => ({
|
|
388
|
+
CalendarMonthGrid: {
|
|
389
|
+
background: color.background,
|
|
390
|
+
textAlign: noflip('left'),
|
|
391
|
+
zIndex,
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
CalendarMonthGrid__animating: {
|
|
395
|
+
zIndex: zIndex + 1,
|
|
396
|
+
},
|
|
397
|
+
|
|
398
|
+
CalendarMonthGrid__horizontal: {
|
|
399
|
+
position: 'absolute',
|
|
400
|
+
left: noflip(spacing.dayPickerHorizontalPadding),
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
CalendarMonthGrid__vertical: {
|
|
404
|
+
margin: '0 auto',
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
CalendarMonthGrid__vertical_scrollable: {
|
|
408
|
+
margin: '0 auto',
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
CalendarMonthGrid_month__horizontal: {
|
|
412
|
+
display: 'inline-block',
|
|
413
|
+
verticalAlign: 'top',
|
|
414
|
+
minHeight: '100%',
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
CalendarMonthGrid_month__hideForAnimation: {
|
|
418
|
+
position: 'absolute',
|
|
419
|
+
zIndex: zIndex - 1,
|
|
420
|
+
opacity: 0,
|
|
421
|
+
pointerEvents: 'none',
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
CalendarMonthGrid_month__hidden: {
|
|
425
|
+
visibility: 'hidden',
|
|
426
|
+
},
|
|
427
|
+
}), { pureComponent: typeof React.PureComponent !== 'undefined' })(CalendarMonthGrid);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { forbidExtraProps } from 'airbnb-prop-types';
|
|
4
|
+
|
|
5
|
+
const propTypes = forbidExtraProps({
|
|
6
|
+
children: PropTypes.node.isRequired,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export default function CalendarWeek({ children }) {
|
|
10
|
+
return (
|
|
11
|
+
<tr>
|
|
12
|
+
{children}
|
|
13
|
+
</tr>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
CalendarWeek.propTypes = propTypes;
|