From 04609b42b835b7bf76e1b46ae8719d6471deb772 Mon Sep 17 00:00:00 2001 From: Artiom Bukati <85628499+abukati@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:11:48 +0300 Subject: [PATCH] Fix calendarType not passed to Day component (#902) Co-authored-by: Wojciech Maj --- packages/react-calendar/src/MonthView.tsx | 12 ++++++++---- packages/react-calendar/src/MonthView/Day.spec.tsx | 3 ++- packages/react-calendar/src/MonthView/Day.tsx | 2 +- packages/react-calendar/src/MonthView/Days.tsx | 3 ++- .../react-calendar/src/MonthView/WeekNumbers.tsx | 2 +- packages/react-calendar/src/MonthView/Weekdays.tsx | 2 +- packages/react-calendar/src/shared/utils.ts | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/react-calendar/src/MonthView.tsx b/packages/react-calendar/src/MonthView.tsx index d84f4a43..6d9da431 100644 --- a/packages/react-calendar/src/MonthView.tsx +++ b/packages/react-calendar/src/MonthView.tsx @@ -9,7 +9,7 @@ import WeekNumbers from './MonthView/WeekNumbers.js'; import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const.js'; import { isCalendarType, tileGroupProps } from './shared/propTypes.js'; -import type { CalendarType } from './shared/types.js'; +import type { CalendarType, DeprecatedCalendarType } from './shared/types.js'; function getCalendarTypeFromLocale(locale: string | undefined): CalendarType { if (locale) { @@ -24,10 +24,14 @@ function getCalendarTypeFromLocale(locale: string | undefined): CalendarType { } type MonthViewProps = { + calendarType?: CalendarType | DeprecatedCalendarType; showWeekNumbers?: boolean; -} & React.ComponentProps & - React.ComponentProps & - React.ComponentProps; +} & Omit< + React.ComponentProps & + React.ComponentProps & + React.ComponentProps, + 'calendarType' +>; const MonthView: React.FC = function MonthView(props) { const { activeStartDate, locale, onMouseLeave, showFixedNumberOfWeeks } = props; diff --git a/packages/react-calendar/src/MonthView/Day.spec.tsx b/packages/react-calendar/src/MonthView/Day.spec.tsx index fd16cb9c..69447d50 100644 --- a/packages/react-calendar/src/MonthView/Day.spec.tsx +++ b/packages/react-calendar/src/MonthView/Day.spec.tsx @@ -6,10 +6,11 @@ import Day from './Day.js'; const tileProps = { activeStartDate: new Date(2018, 0, 1), + calendarType: 'iso8601', classes: ['react-calendar__tile'], currentMonthIndex: 0, date: new Date(2018, 0, 1), -}; +} satisfies React.ComponentProps; describe('Day', () => { it('applies given classNames properly', () => { diff --git a/packages/react-calendar/src/MonthView/Day.tsx b/packages/react-calendar/src/MonthView/Day.tsx index 0868af36..97bf4a3c 100644 --- a/packages/react-calendar/src/MonthView/Day.tsx +++ b/packages/react-calendar/src/MonthView/Day.tsx @@ -15,7 +15,7 @@ import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js'; const className = 'react-calendar__month-view__days__day'; type DayProps = { - calendarType?: CalendarType | DeprecatedCalendarType; + calendarType: CalendarType | DeprecatedCalendarType | undefined; classes?: string[]; currentMonthIndex: number; formatDay?: typeof defaultFormatDay; diff --git a/packages/react-calendar/src/MonthView/Days.tsx b/packages/react-calendar/src/MonthView/Days.tsx index de826c02..d2140264 100644 --- a/packages/react-calendar/src/MonthView/Days.tsx +++ b/packages/react-calendar/src/MonthView/Days.tsx @@ -11,7 +11,7 @@ import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js'; type DaysProps = { activeStartDate: Date; - calendarType?: CalendarType | DeprecatedCalendarType; + calendarType: CalendarType | DeprecatedCalendarType | undefined; showFixedNumberOfWeeks?: boolean; showNeighboringMonth?: boolean; } & Omit< @@ -90,6 +90,7 @@ export default function Days(props: DaysProps) { {...otherProps} {...otherTileProps} activeStartDate={activeStartDate} + calendarType={calendarTypeOrDeprecatedCalendarType} currentMonthIndex={monthIndex} date={date} /> diff --git a/packages/react-calendar/src/MonthView/WeekNumbers.tsx b/packages/react-calendar/src/MonthView/WeekNumbers.tsx index e24adf0c..4e027800 100644 --- a/packages/react-calendar/src/MonthView/WeekNumbers.tsx +++ b/packages/react-calendar/src/MonthView/WeekNumbers.tsx @@ -15,7 +15,7 @@ import type { type WeekNumbersProps = { activeStartDate: Date; - calendarType?: CalendarType | DeprecatedCalendarType; + calendarType: CalendarType | DeprecatedCalendarType | undefined; onClickWeekNumber?: OnClickWeekNumberFunc; onMouseLeave?: () => void; showFixedNumberOfWeeks?: boolean; diff --git a/packages/react-calendar/src/MonthView/Weekdays.tsx b/packages/react-calendar/src/MonthView/Weekdays.tsx index c3dad4d5..77d857e2 100644 --- a/packages/react-calendar/src/MonthView/Weekdays.tsx +++ b/packages/react-calendar/src/MonthView/Weekdays.tsx @@ -17,7 +17,7 @@ const className = 'react-calendar__month-view__weekdays'; const weekdayClassName = `${className}__weekday`; type WeekdaysProps = { - calendarType?: CalendarType | DeprecatedCalendarType; + calendarType: CalendarType | DeprecatedCalendarType | undefined; formatShortWeekday?: typeof defaultFormatShortWeekday; formatWeekday?: typeof defaultFormatWeekday; locale?: string; diff --git a/packages/react-calendar/src/shared/utils.ts b/packages/react-calendar/src/shared/utils.ts index f6751264..e5e7f011 100644 --- a/packages/react-calendar/src/shared/utils.ts +++ b/packages/react-calendar/src/shared/utils.ts @@ -164,7 +164,7 @@ const calendarTypeMap: Record = { }; function isDeprecatedCalendarType( - calendarType?: CalendarType | DeprecatedCalendarType, + calendarType: CalendarType | DeprecatedCalendarType | undefined, ): calendarType is DeprecatedCalendarType { return calendarType !== undefined && calendarType in DEPRECATED_CALENDAR_TYPES; }