Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 02e0f49

Browse files
committed
Add capability to set fixedHeight (constant 6 rows view)
1 parent c4633ed commit 02e0f49

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/components/Calendar/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ Calendar.defaultProps = {
528528
endDatePlaceholder: 'Continuous',
529529
editableDateInputs: false,
530530
dragSelectionEnabled: true,
531+
fixedHeight: false,
531532
};
532533

533534
Calendar.propTypes = {
@@ -579,6 +580,7 @@ Calendar.propTypes = {
579580
rangeColors: PropTypes.arrayOf(PropTypes.string),
580581
editableDateInputs: PropTypes.bool,
581582
dragSelectionEnabled: PropTypes.bool,
583+
fixedHeight: PropTypes.bool,
582584
};
583585

584586
export default Calendar;

src/components/Month/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class Month extends PureComponent {
3939
const { displayMode, focusedRange, drag, styles, disabledDates } = this.props;
4040
const minDate = this.props.minDate && startOfDay(this.props.minDate);
4141
const maxDate = this.props.maxDate && endOfDay(this.props.maxDate);
42-
const monthDisplay = getMonthDisplayRange(this.props.month, this.props.dateOptions);
42+
const monthDisplay = getMonthDisplayRange(
43+
this.props.month,
44+
this.props.dateOptions,
45+
this.props.fixedHeight
46+
);
4347
let ranges = this.props.ranges;
4448
if (displayMode === 'dateRange' && drag.status) {
4549
let { startDate, endDate } = drag.range;
@@ -136,6 +140,7 @@ Month.propTypes = {
136140
dayDisplayFormat: PropTypes.string,
137141
showWeekDays: PropTypes.bool,
138142
showMonthName: PropTypes.bool,
143+
fixedHeight: PropTypes.bool,
139144
};
140145

141146
export default Month;

src/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
endOfMonth,
77
startOfWeek,
88
endOfWeek,
9+
differenceInCalendarDays,
10+
addDays,
911
} from 'date-fns';
1012

1113
export function calcFocusDate(currentFocusedDate, props) {
@@ -52,11 +54,14 @@ export function findNextRangeIndex(ranges, currentRangeIndex = -1) {
5254
return ranges.findIndex(range => range.autoFocus !== false && !range.disabled);
5355
}
5456

55-
export function getMonthDisplayRange(date, dateOptions) {
57+
export function getMonthDisplayRange(date, dateOptions, fixedHeight) {
5658
const startDateOfMonth = startOfMonth(date, dateOptions);
5759
const endDateOfMonth = endOfMonth(date, dateOptions);
5860
const startDateOfCalendar = startOfWeek(startDateOfMonth, dateOptions);
59-
const endDateOfCalendar = endOfWeek(endDateOfMonth, dateOptions);
61+
let endDateOfCalendar = endOfWeek(endDateOfMonth, dateOptions);
62+
if (fixedHeight && differenceInCalendarDays(endDateOfCalendar, startDateOfCalendar) <= 34) {
63+
endDateOfCalendar = addDays(endDateOfCalendar, 7);
64+
}
6065
return {
6166
start: startDateOfCalendar,
6267
end: endDateOfCalendar,

0 commit comments

Comments
 (0)