Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
add callback for onDayClick to DatePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
BeirlaenAaron committed Oct 3, 2023
1 parent 749f1e0 commit 184a013
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/datepicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import localeUtils from './localeUtils';
import { GenericComponent } from '../../@types/types';
import { SIZES } from '../../constants';

export interface DatePickerProps extends Omit<BoxProps & DayPickerProps, 'size' | 'onChange' | 'modifiers' | 'ref'> {
export interface DatePickerProps
extends Omit<BoxProps & DayPickerProps, 'size' | 'onChange' | 'modifiers' | 'ref' | 'onDayClick'> {
/** If true we give a border to our wrapper. */
bordered?: boolean;
/** A class name for the DatePicker to give custom styles. */
Expand All @@ -32,6 +33,8 @@ export interface DatePickerProps extends Omit<BoxProps & DayPickerProps, 'size'
showWeekNumbers?: boolean;
/** The initial month to display if no date is selected. */
initialMonth?: Date;
/** Callback function that is fired when a day is clicked. */
onDayClick?: (day: Date, modifiers: DayModifiers, event: React.MouseEvent<HTMLDivElement>) => void;
}

const DatePicker: GenericComponent<DatePickerProps> = ({
Expand All @@ -43,6 +46,7 @@ const DatePicker: GenericComponent<DatePickerProps> = ({
showWeekNumbers,
initialMonth,
onChange,
onDayClick,
...others
}) => {
const [selectedDate, setSelectedDate] = useState<Date | undefined>(others.selectedDate);
Expand All @@ -53,13 +57,14 @@ const DatePicker: GenericComponent<DatePickerProps> = ({
setSelectedMonth(others.selectedDate);
}, [others.selectedDate]);

const handleDayClick = (day: Date, modifiers: DayModifiers) => {
const handleDayClick = (day: Date, modifiers: DayModifiers, event: React.MouseEvent<HTMLDivElement>) => {
if (modifiers[theme['disabled']]) {
return;
}

setSelectedDate(day);
onChange && onChange(day);
onDayClick && onDayClick(day, modifiers, event);
};

const handleYearMonthChange = (selectedMonth: Date) => {
Expand Down

0 comments on commit 184a013

Please sign in to comment.