import { TZDate } from '@date-fns/tz'; import type { RefObject } from 'react'; import type { CalendarType } from './calendarConfiguration.js'; /** @internal */ export type CalendarViewType = 'day' | 'month' | 'year'; /** @internal */ export interface UseCalendarItemProps { date: TZDate; itemRef: RefObject | undefined; } /** * Index of the first day of the week, used by date-fns. 0 is for Sunday. * @internal */ export type FirstDayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6; /** @internal */ export interface CalendarState { /** The current date when mounting the calendar. */ today: TZDate; /** The date, defining what days/months/years are currently shown in the calendar. */ activeDate: TZDate; /** The currently open view. */ currentView: CalendarViewType; /** * Indicates if a keydown event originated from within the calendar. * Used to control focus updates and prevent unwanted focus changes. */ shouldUpdateFocusFromKeydown: boolean | null; /** The type of calendar (single or range). */ type: CalendarType; /** How the next selection should update the selected date. It is undefined for single calendars. */ position?: 'from' | 'to'; } /** @internal */ export type CalendarNavigationPayload = { /** * The amount defines by how many items the view should be shifted. The sign defines whether the value is subtracted or added to the current view. * For example, in the month view of January a +1 would show February and a -1 December of the year before. */ amount: number | 'endOfWeek' | 'startOfWeek'; /** Some navigation shortcuts don't navigate within the view but affect the whole view, e.g. in the day view navigating to the next month with PageUp. */ unit?: CalendarViewType; }; /** @internal */ export type CalendarReducerAction = { type: 'activeDateChange'; payload: { activeDate: TZDate; changeToView?: CalendarViewType; }; } | { type: 'shouldUpdateFocusFromKeydown'; payload: boolean; } | { type: 'currentViewChange'; payload: CalendarViewType; } | { type: 'navigateCurrentView'; payload: CalendarNavigationPayload; };