Skip to content

Commit 7a292c7

Browse files
authored
Adapt Calendar component for Node v22.12+ (#2832)
* Adapt Calendar component for Node v22.12+ * Revert Node version pin
1 parent 6e2c051 commit 7a292c7

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

.changeset/shaggy-coins-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sumup-oss/circuit-ui": minor
3+
---
4+
5+
Deprecated the Calendar component's `calendar` prop since support for the `gregory` calendar system wasn't fully tested and is partially broken. Use the default `iso8601` calendar system instead. The prop will be removed in the next major version.

.changeset/sour-llamas-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sumup-oss/circuit-ui": patch
3+
---
4+
5+
Fixed the display order of the Calendar component's month headline on Node 22.12 and above.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node: [20, 22.11]
10+
node: [20, 22]
1111
steps:
1212
- name: Checkout repository
1313
uses: actions/checkout@v4

.github/workflows/templates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
1313
matrix:
14-
node: [20, 22.11]
14+
node: [20, 22]
1515
template: [astro, nextjs, remix]
1616
include:
1717
- template: astro

packages/circuit-ui/components/Calendar/Calendar.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Dates are formatted using the [`Intl.DateTimeFormat` API](https://developer.mozi
2828

2929
Use the `firstDayOfWeek` prop to set the first day of the week for the locale, either `1` (Monday) or `7` (Sunday). This information can be obtained using the [`Intl.Locale.prototype.getWeekInfo()` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo#firstday) in supported browsers.
3030

31-
Only `iso8601` and `gregory` [calendars](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars#supported_calendar_types) and the left-to-right [writing direction](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir) are currently supported.
31+
Only the `iso8601` [calendar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars#supported_calendar_types) and the left-to-right [writing direction](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir) are currently supported.
3232

3333
<Story of={Stories.Localized} />
3434

packages/circuit-ui/components/Calendar/Calendar.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ interface SharedProps {
9292
*/
9393
locale?: Locale;
9494
/**
95+
* @deprecated Support for the `gregory` calendar has been removed since it
96+
* never fully worked. The `calendar` prop will be removed in the next major
97+
* version.
98+
*
9599
* The identifier for the used [calendar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar). Default: `iso8601`.
96100
*/
97101
calendar?: 'iso8601' | 'gregory';
@@ -150,7 +154,6 @@ export const Calendar = forwardRef<HTMLDivElement, CalendarProps>(
150154
nextMonthButtonLabel,
151155
modifiers,
152156
numberOfMonths = 1,
153-
calendar = 'iso8601',
154157
...rest
155158
} = useI18n(props, translations);
156159
const [{ months, focusedDate, hoveredDate, today }, dispatch] = useReducer(
@@ -311,7 +314,6 @@ export const Calendar = forwardRef<HTMLDivElement, CalendarProps>(
311314
firstDayOfWeek={firstDayOfWeek}
312315
daysInWeek={daysInWeek}
313316
locale={locale}
314-
calendar={calendar}
315317
modifiers={modifiers}
316318
onFocus={handleFocusDate}
317319
onSelect={onSelect}
@@ -358,17 +360,16 @@ function Month({
358360
firstDayOfWeek = 1,
359361
daysInWeek,
360362
locale,
361-
calendar,
362363
}: MonthProps) {
363364
const descriptionIds = useId();
364365
const headlineId = useId();
365366
const headline = useMemo(
366-
() => getMonthHeadline(yearMonth, locale, calendar),
367-
[yearMonth, locale, calendar],
367+
() => getMonthHeadline(yearMonth, locale),
368+
[yearMonth, locale],
368369
);
369370
const weekdays = useMemo(
370-
() => getWeekdays(firstDayOfWeek, daysInWeek, locale, calendar),
371-
[firstDayOfWeek, daysInWeek, locale, calendar],
371+
() => getWeekdays(firstDayOfWeek, daysInWeek, locale),
372+
[firstDayOfWeek, daysInWeek, locale],
372373
);
373374
const weeks = useMemo(
374375
() => getViewOfMonth(yearMonth, firstDayOfWeek, daysInWeek),

packages/circuit-ui/components/Calendar/CalendarService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,18 @@ export function getWeekdays(
143143
firstDayOfWeek: FirstDayOfWeek = 1,
144144
daysInWeek: DaysInWeek = 7,
145145
locale?: Locale,
146-
calendar?: string,
147146
) {
148147
return Array.from(Array(daysInWeek)).map((_, index) => {
149148
// 1973 started with a Monday
150149
const date = new Temporal.PlainDate(1973, 1, index + firstDayOfWeek);
151150
return {
152151
narrow: formatDateTime(date, locale, {
153152
weekday: 'narrow',
154-
calendar,
153+
calendar: date.calendarId,
155154
}),
156155
long: formatDateTime(date, locale, {
157156
weekday: 'long',
158-
calendar,
157+
calendar: date.calendarId,
159158
}),
160159
};
161160
}) as Weekdays;
@@ -164,12 +163,17 @@ export function getWeekdays(
164163
export function getMonthHeadline(
165164
yearMonth: Temporal.PlainYearMonth,
166165
locale?: Locale,
167-
calendar = 'iso8601',
168166
) {
169-
return formatDateTime(yearMonth, locale, {
167+
// Temporal objects use the `iso8601` calendar system by default, which
168+
// (incorrectly?) renders the year before the month since Node 22.12
169+
// (e.g. "2020 March" instead of "March 2020").
170+
// A `PlainYearMonth` has to be converted to a `PlainDate` to be able to
171+
// change its calendar system.
172+
const date = yearMonth.toPlainDate({ day: 1 }).withCalendar('gregory');
173+
return formatDateTime(date, locale, {
170174
year: 'numeric',
171175
month: 'long',
172-
calendar,
176+
calendar: date.calendarId,
173177
});
174178
}
175179

0 commit comments

Comments
 (0)