Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default function ReadMeExampleSingle() {
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// onChange={} // same props as onConfirm but triggered without confirmed by user
// saveLabel="Save" // optional
Expand Down Expand Up @@ -149,6 +150,7 @@ export default function ReadMeExampleRange() {
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// onChange={} // same props as onConfirm but triggered without confirmed by user
// locale={'nl'} // optional
Expand Down Expand Up @@ -203,6 +205,7 @@ export default function ReadMeExampleMultiple() {
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// locale={'nl'} // optional
// saveLabel="Save" // optional
Expand Down
1 change: 1 addition & 0 deletions src/Date/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ScrollModeType = 'horizontal' | 'vertical'
export type ValidRangeType = {
startDate?: Date
endDate?: Date
disabledDates?: Date[]
}

export type BaseCalendarProps = {
Expand Down
18 changes: 17 additions & 1 deletion src/Date/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
)
: undefined

const validDisabledDates = validRange?.disabledDates
? validRange?.disabledDates
: undefined

const { monthName, month, year } = React.useMemo(() => {
const md = addMonths(new Date(), realIndex)
const y = md.getFullYear()
Expand Down Expand Up @@ -153,11 +157,22 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
let inRange = false
let disabled = false
let selected = false
let inDisabledDates = false
let leftCrop = dayOfMonth === 1
let rightCrop = dayOfMonth === daysInMonth

const isFirstDayOfMonth = dayOfMonth === 1
const isLastDayOfMonth = dayOfMonth === daysInMonth

inDisabledDates = validDisabledDates
? validDisabledDates.some((disabledDate) =>
areDatesOnSameDay(disabledDate, day)
)
: false
if (inDisabledDates) {
disabled = true
}

if (mode === 'range') {
const selectedStartDay = areDatesOnSameDay(day, startDate)
const selectedEndDay = areDatesOnSameDay(day, endDate)
Expand Down Expand Up @@ -237,7 +252,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
endUnix: validRangeEnd,
})

if (inRange) {
if (inRange && !inDisabledDates) {
disabled = false
}

Expand Down Expand Up @@ -273,6 +288,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
dates,
validRangeStart,
validRangeEnd,
validDisabledDates,
mode,
])

Expand Down