From 26d079aa6fe6fa9c6f092607aca1fcc74fadf0da Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Mon, 29 Apr 2024 11:28:44 +0200 Subject: [PATCH] [breaking] Remove support for deprecated calendar types --- packages/react-calendar/src/Calendar.tsx | 3 +- packages/react-calendar/src/MonthView.tsx | 4 +- packages/react-calendar/src/MonthView/Day.tsx | 7 ++-- .../react-calendar/src/MonthView/Days.tsx | 10 ++--- .../src/MonthView/WeekNumbers.tsx | 19 ++------- .../react-calendar/src/MonthView/Weekdays.tsx | 8 ++-- packages/react-calendar/src/shared/const.ts | 7 ---- packages/react-calendar/src/shared/types.ts | 5 +-- packages/react-calendar/src/shared/utils.ts | 39 +------------------ 9 files changed, 19 insertions(+), 83 deletions(-) diff --git a/packages/react-calendar/src/Calendar.tsx b/packages/react-calendar/src/Calendar.tsx index 498e99f1..5e369c05 100644 --- a/packages/react-calendar/src/Calendar.tsx +++ b/packages/react-calendar/src/Calendar.tsx @@ -16,7 +16,6 @@ import type { Action, CalendarType, ClassName, - DeprecatedCalendarType, Detail, LooseValue, NavigationLabelFunc, @@ -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 `
` element. * diff --git a/packages/react-calendar/src/MonthView.tsx b/packages/react-calendar/src/MonthView.tsx index a4cd0275..5ce4241d 100644 --- a/packages/react-calendar/src/MonthView.tsx +++ b/packages/react-calendar/src/MonthView.tsx @@ -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) { @@ -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. * diff --git a/packages/react-calendar/src/MonthView/Day.tsx b/packages/react-calendar/src/MonthView/Day.tsx index 52962ad8..5c705c55 100644 --- a/packages/react-calendar/src/MonthView/Day.tsx +++ b/packages/react-calendar/src/MonthView/Day.tsx @@ -9,7 +9,7 @@ import { } 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'; @@ -19,7 +19,7 @@ type DayProps = { * * @example 'iso8601' */ - calendarType: CalendarType | DeprecatedCalendarType | undefined; + calendarType: CalendarType | undefined; classes?: string[]; currentMonthIndex: number; /** @@ -40,14 +40,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[] = []; diff --git a/packages/react-calendar/src/MonthView/Days.tsx b/packages/react-calendar/src/MonthView/Days.tsx index a3d05be3..0c0b9f89 100644 --- a/packages/react-calendar/src/MonthView/Days.tsx +++ b/packages/react-calendar/src/MonthView/Days.tsx @@ -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 = { /** @@ -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`. * @@ -44,7 +43,7 @@ type DaysProps = { export default function Days(props: DaysProps) { const { activeStartDate, - calendarType: calendarTypeOrDeprecatedCalendarType, + calendarType, hover, showFixedNumberOfWeeks, showNeighboringMonth, @@ -53,7 +52,6 @@ export default function Days(props: DaysProps) { ...otherProps } = props; - const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType); const year = getYear(activeStartDate); const monthIndex = getMonth(activeStartDate); @@ -111,7 +109,7 @@ export default function Days(props: DaysProps) { {...otherProps} {...otherTileProps} activeStartDate={activeStartDate} - calendarType={calendarTypeOrDeprecatedCalendarType} + calendarType={calendarType} currentMonthIndex={monthIndex} date={date} /> diff --git a/packages/react-calendar/src/MonthView/WeekNumbers.tsx b/packages/react-calendar/src/MonthView/WeekNumbers.tsx index ea5726e5..9c343f6c 100644 --- a/packages/react-calendar/src/MonthView/WeekNumbers.tsx +++ b/packages/react-calendar/src/MonthView/WeekNumbers.tsx @@ -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 = { /** @@ -24,7 +19,7 @@ type WeekNumbersProps = { * * @example 'iso8601' */ - calendarType: CalendarType | DeprecatedCalendarType | undefined; + calendarType: CalendarType | undefined; /** * Function called when the user clicks a week number. * @@ -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; diff --git a/packages/react-calendar/src/MonthView/Weekdays.tsx b/packages/react-calendar/src/MonthView/Weekdays.tsx index f2734ce8..87bf37d7 100644 --- a/packages/react-calendar/src/MonthView/Weekdays.tsx +++ b/packages/react-calendar/src/MonthView/Weekdays.tsx @@ -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`; @@ -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. * @@ -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); diff --git a/packages/react-calendar/src/shared/const.ts b/packages/react-calendar/src/shared/const.ts index e214a377..fc519b6e 100644 --- a/packages/react-calendar/src/shared/const.ts +++ b/packages/react-calendar/src/shared/const.ts @@ -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', diff --git a/packages/react-calendar/src/shared/types.ts b/packages/react-calendar/src/shared/types.ts index 4d5fb24d..78b8ab63 100644 --- a/packages/react-calendar/src/shared/types.ts +++ b/packages/react-calendar/src/shared/types.ts @@ -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]; @@ -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; diff --git a/packages/react-calendar/src/shared/utils.ts b/packages/react-calendar/src/shared/utils.ts index 77862b6a..888f0418 100644 --- a/packages/react-calendar/src/shared/utils.ts +++ b/packages/react-calendar/src/shared/utils.ts @@ -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. @@ -155,37 +152,3 @@ export function getTileClasses(args: { return classes; } - -const calendarTypeMap: Record = { - [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; -}