@@ -18,9 +18,10 @@ import {
1818 startAtIndex ,
1919 beginOffset ,
2020 estimatedMonthHeight ,
21+ isDateWithinOptionalRange ,
2122} from './dateUtils'
2223import { getCalendarHeaderHeight } from './CalendarHeader'
23- import { ModeType } from './Calendar'
24+ import type { ModeType , ValidRangeType } from './Calendar'
2425import { dayNamesHeight } from './DayNames'
2526import { useTextColorOnPrimary } from '../utils'
2627
@@ -40,6 +41,7 @@ interface BaseMonthProps {
4041 primaryColor : string
4142 selectColor : string
4243 roundness : number
44+ validRange ?: ValidRangeType
4345}
4446
4547interface MonthRangeProps extends BaseMonthProps {
@@ -82,6 +84,7 @@ function Month({
8284 locale,
8385 // @ts -ignore
8486 dates,
87+ validRange,
8588} :
8689 | MonthSingleProps
8790 | MonthRangeProps
@@ -92,6 +95,16 @@ function Month({
9295 const realIndex = getRealIndex ( index )
9396 const isHorizontal = scrollMode === 'horizontal'
9497
98+ const validRangeStart =
99+ validRange ?. startDate instanceof Date
100+ ? validRange ?. startDate ?. toISOString ( )
101+ : null
102+
103+ const validRangeEnd =
104+ validRange ?. endDate instanceof Date
105+ ? validRange ?. endDate ?. toISOString ( )
106+ : null
107+
95108 const { monthName, month, year } = React . useMemo ( ( ) => {
96109 const md = addMonths ( new Date ( ) , realIndex )
97110 const y = md . getFullYear ( )
@@ -125,6 +138,11 @@ function Month({
125138 const selectedEndDay = areDatesOnSameDay ( day , endDate )
126139 const selectedDay = areDatesOnSameDay ( day , date )
127140
141+ const isWithinOptionalValidRange = isDateWithinOptionalRange ( day , {
142+ startDate : validRangeStart ? new Date ( validRangeStart ) : undefined ,
143+ endDate : validRangeEnd ? new Date ( validRangeEnd ) : undefined ,
144+ } )
145+
128146 const multiDates = dates as Date [ ] | undefined
129147
130148 const selectedMultiDay = ! ! multiDates ?. some ( ( d ) =>
@@ -151,6 +169,10 @@ function Month({
151169 disabled = false
152170 }
153171
172+ if ( ! isWithinOptionalValidRange ) {
173+ disabled = true
174+ }
175+
154176 let leftCrop : boolean = selectedStartDay || dayOfMonth === 1
155177 let rightCrop : boolean = selectedEndDay || dayOfMonth === daysInMonth
156178
@@ -208,7 +230,19 @@ function Month({
208230 } ) ,
209231 }
210232 } )
211- } , [ year , month , index , startDate , endDate , date , dates , mode , excludedDates ] )
233+ } , [
234+ year ,
235+ month ,
236+ index ,
237+ startDate ,
238+ endDate ,
239+ date ,
240+ validRangeStart ,
241+ validRangeEnd ,
242+ dates ,
243+ mode ,
244+ excludedDates ,
245+ ] )
212246
213247 return (
214248 < View style = { [ styles . month , { height : getMonthHeight ( scrollMode , index ) } ] } >
0 commit comments