diff --git a/packages/react/src/components/Forms/DatePicker/Calendar.tsx b/packages/react/src/components/Forms/DatePicker/Calendar.tsx index b099997..70330e2 100644 --- a/packages/react/src/components/Forms/DatePicker/Calendar.tsx +++ b/packages/react/src/components/Forms/DatePicker/Calendar.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useRef } from "react"; +import React, { forwardRef, Ref, useMemo, useRef } from "react"; import { CalendarDate, createCalendar, @@ -11,15 +11,24 @@ import { useDateFormatter, useLocale, } from "@react-aria/i18n"; -import { useCalendarState } from "@react-stately/calendar"; -import { useCalendar } from "@react-aria/calendar"; +import { + CalendarState, + RangeCalendarState, + useCalendarState, + useRangeCalendarState, +} from "@react-stately/calendar"; +import { + CalendarAria, + useCalendar, + useRangeCalendar, +} from "@react-aria/calendar"; import { useSelect, UseSelectReturnValue, UseSelectStateChange, } from "downshift"; import classNames from "classnames"; -import { CalendarProps } from "react-aria"; +import { CalendarProps, RangeCalendarProps } from "react-aria"; import { range } from ":/utils"; import { Button } from ":/components/Button"; import { CalendarGrid } from ":/components/Forms/DatePicker/CalendarGrid"; @@ -75,231 +84,253 @@ const DropdownValues = ({ options, downShift }: DropdownValuesProps) => ( ); -interface CalendarSubProps extends CalendarProps { +interface CalendarAuxProps extends CalendarAria { minYear?: number; maxYear?: number; + state: RangeCalendarState | CalendarState; } -export const Calendar = ({ - minYear = 1900, // in gregorian calendar. - maxYear = 2050, // in gregorian calendar. - ...props -}: CalendarSubProps) => { - const { locale } = useLocale(); - const { t } = useCunningham(); - const ref = useRef(null); +const CalendarAux = forwardRef( + ( + { + state, + minYear = 1900, // in gregorian calendar. + maxYear = 2050, // in gregorian calendar. + prevButtonProps, + nextButtonProps, + calendarProps, + }: CalendarAuxProps, + ref: Ref + ) => { + const { t } = useCunningham(); + const useTimeZoneFormatter = (formatOptions: DateFormatterOptions) => { + return useDateFormatter({ + ...formatOptions, + timeZone: state.timeZone, + }); + }; + + const monthItemsFormatter = useTimeZoneFormatter({ month: "long" }); + const selectedMonthItemFormatter = useTimeZoneFormatter({ month: "short" }); + const yearItemsFormatter = useTimeZoneFormatter({ year: "numeric" }); + + const monthItems: Array