Skip to content

Commit

Permalink
chore: remove uneeded event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed May 22, 2024
1 parent ea98ea9 commit d37159d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
24 changes: 6 additions & 18 deletions packages/blade/src/components/DatePicker/Calendar.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ const Calendar = <Type extends DateSelectionType>({
locale,
onNext,
onPrevious,
onNextMonth,
onNextYear,
onNextDecade,
onPreviousMonth,
onPreviousYear,
onPreviousDecade,
presets,
...props
}: CalendarProps<Type> & {
Expand Down Expand Up @@ -73,47 +67,41 @@ const Calendar = <Type extends DateSelectionType>({

const handleNextMonth = () => {
const nextDate = dayjs(currentDate).add(columnsToScroll, 'month').toDate();
onNextMonth?.(nextDate);
onNext?.(nextDate);
onNext?.({ date: nextDate, type: 'month' });
setDate(nextDate);
};

const handlePreviousMonth = () => {
const nextDate = dayjs(currentDate).subtract(columnsToScroll, 'month').toDate();
onPreviousMonth?.(nextDate);
onPrevious?.(nextDate);
onPrevious?.({ date: nextDate, type: 'month' });
setDate(nextDate);
};

const handleNextYear = () => {
const nextDate = dayjs(currentDate).add(columnsToScroll, 'year').toDate();
onNextYear?.(nextDate);
onNext?.(nextDate);
onNext?.({ date: nextDate, type: 'year' });
setDate(nextDate);
};

const handlePreviousYear = () => {
const nextDate = dayjs(currentDate).subtract(columnsToScroll, 'year').toDate();
onPreviousYear?.(nextDate);
onPrevious?.(nextDate);
onPrevious?.({ date: nextDate, type: 'year' });
setDate(nextDate);
};

const handleNextDecade = () => {
const nextDate = dayjs(currentDate)
.add(10 * columnsToScroll, 'year')
.toDate();
onNextDecade?.(nextDate);
onNext?.(nextDate);
onNext?.({ date: nextDate, type: 'decade' });
setDate(nextDate);
};

const handlePreviousDecade = () => {
const nextDate = dayjs(currentDate)
.subtract(10 * columnsToScroll, 'year')
.toDate();
onPreviousDecade?.(nextDate);
onNext?.(nextDate);
onPrevious?.({ date: nextDate, type: 'decade' });
setDate(nextDate);
};

Expand Down
8 changes: 4 additions & 4 deletions packages/blade/src/components/DatePicker/DatePicker.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ const DatePicker = <Type extends DateSelectionType = 'single'>({
props?.onYearSelect?.(date);
onDateChange(date);
}}
onNext={(date) => {
props?.onNext?.(date);
onNext={(data) => {
props?.onNext?.(data);
forceRerenderBottomSheet();
}}
onPrevious={(date) => {
props?.onPrevious?.(date);
onPrevious={(data) => {
props?.onPrevious?.(data);
forceRerenderBottomSheet();
}}
picker={_picker}
Expand Down
24 changes: 15 additions & 9 deletions packages/blade/src/components/DatePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { BaseInputProps } from '~components/Input/BaseInput';
import type { TextInputProps } from '~components/Input/TextInput';
import type { FormInputValidationProps } from '~components/Form';

type Level = 'month' | 'year' | 'decade';
type PickerType = 'day' | 'month' | 'year';
type Preset = {
/**
Expand Down Expand Up @@ -101,15 +102,20 @@ type CalendarProps<SelectionType extends DateSelectionType> = Pick<
*/
locale?: string;

// Basic selection props
onNext?: (date: Date) => void;
onNextMonth?: (date: Date) => void;
onNextYear?: (date: Date) => void;
onNextDecade?: (date: Date) => void;
onPrevious?: (date: Date) => void;
onPreviousYear?: (date: Date) => void;
onPreviousMonth?: (date: Date) => void;
onPreviousDecade?: (date: Date) => void;
/**
* Callback which is called whenever the next button is clicked.
*
* @param date - The updated date.
* @param type - The level of the calendar. ("month" | "year" | "decade")
*/
onNext?: ({ date, type }: { date: Date; type: Level }) => void;
/**
* Callback which is called whenever the previous button is clicked.
*
* @param date - The updated date.
* @param type - The level of the calendar. ("month" | "year" | "decade")
*/
onPrevious?: ({ date, type }: { date: Date; type: Level }) => void;
};

type DatePickerProps<Type extends DateSelectionType> = Omit<
Expand Down

0 comments on commit d37159d

Please sign in to comment.