Skip to content

Commit

Permalink
[breaking] Remove support for deprecated calendar types
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Apr 29, 2024
1 parent 0c069d7 commit 9045b27
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 84 deletions.
3 changes: 1 addition & 2 deletions packages/react-calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {
Action,
CalendarType,
ClassName,
DeprecatedCalendarType,
Detail,
LooseValue,
NavigationLabelFunc,
Expand Down Expand Up @@ -69,7 +68,7 @@ export type CalendarProps = {
*
* @example 'iso8601'
*/
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType?: CalendarType;
/**
* Class name(s) that will be added along with `"react-calendar"` to the main react-calendar `<div>` element.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/react-calendar/src/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WeekNumbers from './MonthView/WeekNumbers.js';

import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const.js';

import type { CalendarType, DeprecatedCalendarType } from './shared/types.js';
import type { CalendarType } from './shared/types.js';

function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
if (locale) {
Expand All @@ -26,7 +26,7 @@ type MonthViewProps = {
*
* @example 'iso8601'
*/
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType?: CalendarType;
/**
* Whether week numbers shall be shown at the left of MonthView or not.
*
Expand Down
8 changes: 3 additions & 5 deletions packages/react-calendar/src/MonthView/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
formatDay as defaultFormatDay,
formatLongDate as defaultFormatLongDate,
} from '../shared/dateFormatter.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
import type { CalendarType } from '../shared/types.js';

const className = 'react-calendar__month-view__days__day';

Expand All @@ -19,7 +18,7 @@ type DayProps = {
*
* @example 'iso8601'
*/
calendarType: CalendarType | DeprecatedCalendarType | undefined;
calendarType: CalendarType | undefined;
classes?: string[];
currentMonthIndex: number;
/**
Expand All @@ -40,14 +39,13 @@ type DayProps = {
>;

export default function Day({
calendarType: calendarTypeOrDeprecatedCalendarType,
calendarType,
classes = [],
currentMonthIndex,
formatDay = defaultFormatDay,
formatLongDate = defaultFormatLongDate,
...otherProps
}: DayProps) {
const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
const { date, locale } = otherProps;

const classesProps: string[] = [];
Expand Down
10 changes: 4 additions & 6 deletions packages/react-calendar/src/MonthView/Days.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import TileGroup from '../TileGroup.js';
import Day from './Day.js';

import { getDayOfWeek } from '../shared/dates.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
import type { CalendarType } from '../shared/types.js';

type DaysProps = {
/**
Expand All @@ -20,7 +19,7 @@ type DaysProps = {
*
* @example 'iso8601'
*/
calendarType: CalendarType | DeprecatedCalendarType | undefined;
calendarType: CalendarType | undefined;
/**
* Whether to always show fixed number of weeks (6). Forces `showNeighboringMonth` prop to be `true`.
*
Expand All @@ -44,7 +43,7 @@ type DaysProps = {
export default function Days(props: DaysProps) {
const {
activeStartDate,
calendarType: calendarTypeOrDeprecatedCalendarType,
calendarType,
hover,
showFixedNumberOfWeeks,
showNeighboringMonth,
Expand All @@ -53,7 +52,6 @@ export default function Days(props: DaysProps) {
...otherProps
} = props;

const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
const year = getYear(activeStartDate);
const monthIndex = getMonth(activeStartDate);

Expand Down Expand Up @@ -111,7 +109,7 @@ export default function Days(props: DaysProps) {
{...otherProps}
{...otherTileProps}
activeStartDate={activeStartDate}
calendarType={calendarTypeOrDeprecatedCalendarType}
calendarType={calendarType}
currentMonthIndex={monthIndex}
date={date}
/>
Expand Down
19 changes: 4 additions & 15 deletions packages/react-calendar/src/MonthView/WeekNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import WeekNumber from './WeekNumber.js';
import Flex from '../Flex.js';

import { getBeginOfWeek, getDayOfWeek, getWeekNumber } from '../shared/dates.js';
import { mapCalendarType } from '../shared/utils.js';

import type {
CalendarType,
DeprecatedCalendarType,
OnClickWeekNumberFunc,
} from '../shared/types.js';
import type { CalendarType, OnClickWeekNumberFunc } from '../shared/types.js';

type WeekNumbersProps = {
/**
Expand All @@ -24,7 +19,7 @@ type WeekNumbersProps = {
*
* @example 'iso8601'
*/
calendarType: CalendarType | DeprecatedCalendarType | undefined;
calendarType: CalendarType | undefined;
/**
* Function called when the user clicks a week number.
*
Expand All @@ -42,15 +37,9 @@ type WeekNumbersProps = {
};

export default function WeekNumbers(props: WeekNumbersProps) {
const {
activeStartDate,
calendarType: calendarTypeOrDeprecatedCalendarType,
onClickWeekNumber,
onMouseLeave,
showFixedNumberOfWeeks,
} = props;
const { activeStartDate, calendarType, onClickWeekNumber, onMouseLeave, showFixedNumberOfWeeks } =
props;

const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
const numberOfWeeks = (() => {
if (showFixedNumberOfWeeks) {
return 6;
Expand Down
8 changes: 3 additions & 5 deletions packages/react-calendar/src/MonthView/Weekdays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
formatShortWeekday as defaultFormatShortWeekday,
formatWeekday as defaultFormatWeekday,
} from '../shared/dateFormatter.js';
import { mapCalendarType } from '../shared/utils.js';

import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
import type { CalendarType } from '../shared/types.js';

const className = 'react-calendar__month-view__weekdays';
const weekdayClassName = `${className}__weekday`;
Expand All @@ -21,7 +20,7 @@ type WeekdaysProps = {
*
* @example 'iso8601'
*/
calendarType: CalendarType | DeprecatedCalendarType | undefined;
calendarType: CalendarType | undefined;
/**
* Function called to override default formatting of weekday names (shortened). Can be used to use your own formatting function.
*
Expand All @@ -45,14 +44,13 @@ type WeekdaysProps = {

export default function Weekdays(props: WeekdaysProps) {
const {
calendarType: calendarTypeOrDeprecatedCalendarType,
calendarType,
formatShortWeekday = defaultFormatShortWeekday,
formatWeekday = defaultFormatWeekday,
locale,
onMouseLeave,
} = props;

const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
const anyDate = new Date();
const beginOfMonth = getMonthStart(anyDate);
const year = getYear(beginOfMonth);
Expand Down
7 changes: 0 additions & 7 deletions packages/react-calendar/src/shared/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ export const CALENDAR_TYPES = {
ISO_8601: 'iso8601',
} as const;

export const DEPRECATED_CALENDAR_TYPES = {
ARABIC: 'Arabic',
HEBREW: 'Hebrew',
ISO_8601: 'ISO 8601',
US: 'US',
} as const;

export const CALENDAR_TYPE_LOCALES = {
[CALENDAR_TYPES.GREGORY]: [
'en-CA',
Expand Down
5 changes: 1 addition & 4 deletions packages/react-calendar/src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CALENDAR_TYPES, DEPRECATED_CALENDAR_TYPES } from './const.js';
import type { CALENDAR_TYPES } from './const.js';

export type Range<T> = [T, T];

Expand All @@ -8,9 +8,6 @@ export type CalendarType = (typeof CALENDAR_TYPES)[keyof typeof CALENDAR_TYPES];

export type ClassName = string | null | undefined | (string | null | undefined)[];

export type DeprecatedCalendarType =
(typeof DEPRECATED_CALENDAR_TYPES)[keyof typeof DEPRECATED_CALENDAR_TYPES];

export type Detail = 'century' | 'decade' | 'year' | 'month';

type LooseValuePiece = string | Date | null;
Expand Down
39 changes: 1 addition & 38 deletions packages/react-calendar/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import warning from 'warning';

import { CALENDAR_TYPES, DEPRECATED_CALENDAR_TYPES } from './const.js';
import { getRange } from './dates.js';

import type { CalendarType, DeprecatedCalendarType, Range, RangeType, Value } from './types.js';
import type { Range, RangeType, Value } from './types.js';

/**
* Returns a value no smaller than min and no larger than max.
Expand Down Expand Up @@ -155,37 +152,3 @@ export function getTileClasses(args: {

return classes;
}

const calendarTypeMap: Record<DeprecatedCalendarType, CalendarType> = {
[DEPRECATED_CALENDAR_TYPES.ARABIC]: CALENDAR_TYPES.ISLAMIC,
[DEPRECATED_CALENDAR_TYPES.HEBREW]: CALENDAR_TYPES.HEBREW,
[DEPRECATED_CALENDAR_TYPES.ISO_8601]: CALENDAR_TYPES.ISO_8601,
[DEPRECATED_CALENDAR_TYPES.US]: CALENDAR_TYPES.GREGORY,
};

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

let warned = false;

export function mapCalendarType(
calendarTypeOrDeprecatedCalendarType?: CalendarType | DeprecatedCalendarType,
): CalendarType | undefined {
if (isDeprecatedCalendarType(calendarTypeOrDeprecatedCalendarType)) {
const calendarType = calendarTypeMap[calendarTypeOrDeprecatedCalendarType];

warning(
warned,
`Specifying calendarType="${calendarTypeOrDeprecatedCalendarType}" is deprecated. Use calendarType="${calendarType}" instead.`,
);

warned = true;

return calendarType;
}

return calendarTypeOrDeprecatedCalendarType;
}

0 comments on commit 9045b27

Please sign in to comment.