import { TZDate } from '@date-fns/tz'; import type { RefObject } from 'react'; import type { TimeValue, TimeframeV2 } from '../../../core/types/time.js'; import type { StringTimeOffset } from '../../forms-core/time/types.js'; import type { CalendarType } from '../Calendar.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; /** Whether the calendar is currently focused, needed for some keyboard navigation. */ isCalendarBodyFocused: boolean | null; /** The day the week starts on depending on the locale. */ weekStartsOn: FirstDayOfWeek; /** The currently selected date. */ selectedDate: TimeValue | Partial | 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'; /** The earliest date that can be selected. */ min?: TZDate; /** The latest date that can be selected. */ max?: TZDate; /** * A date or date range defining the initial or expected time that should be added to the value. * If none set it falls back to `startOfDay` or `endOfDay` for the to date. */ timeOffset: StringTimeOffset; /** * The date currently hovered if the second date of a timeframe is selected. */ hoveredDate?: TZDate | null; /** * The id of the current error. */ errorId?: string; } /** @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: 'isCalendarBodyFocusedChange'; payload: boolean; } | { type: 'weekStartsOnChange'; payload: FirstDayOfWeek; } | { type: 'currentViewChange'; payload: CalendarViewType; } | { type: 'selectionChanged'; payload: string | null; } | { type: 'navigateCurrentView'; payload: CalendarNavigationPayload; } | { type: 'valueChanged'; payload: TimeValue | Partial | null; } | { type: 'hoveredItemChanged'; payload: TZDate | null; } | { type: 'typeChanged'; payload: Pick; } | { type: 'updateError'; payload: string | undefined; };