Skip to content

Commit 9045b27

Browse files
committed
[breaking] Remove support for deprecated calendar types
1 parent 0c069d7 commit 9045b27

File tree

9 files changed

+19
-84
lines changed

9 files changed

+19
-84
lines changed

packages/react-calendar/src/Calendar.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
Action,
1717
CalendarType,
1818
ClassName,
19-
DeprecatedCalendarType,
2019
Detail,
2120
LooseValue,
2221
NavigationLabelFunc,
@@ -69,7 +68,7 @@ export type CalendarProps = {
6968
*
7069
* @example 'iso8601'
7170
*/
72-
calendarType?: CalendarType | DeprecatedCalendarType;
71+
calendarType?: CalendarType;
7372
/**
7473
* Class name(s) that will be added along with `"react-calendar"` to the main react-calendar `<div>` element.
7574
*

packages/react-calendar/src/MonthView.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import WeekNumbers from './MonthView/WeekNumbers.js';
66

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

9-
import type { CalendarType, DeprecatedCalendarType } from './shared/types.js';
9+
import type { CalendarType } from './shared/types.js';
1010

1111
function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
1212
if (locale) {
@@ -26,7 +26,7 @@ type MonthViewProps = {
2626
*
2727
* @example 'iso8601'
2828
*/
29-
calendarType?: CalendarType | DeprecatedCalendarType;
29+
calendarType?: CalendarType;
3030
/**
3131
* Whether week numbers shall be shown at the left of MonthView or not.
3232
*

packages/react-calendar/src/MonthView/Day.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import {
77
formatDay as defaultFormatDay,
88
formatLongDate as defaultFormatLongDate,
99
} from '../shared/dateFormatter.js';
10-
import { mapCalendarType } from '../shared/utils.js';
1110

12-
import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
11+
import type { CalendarType } from '../shared/types.js';
1312

1413
const className = 'react-calendar__month-view__days__day';
1514

@@ -19,7 +18,7 @@ type DayProps = {
1918
*
2019
* @example 'iso8601'
2120
*/
22-
calendarType: CalendarType | DeprecatedCalendarType | undefined;
21+
calendarType: CalendarType | undefined;
2322
classes?: string[];
2423
currentMonthIndex: number;
2524
/**
@@ -40,14 +39,13 @@ type DayProps = {
4039
>;
4140

4241
export default function Day({
43-
calendarType: calendarTypeOrDeprecatedCalendarType,
42+
calendarType,
4443
classes = [],
4544
currentMonthIndex,
4645
formatDay = defaultFormatDay,
4746
formatLongDate = defaultFormatLongDate,
4847
...otherProps
4948
}: DayProps) {
50-
const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
5149
const { date, locale } = otherProps;
5250

5351
const classesProps: string[] = [];

packages/react-calendar/src/MonthView/Days.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import TileGroup from '../TileGroup.js';
44
import Day from './Day.js';
55

66
import { getDayOfWeek } from '../shared/dates.js';
7-
import { mapCalendarType } from '../shared/utils.js';
87

9-
import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
8+
import type { CalendarType } from '../shared/types.js';
109

1110
type DaysProps = {
1211
/**
@@ -20,7 +19,7 @@ type DaysProps = {
2019
*
2120
* @example 'iso8601'
2221
*/
23-
calendarType: CalendarType | DeprecatedCalendarType | undefined;
22+
calendarType: CalendarType | undefined;
2423
/**
2524
* Whether to always show fixed number of weeks (6). Forces `showNeighboringMonth` prop to be `true`.
2625
*
@@ -44,7 +43,7 @@ type DaysProps = {
4443
export default function Days(props: DaysProps) {
4544
const {
4645
activeStartDate,
47-
calendarType: calendarTypeOrDeprecatedCalendarType,
46+
calendarType,
4847
hover,
4948
showFixedNumberOfWeeks,
5049
showNeighboringMonth,
@@ -53,7 +52,6 @@ export default function Days(props: DaysProps) {
5352
...otherProps
5453
} = props;
5554

56-
const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
5755
const year = getYear(activeStartDate);
5856
const monthIndex = getMonth(activeStartDate);
5957

@@ -111,7 +109,7 @@ export default function Days(props: DaysProps) {
111109
{...otherProps}
112110
{...otherTileProps}
113111
activeStartDate={activeStartDate}
114-
calendarType={calendarTypeOrDeprecatedCalendarType}
112+
calendarType={calendarType}
115113
currentMonthIndex={monthIndex}
116114
date={date}
117115
/>

packages/react-calendar/src/MonthView/WeekNumbers.tsx

+4-15
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import WeekNumber from './WeekNumber.js';
44
import Flex from '../Flex.js';
55

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

9-
import type {
10-
CalendarType,
11-
DeprecatedCalendarType,
12-
OnClickWeekNumberFunc,
13-
} from '../shared/types.js';
8+
import type { CalendarType, OnClickWeekNumberFunc } from '../shared/types.js';
149

1510
type WeekNumbersProps = {
1611
/**
@@ -24,7 +19,7 @@ type WeekNumbersProps = {
2419
*
2520
* @example 'iso8601'
2621
*/
27-
calendarType: CalendarType | DeprecatedCalendarType | undefined;
22+
calendarType: CalendarType | undefined;
2823
/**
2924
* Function called when the user clicks a week number.
3025
*
@@ -42,15 +37,9 @@ type WeekNumbersProps = {
4237
};
4338

4439
export default function WeekNumbers(props: WeekNumbersProps) {
45-
const {
46-
activeStartDate,
47-
calendarType: calendarTypeOrDeprecatedCalendarType,
48-
onClickWeekNumber,
49-
onMouseLeave,
50-
showFixedNumberOfWeeks,
51-
} = props;
40+
const { activeStartDate, calendarType, onClickWeekNumber, onMouseLeave, showFixedNumberOfWeeks } =
41+
props;
5242

53-
const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
5443
const numberOfWeeks = (() => {
5544
if (showFixedNumberOfWeeks) {
5645
return 6;

packages/react-calendar/src/MonthView/Weekdays.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import {
88
formatShortWeekday as defaultFormatShortWeekday,
99
formatWeekday as defaultFormatWeekday,
1010
} from '../shared/dateFormatter.js';
11-
import { mapCalendarType } from '../shared/utils.js';
1211

13-
import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
12+
import type { CalendarType } from '../shared/types.js';
1413

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

4645
export default function Weekdays(props: WeekdaysProps) {
4746
const {
48-
calendarType: calendarTypeOrDeprecatedCalendarType,
47+
calendarType,
4948
formatShortWeekday = defaultFormatShortWeekday,
5049
formatWeekday = defaultFormatWeekday,
5150
locale,
5251
onMouseLeave,
5352
} = props;
5453

55-
const calendarType = mapCalendarType(calendarTypeOrDeprecatedCalendarType);
5654
const anyDate = new Date();
5755
const beginOfMonth = getMonthStart(anyDate);
5856
const year = getYear(beginOfMonth);

packages/react-calendar/src/shared/const.ts

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ export const CALENDAR_TYPES = {
55
ISO_8601: 'iso8601',
66
} as const;
77

8-
export const DEPRECATED_CALENDAR_TYPES = {
9-
ARABIC: 'Arabic',
10-
HEBREW: 'Hebrew',
11-
ISO_8601: 'ISO 8601',
12-
US: 'US',
13-
} as const;
14-
158
export const CALENDAR_TYPE_LOCALES = {
169
[CALENDAR_TYPES.GREGORY]: [
1710
'en-CA',

packages/react-calendar/src/shared/types.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CALENDAR_TYPES, DEPRECATED_CALENDAR_TYPES } from './const.js';
1+
import type { CALENDAR_TYPES } from './const.js';
22

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

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

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

11-
export type DeprecatedCalendarType =
12-
(typeof DEPRECATED_CALENDAR_TYPES)[keyof typeof DEPRECATED_CALENDAR_TYPES];
13-
1411
export type Detail = 'century' | 'decade' | 'year' | 'month';
1512

1613
type LooseValuePiece = string | Date | null;

packages/react-calendar/src/shared/utils.ts

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import warning from 'warning';
2-
3-
import { CALENDAR_TYPES, DEPRECATED_CALENDAR_TYPES } from './const.js';
41
import { getRange } from './dates.js';
52

6-
import type { CalendarType, DeprecatedCalendarType, Range, RangeType, Value } from './types.js';
3+
import type { Range, RangeType, Value } from './types.js';
74

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

156153
return classes;
157154
}
158-
159-
const calendarTypeMap: Record<DeprecatedCalendarType, CalendarType> = {
160-
[DEPRECATED_CALENDAR_TYPES.ARABIC]: CALENDAR_TYPES.ISLAMIC,
161-
[DEPRECATED_CALENDAR_TYPES.HEBREW]: CALENDAR_TYPES.HEBREW,
162-
[DEPRECATED_CALENDAR_TYPES.ISO_8601]: CALENDAR_TYPES.ISO_8601,
163-
[DEPRECATED_CALENDAR_TYPES.US]: CALENDAR_TYPES.GREGORY,
164-
};
165-
166-
function isDeprecatedCalendarType(
167-
calendarType: CalendarType | DeprecatedCalendarType | undefined,
168-
): calendarType is DeprecatedCalendarType {
169-
return calendarType !== undefined && calendarType in DEPRECATED_CALENDAR_TYPES;
170-
}
171-
172-
let warned = false;
173-
174-
export function mapCalendarType(
175-
calendarTypeOrDeprecatedCalendarType?: CalendarType | DeprecatedCalendarType,
176-
): CalendarType | undefined {
177-
if (isDeprecatedCalendarType(calendarTypeOrDeprecatedCalendarType)) {
178-
const calendarType = calendarTypeMap[calendarTypeOrDeprecatedCalendarType];
179-
180-
warning(
181-
warned,
182-
`Specifying calendarType="${calendarTypeOrDeprecatedCalendarType}" is deprecated. Use calendarType="${calendarType}" instead.`,
183-
);
184-
185-
warned = true;
186-
187-
return calendarType;
188-
}
189-
190-
return calendarTypeOrDeprecatedCalendarType;
191-
}

0 commit comments

Comments
 (0)