UNPKG

@ilamy/calendar

Version:

A full-featured React calendar component library built with Shadcn-Ui, Tailwind CSS, and TypeScript.

361 lines (360 loc) 11.7 kB
import React3 from "react"; import dayjs from "dayjs"; import "dayjs/locale/af"; import "dayjs/locale/am"; import "dayjs/locale/ar-dz"; import "dayjs/locale/ar-iq"; import "dayjs/locale/ar-kw"; import "dayjs/locale/ar-ly"; import "dayjs/locale/ar-ma"; import "dayjs/locale/ar-sa"; import "dayjs/locale/ar-tn"; import "dayjs/locale/ar"; import "dayjs/locale/az"; import "dayjs/locale/be"; import "dayjs/locale/bg"; import "dayjs/locale/bi"; import "dayjs/locale/bm"; import "dayjs/locale/bn-bd"; import "dayjs/locale/bn"; import "dayjs/locale/bo"; import "dayjs/locale/br"; import "dayjs/locale/bs"; import "dayjs/locale/ca"; import "dayjs/locale/cs"; import "dayjs/locale/cv"; import "dayjs/locale/cy"; import "dayjs/locale/da"; import "dayjs/locale/de-at"; import "dayjs/locale/de-ch"; import "dayjs/locale/de"; import "dayjs/locale/dv"; import "dayjs/locale/el"; import "dayjs/locale/en-au"; import "dayjs/locale/en-ca"; import "dayjs/locale/en-gb"; import "dayjs/locale/en-ie"; import "dayjs/locale/en-il"; import "dayjs/locale/en-in"; import "dayjs/locale/en-nz"; import "dayjs/locale/en-sg"; import "dayjs/locale/en-tt"; import "dayjs/locale/en"; import "dayjs/locale/eo"; import "dayjs/locale/es-do"; import "dayjs/locale/es-mx"; import "dayjs/locale/es-pr"; import "dayjs/locale/es-us"; import "dayjs/locale/es"; import "dayjs/locale/et"; import "dayjs/locale/eu"; import "dayjs/locale/fa"; import "dayjs/locale/fi"; import "dayjs/locale/fo"; import "dayjs/locale/fr-ca"; import "dayjs/locale/fr-ch"; import "dayjs/locale/fr"; import "dayjs/locale/fy"; import "dayjs/locale/ga"; import "dayjs/locale/gd"; import "dayjs/locale/gl"; import "dayjs/locale/gom-latn"; import "dayjs/locale/gu"; import "dayjs/locale/he"; import "dayjs/locale/hi"; import "dayjs/locale/hr"; import "dayjs/locale/ht"; import "dayjs/locale/hu"; import "dayjs/locale/hy-am"; import "dayjs/locale/id"; import "dayjs/locale/is"; import "dayjs/locale/it-ch"; import "dayjs/locale/it"; import "dayjs/locale/ja"; import "dayjs/locale/jv"; import "dayjs/locale/ka"; import "dayjs/locale/kk"; import "dayjs/locale/km"; import "dayjs/locale/kn"; import "dayjs/locale/ko"; import "dayjs/locale/ku"; import "dayjs/locale/ky"; import "dayjs/locale/lb"; import "dayjs/locale/lo"; import "dayjs/locale/lt"; import "dayjs/locale/lv"; import "dayjs/locale/me"; import "dayjs/locale/mi"; import "dayjs/locale/mk"; import "dayjs/locale/ml"; import "dayjs/locale/mn"; import "dayjs/locale/mr"; import "dayjs/locale/ms-my"; import "dayjs/locale/ms"; import "dayjs/locale/mt"; import "dayjs/locale/my"; import "dayjs/locale/nb"; import "dayjs/locale/ne"; import "dayjs/locale/nl-be"; import "dayjs/locale/nl"; import "dayjs/locale/nn"; import "dayjs/locale/oc-lnc"; import "dayjs/locale/pa-in"; import "dayjs/locale/pl"; import "dayjs/locale/pt-br"; import "dayjs/locale/pt"; import "dayjs/locale/rn"; import "dayjs/locale/ro"; import "dayjs/locale/ru"; import "dayjs/locale/rw"; import "dayjs/locale/sd"; import "dayjs/locale/se"; import "dayjs/locale/si"; import "dayjs/locale/sk"; import "dayjs/locale/sl"; import "dayjs/locale/sq"; import "dayjs/locale/sr-cyrl"; import "dayjs/locale/sr"; import "dayjs/locale/ss"; import "dayjs/locale/sv-fi"; import "dayjs/locale/sv"; import "dayjs/locale/sw"; import "dayjs/locale/ta"; import "dayjs/locale/te"; import "dayjs/locale/tet"; import "dayjs/locale/tg"; import "dayjs/locale/th"; import "dayjs/locale/tk"; import "dayjs/locale/tl-ph"; import "dayjs/locale/tlh"; import "dayjs/locale/tr"; import "dayjs/locale/tzl"; import "dayjs/locale/tzm-latn"; import "dayjs/locale/tzm"; import "dayjs/locale/ug-cn"; import "dayjs/locale/uk"; import "dayjs/locale/ur"; import "dayjs/locale/uz-latn"; import "dayjs/locale/uz"; import "dayjs/locale/vi"; import "dayjs/locale/x-pseudo"; import "dayjs/locale/yo"; import "dayjs/locale/zh-cn"; import "dayjs/locale/zh-hk"; import "dayjs/locale/zh-tw"; import "dayjs/locale/zh"; import { Options } from "rrule"; /** * Re-rrule.js Options with practical TypeScript interface. * Makes all properties optional except freq and dtstart (which are required by RFC 5545). * This allows clean object creation without needing explicit null values. * * @see https://tools.ietf.org/html/rfc5545 - RFC 5545 iCalendar specification * @see https://github.com/jakubroztocil/rrule - rrule.js library documentation */ type RRuleOptions = { /** * The frequency of the event. Must be one of the following: DAILY, WEEKLY, MONTHLY, etc. */ freq: Options["freq"] /** * The start date of the recurrence rule. This defines when the recurrence pattern begins. * Required for proper RRULE functionality according to RFC 5545. * @important Same as the event start date. */ dtstart: Date } & Partial<Omit<Options, "freq" | "dtstart">>; /** * Core calendar event interface representing a single calendar event. * This is the primary data structure for calendar events. */ interface CalendarEvent { /** Unique identifier for the event */ id: string | number; /** Display title of the event */ title: string; /** Start date and time of the event */ start: dayjs.Dayjs; /** End date and time of the event */ end: dayjs.Dayjs; /** * Color for the event (supports CSS color values, hex, rgb, hsl, or CSS class names) * @example "#3b82f6", "blue-500", "rgb(59, 130, 246)" */ color?: string; /** * Background color for the event (supports CSS color values, hex, rgb, hsl, or CSS class names) * @example "#dbeafe", "blue-100", "rgba(59, 130, 246, 0.1)" */ backgroundColor?: string; /** Optional description or notes for the event */ description?: string; /** Optional location where the event takes place */ location?: string; /** * Whether this is an all-day event * @default false */ allDay?: boolean; /** * Recurrence rule for recurring events (RFC 5545 standard) * * Uses TypeScript interface for better readability, type safety, and IDE support * compared to RRULE string format. Converted to rrule.js format internally. * * @example { freq: 'WEEKLY', interval: 1, byweekday: ['MO', 'WE', 'FR'] } * @example { freq: 'DAILY', interval: 1, count: 10 } * @example { freq: 'MONTHLY', interval: 1, until: new Date('2025-12-31') } */ rrule?: RRuleOptions; /** * Exception dates (EXDATE) - dates to exclude from recurrence * Uses ISO string format for storage and transmission * @example ['2025-01-15T09:00:00.000Z', '2025-01-22T09:00:00.000Z'] */ exdates?: string[]; /** * Recurrence ID (RECURRENCE-ID) - identifies modified instances * Points to the original occurrence date this event modifies * Used for events that are modifications of recurring instances */ recurrenceId?: string; /** * UID for iCalendar compatibility * Unique identifier across calendar systems */ uid?: string; /** * Custom data associated with the event * Use this to store additional metadata specific to your application * @example { meetingType: 'standup', attendees: ['john', 'jane'] } */ data?: Record<string, any>; } /** * Supported days of the week for calendar configuration. * Used for setting the first day of the week and other week-related settings. */ type WeekDays = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday"; import React2 from "react"; /** * This interface extends the base CalendarEvent but allows more flexible date types * for the start and end properties. The component will automatically convert these * to dayjs objects internally for consistent date handling. * * @interface IlamyCalendarPropEvent * @extends {Omit<CalendarEvent, 'start' | 'end'>} */ interface IlamyCalendarPropEvent extends Omit<CalendarEvent, "start" | "end"> { start: dayjs.Dayjs | Date | string; end: dayjs.Dayjs | Date | string; } interface IlamyCalendarProps { /** * Array of events to display in the calendar. */ events?: IlamyCalendarPropEvent[]; /** * The first day of the week to display in the calendar. * Can be 'sunday', 'monday', etc. Defaults to 'sunday'. */ firstDayOfWeek?: WeekDays; /** * Custom render function for calendar events. * If provided, it will override the default event rendering. */ renderEvent?: (event: CalendarEvent) => React2.ReactNode; /** * Callback when an event is clicked. * Provides the clicked event object. */ onEventClick?: (event: CalendarEvent) => void; /** * Callback when a calendar cell is clicked. * Provides the start and end date of the clicked cell. */ onCellClick?: (start: dayjs.Dayjs, end: dayjs.Dayjs) => void; /** * Callback when the calendar view changes (month, week, day, year). * Useful for syncing with external state or analytics. */ onViewChange?: (view: "month" | "week" | "day" | "year") => void; /** * Locale to use for formatting dates and times. * If not provided, the default locale will be used. */ locale?: string; /** * Timezone to use for displaying dates and times. * If not provided, the local timezone will be used. */ timezone?: string; /** * Whether to disable click events on calendar cells. * Useful for read-only views or when cell clicks are not needed. */ disableCellClick?: boolean; /** * Whether to disable click events on calendar events. * Useful for read-only views or when event clicks are not needed. */ disableEventClick?: boolean; /** * Whether to disable drag-and-drop functionality for calendar events. * Useful for read-only views or when drag-and-drop is not needed. */ disableDragAndDrop?: boolean; dayMaxEvents?: number; /** * Whether to stick the view header to the top of the calendar. * Useful for keeping the header visible while scrolling. */ stickyViewHeader?: boolean; /** * Custom class name for the view header. * Useful for applying custom styles or themes. */ viewHeaderClassName?: string; /** * Custom header component to replace the default calendar header. * Useful for adding custom branding or additional controls. */ headerComponent?: React2.ReactNode; } declare const IlamyCalendar: React3.FC<IlamyCalendarProps>; /** * Simplified calendar context type for external use * Contains only the most commonly used calendar operations */ interface UseIlamyCalendarContextReturn { readonly currentDate: dayjs.Dayjs; readonly view: "month" | "week" | "day" | "year"; readonly events: CalendarEvent[]; readonly isEventFormOpen: boolean; readonly selectedEvent: CalendarEvent | null; readonly selectedDate: dayjs.Dayjs | null; readonly firstDayOfWeek: number; readonly setCurrentDate: (date: dayjs.Dayjs) => void; readonly selectDate: (date: dayjs.Dayjs) => void; readonly setView: (view: "month" | "week" | "day" | "year") => void; readonly nextPeriod: () => void; readonly prevPeriod: () => void; readonly today: () => void; readonly addEvent: (event: CalendarEvent) => void; readonly updateEvent: (eventId: string | number, event: Partial<CalendarEvent>) => void; readonly deleteEvent: (eventId: string | number) => void; readonly openEventForm: (date?: dayjs.Dayjs) => void; readonly closeEventForm: () => void; } declare const useIlamyCalendarContext: () => UseIlamyCalendarContextReturn; declare const isRecurringEvent: (event: CalendarEvent) => boolean; interface GenerateRecurringEventsProps { event: CalendarEvent; currentEvents: CalendarEvent[]; startDate: dayjs.Dayjs; endDate: dayjs.Dayjs; } declare const generateRecurringEvents: ({ event, currentEvents, startDate, endDate }: GenerateRecurringEventsProps) => CalendarEvent[]; import { Frequency, Weekday } from "rrule"; import { RRule } from "rrule"; export { useIlamyCalendarContext, isRecurringEvent, generateRecurringEvents, Weekday, WeekDays, UseIlamyCalendarContextReturn, RRuleOptions, RRule, IlamyCalendarProps, IlamyCalendar, Frequency, CalendarEvent };