Skip to content

Commit

Permalink
Fix calendarType not passed to Day component (#902)
Browse files Browse the repository at this point in the history

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
  • Loading branch information
abukati and wojtekmaj committed Oct 17, 2023
1 parent 8758cee commit 04609b4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions packages/react-calendar/src/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,10 +24,14 @@ function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
}

type MonthViewProps = {
calendarType?: CalendarType | DeprecatedCalendarType;
showWeekNumbers?: boolean;
} & React.ComponentProps<typeof Weekdays> &
React.ComponentProps<typeof WeekNumbers> &
React.ComponentProps<typeof Days>;
} & Omit<
React.ComponentProps<typeof Weekdays> &
React.ComponentProps<typeof WeekNumbers> &
React.ComponentProps<typeof Days>,
'calendarType'
>;

const MonthView: React.FC<MonthViewProps> = function MonthView(props) {
const { activeStartDate, locale, onMouseLeave, showFixedNumberOfWeeks } = props;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-calendar/src/MonthView/Day.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Day>;

describe('Day', () => {
it('applies given classNames properly', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-calendar/src/MonthView/Days.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -90,6 +90,7 @@ export default function Days(props: DaysProps) {
{...otherProps}
{...otherTileProps}
activeStartDate={activeStartDate}
calendarType={calendarTypeOrDeprecatedCalendarType}
currentMonthIndex={monthIndex}
date={date}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/WeekNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {

type WeekNumbersProps = {
activeStartDate: Date;
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType: CalendarType | DeprecatedCalendarType | undefined;
onClickWeekNumber?: OnClickWeekNumberFunc;
onMouseLeave?: () => void;
showFixedNumberOfWeeks?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/Weekdays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const calendarTypeMap: Record<DeprecatedCalendarType, CalendarType> = {
};

function isDeprecatedCalendarType(
calendarType?: CalendarType | DeprecatedCalendarType,
calendarType: CalendarType | DeprecatedCalendarType | undefined,
): calendarType is DeprecatedCalendarType {
return calendarType !== undefined && calendarType in DEPRECATED_CALENDAR_TYPES;
}
Expand Down

0 comments on commit 04609b4

Please sign in to comment.