import { CSSProperties, ReactNode, Ref } from 'react'; import { SlotClassNames, SlotStyles, HtmlProps } from '../types/slots.types.js'; import { ColorValue } from '../themeProvider/color.types.js'; import { Weekday } from '../utils/weekStart.js'; export declare enum CalendarView { Month = "month", Week = "week", Day = "day", Agenda = "agenda" } /** A day of the week, as `Date#getDay()` counts: 0 is Sunday, 1 is Monday. */ export type CalendarWeekday = Weekday; /** First day of the week, as `Date#getDay()` counts: 0 is Sunday, 1 is Monday. */ export type CalendarWeekStart = CalendarWeekday; export interface CalendarEvent { /** Unique among `events`: each occurrence of a recurring series needs an id of its own. */ id: string | number; title: string; /** Local time. */ start: Date; /** Local time, exclusive. An all-day event on the 26th ends at midnight on the 27th. */ end: Date; /** Shown in the all-day row instead of the time grid. Timed events of 24 hours or more are too. */ allDay?: boolean; /** A `ThemeColor` or any CSS colour. Falls back to `--primary-color`. */ color?: ColorValue; /** Can be clicked but not moved or resized. */ readOnly?: boolean; } /** A span of local time. `end` is exclusive. */ export interface CalendarRange { start: Date; end: Date; } export interface CalendarEventChange { event: E; start: Date; end: Date; } export interface CalendarSlot { start: Date; end: Date; allDay: boolean; } /** Where `renderEvent` draws an event. */ export interface CalendarEventContext { /** * The event has one line: an event under 45 minutes in the week and day views, an all-day bar, * or a row of the month view. The day and agenda lists have room for more. */ singleLine: boolean; } export type CalendarSlots = 'root' | 'header' | 'dayHeader' | 'cell' | 'event'; /** Text Calendar renders of its own, for translating it. Dates and times come from `locale`. */ export interface CalendarLabels { /** Previous period button (default `Previous`). */ previous?: string; /** Next period button (default `Next`). */ next?: string; /** Jump to today (default `Today`). */ today?: string; /** Name of the view switcher, read out by screen readers (default `Calendar view`). */ viewSwitcher?: string; month?: string; week?: string; day?: string; agenda?: string; /** All-day row and all-day events (default `All day`). */ allDay?: string; /** Overflow button in a month cell (default `+3 more`). */ more?: (count: number) => string; /** Appended to a day's name for screen readers (default `3 events`). */ eventCount?: (count: number) => string; /** A day or period without events (default `No events`). */ noEvents?: string; /** Create button in the header and in a day's event list, shown when `onSlotCreate` is set (default `New event`). */ newEvent?: string; /** A week number, shown with `showWeekNumbers` (default `Week 40`). */ weekNumber?: (week: number) => string; } export interface CalendarProps extends HtmlProps { /** The events to show. Only the ones inside the range `onRangeChange` reports are needed. */ events: E[]; /** Controlled: the selected day, `'YYYY-MM-DD'`, whose period is shown. Omit for uncontrolled. */ date?: string; /** Day shown initially when uncontrolled, `'YYYY-MM-DD'` (default today). */ defaultDate?: string; /** Called with the new day, `'YYYY-MM-DD'`: the value a DatePicker holds. */ onDateChange?: (day: string) => void; /** Controlled view. Omit for uncontrolled. */ view?: CalendarView; /** View shown initially when uncontrolled (default the first of `views`). */ defaultView?: CalendarView; onViewChange?: (view: CalendarView) => void; /** Views offered in the switcher, in order. The switcher is hidden when there is only one (default all four). */ views?: CalendarView[]; /** BCP 47 tag for dates, times and the week start (default the app's `locale`, else the browser's). */ locale?: string; /** Overrides the locale's first day of the week. */ weekStartsOn?: CalendarWeekStart; /** Minutes that creating, moving and resizing snap to (default `15`). */ slotMinutes?: number; /** Days of the week left out of every view: `[0, 6]` hides the weekend. */ hiddenDays?: CalendarWeekday[]; /** * Hour the week and day views open at, such as `6` for 06:00 (default an hour before now while * today is shown, otherwise the start of `workingHours`, or 07:00). */ scrollToHour?: number; /** * Working time in the week and day views, `[8, 17]` for 08:00 to 17:00: the hours outside it are * shaded. `[22, 6]` runs overnight. Its start is also the hour those views open at when today is * not shown and `scrollToHour` is not set. */ workingHours?: readonly [start: number, end: number]; /** Shows ISO 8601 week numbers: on each row of the month view, and in the corner of the week and day views. */ showWeekNumbers?: boolean; /** * Called on mount and whenever the shown period changes, with the period and one either side of * it, so the neighbours are already filled while swiping. Fetch events and expand recurring * series for this range. */ onRangeChange?: (range: CalendarRange) => void; /** An event was clicked or tapped. `anchor` is its element, for positioning a popover. */ onEventClick?: (event: E, anchor: HTMLElement) => void; /** * An event was moved or resized. Setting it is what makes events draggable. Update `events` * in the same render, or return a promise: the event then stays where it was dropped until the * promise settles, and is drawn from `events` again after that, back in place if it rejected. */ onEventChange?: (change: CalendarEventChange) => void | Promise; /** * Empty time was clicked or dragged over, or the header's New event button pressed. Setting it is * what enables creating: a click creates an hour, or an all-day slot in the month view and the * all-day row. `anchor` marks the slot on screen, for a popover's `anchor`: the first day's cell * in the month view, the first day's header for the all-day row, an invisible box over the slot * in the time grid, and the button itself from the header. */ onSlotCreate?: (slot: CalendarSlot, anchor: HTMLElement) => void; /** * Content of an event, in place of its title. Must not contain interactive elements. Keep to the * title where `context.singleLine` is set: further lines have no room there. */ renderEvent?: (event: E, context: CalendarEventContext) => ReactNode; /** A class for one event's element, next to `classNames.event`: a tentative, cancelled or selected event. */ eventClassName?: (event: E) => string | undefined; /** The root element. */ ref?: Ref; className?: string; style?: CSSProperties; classNames?: SlotClassNames; styles?: SlotStyles; /** Overrides the text Calendar renders of its own. Merged per key. */ labels?: CalendarLabels; } /** * The props `ConfigProvider` can set for every Calendar. The rest depend on the event type, and * `locale` is the provider's own. */ export type CalendarDefaults = Pick;