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

Add callback for onDayClick to DatePicker #2778

Merged
merged 4 commits into from
Oct 3, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

### Dependency updates

## [22.3.4] - 2023-10-03

### Added

`DatePicker`: `onDayClick` callback. ([@BeirlaenAaron](https://https://github.com/BeirlaenAaron) in [#2778](https://github.com/teamleadercrm/ui/pull/2778))

## [22.3.3] - 2023-09-13

- - `luxon`: Bump luxon from 3.0.3 to 3.4.3 ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2518](https://github.com/teamleadercrm/ui/pull/2764)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "22.3.3",
"version": "22.3.4",
"author": "Teamleader <development@teamleader.eu>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
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