diff --git a/components/calendar/generateCalendar.tsx b/components/calendar/generateCalendar.tsx index 9590edb14e..f291cf6666 100644 --- a/components/calendar/generateCalendar.tsx +++ b/components/calendar/generateCalendar.tsx @@ -54,24 +54,23 @@ export interface CalendarProps { onSelect?: (date: DateType, selectInfo: SelectInfo) => void; } -function generateCalendar(generateConfig: GenerateConfig) { - function isSameYear(date1: DateType, date2: DateType) { - return date1 && date2 && generateConfig.getYear(date1) === generateConfig.getYear(date2); - } +const isSameYear = (date1: T, date2: T, config: GenerateConfig) => { + const { getYear } = config; + return date1 && date2 && getYear(date1) === getYear(date2); +}; - function isSameMonth(date1: DateType, date2: DateType) { - return ( - isSameYear(date1, date2) && generateConfig.getMonth(date1) === generateConfig.getMonth(date2) - ); - } +const isSameMonth = (date1: T, date2: T, config: GenerateConfig) => { + const { getMonth } = config; + return isSameYear(date1, date2, config) && getMonth(date1) === getMonth(date2); +}; - function isSameDate(date1: DateType, date2: DateType) { - return ( - isSameMonth(date1, date2) && generateConfig.getDate(date1) === generateConfig.getDate(date2) - ); - } +const isSameDate = (date1: T, date2: T, config: GenerateConfig) => { + const { getDate } = config; + return isSameMonth(date1, date2, config) && getDate(date1) === getDate(date2); +}; - const Calendar = (props: CalendarProps) => { +const generateCalendar = (generateConfig: GenerateConfig) => { + const Calendar: React.FC>> = (props) => { const { prefixCls: customizePrefixCls, className, @@ -149,11 +148,11 @@ function generateCalendar(generateConfig: GenerateCo const triggerChange = (date: DateType) => { setMergedValue(date); - if (!isSameDate(date, mergedValue)) { + if (!isSameDate(date, mergedValue, generateConfig)) { // Trigger when month panel switch month if ( - (panelMode === 'date' && !isSameMonth(date, mergedValue)) || - (panelMode === 'month' && !isSameYear(date, mergedValue)) + (panelMode === 'date' && !isSameMonth(date, mergedValue, generateConfig)) || + (panelMode === 'month' && !isSameYear(date, mergedValue, generateConfig)) ) { triggerPanelChange(date, mergedMode); } @@ -200,7 +199,7 @@ function generateCalendar(generateConfig: GenerateCo return (
@@ -230,7 +229,7 @@ function generateCalendar(generateConfig: GenerateCo return (
@@ -322,6 +321,6 @@ function generateCalendar(generateConfig: GenerateCo } return Calendar; -} +}; export default generateCalendar; diff --git a/components/date-picker/PickerButton.tsx b/components/date-picker/PickerButton.tsx index 97af6420ef..d0a572c255 100644 --- a/components/date-picker/PickerButton.tsx +++ b/components/date-picker/PickerButton.tsx @@ -3,6 +3,8 @@ import * as React from 'react'; import Button from '../button'; import type { ButtonProps } from '../button'; -export default function PickerButton(props: ButtonProps) { - return