Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit efd2506

Browse files
committed
feat: Add support for custom function in disabledDates (#60)
1 parent 6dabd59 commit efd2506

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ interface Vue3DatePicker {
111111
};
112112
disableMonthYearSelect?: boolean;
113113
yearRange?: number[];
114-
disabledDates?: Date[] | string[];
114+
disabledDates?: Date[] | string[] | ((date: Date) => boolean);
115115
inline?: boolean;
116116
selectText?: string;
117117
cancelText?: string;

src/Vue3DatePicker/Vue3DatePicker.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
WeekStartStr,
144144
IMarker,
145145
ITransition,
146+
IDisableDates,
146147
} from './interfaces';
147148
import { getDateHours, getDateMinutes, getDateSeconds, getDefaultPattern, isValidTime } from './utils/date-utils';
148149
import { getDefaultTextInputOptions, getDefaultFilters, mergeDefaultTransitions } from './utils/util';
@@ -210,7 +211,7 @@
210211
filters: { type: Object as PropType<IDateFilter>, default: () => ({}) },
211212
disableMonthYearSelect: { type: Boolean as PropType<boolean>, default: false },
212213
yearRange: { type: Array as PropType<number[]>, default: () => [1900, 2100] },
213-
disabledDates: { type: Array as PropType<Date[] | string[]>, default: () => [] },
214+
disabledDates: { type: [Array, Function] as PropType<Date[] | string[] | IDisableDates>, default: () => [] },
214215
disabledWeekDays: { type: Array as PropType<string[] | number[]>, default: () => [] },
215216
inline: { type: Boolean as PropType<boolean>, default: false },
216217
selectText: { type: String as PropType<string>, default: 'Select' },

src/Vue3DatePicker/components/DatepickerMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
ICalendarDate,
9393
IDateFilter,
9494
IDefaultSelect,
95+
IDisableDates,
9596
IFormat,
9697
IMarker,
9798
InternalModuleValue,
@@ -143,7 +144,7 @@
143144
},
144145
locale: { type: String as PropType<string>, default: 'en-US' },
145146
weekNumName: { type: String as PropType<string>, default: 'W' },
146-
disabledDates: { type: Array as PropType<Date[] | string[]>, default: () => [] },
147+
disabledDates: { type: [Array, Function] as PropType<Date[] | string[] | IDisableDates>, default: () => [] },
147148
filters: { type: Object as PropType<IDateFilter>, default: () => ({}) },
148149
minTime: { type: Object as PropType<ITimeValue>, default: null },
149150
maxTime: { type: Object as PropType<ITimeValue>, default: null },

src/Vue3DatePicker/components/composition/calendar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ export const useCalendar = (props: UseCalendar, emit: VueEmit): IUseCalendar =>
133133
const isDisabled = (date: Date): boolean => {
134134
const aboveMax = props.maxDate ? isDateAfter(date, props.maxDate) : false;
135135
const bellowMin = props.minDate ? isDateBefore(date, props.minDate) : false;
136-
const inDisableArr = props.disabledDates.some((disabledDate: Date | string) => isDateEqual(disabledDate, date));
136+
const inDisableArr =
137+
typeof props.disabledDates === 'function'
138+
? props.disabledDates(date)
139+
: props.disabledDates.some((disabledDate: Date | string) => isDateEqual(disabledDate, date));
137140
const disabledMonths = props.filters.months.length ? props.filters.months.map((month) => +month) : [];
138141
const inDisabledMonths = disabledMonths.includes(getDateMonth(date));
139142
const weekDayDisabled = props.disabledWeekDays.length

src/Vue3DatePicker/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export type UseCalendar = {
8686
minDate: Date | string;
8787
filters: IDateFilter;
8888
yearRange: number[];
89-
disabledDates: string[] | Date[];
89+
disabledDates: Date[] | string[] | IDisableDates;
9090
autoApply: boolean;
9191
monthPicker: boolean;
9292
timePicker: boolean;
@@ -140,5 +140,5 @@ export interface ITransition {
140140
next: string;
141141
previous: string;
142142
}
143-
143+
export type IDisableDates = (date: Date) => boolean;
144144
export type ITimeType = 'hours' | 'minutes' | 'seconds';

0 commit comments

Comments
 (0)