@ilamy/calendar 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import React3 from "react";
1
+ import React4 from "react";
2
+ import dayjs from "dayjs";
2
3
  import { Options } from "rrule";
3
4
  /**
4
5
  * Re-rrule.js Options with practical TypeScript interface.
@@ -80,6 +81,10 @@ interface CalendarEvent {
80
81
  * Unique identifier across calendar systems
81
82
  */
82
83
  uid?: string;
84
+ /** Single resource assignment */
85
+ resourceId?: string | number;
86
+ /** Multiple resource assignment (cross-resource events) */
87
+ resourceIds?: (string | number)[];
83
88
  /**
84
89
  * Custom data associated with the event
85
90
  * Use this to store additional metadata specific to your application
@@ -92,7 +97,36 @@ interface CalendarEvent {
92
97
  * Used for setting the first day of the week and other week-related settings.
93
98
  */
94
99
  type WeekDays = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
95
- import React2 from "react";
100
+ /**
101
+ * Configuration for business hours.
102
+ * Defines the working hours to be highlighted on the calendar.
103
+ */
104
+ interface BusinessHours {
105
+ /**
106
+ * Days of the week to apply business hours to.
107
+ * @default ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
108
+ */
109
+ daysOfWeek?: WeekDays[];
110
+ /**
111
+ * Start time for business hours in 24-hour format (0-24).
112
+ * @default 9
113
+ */
114
+ startTime?: number;
115
+ /**
116
+ * End time for business hours in 24-hour format (0-24).
117
+ * @default 17
118
+ */
119
+ endTime?: number;
120
+ }
121
+ interface EventFormProps {
122
+ open?: boolean;
123
+ selectedEvent?: CalendarEvent | null;
124
+ onAdd?: (event: CalendarEvent) => void;
125
+ onUpdate?: (event: CalendarEvent) => void;
126
+ onDelete?: (event: CalendarEvent) => void;
127
+ onClose: () => void;
128
+ }
129
+ import React3 from "react";
96
130
  interface Translations {
97
131
  today: string;
98
132
  create: string;
@@ -193,6 +227,14 @@ interface Translations {
193
227
  type TranslationKey = keyof Translations;
194
228
  type TranslatorFunction = (key: TranslationKey | string) => string;
195
229
  /**
230
+ * Available calendar view types.
231
+ */
232
+ type CalendarView = "month" | "week" | "day" | "year";
233
+ /**
234
+ * Time format options for displaying times in the calendar.
235
+ */
236
+ type TimeFormat = "12-hour" | "24-hour";
237
+ /**
196
238
  * This interface extends the base CalendarEvent but allows more flexible date types
197
239
  * for the start and end properties. The component will automatically convert these
198
240
  * to dayjs objects internally for consistent date handling.
@@ -204,6 +246,18 @@ interface IlamyCalendarPropEvent extends Omit<CalendarEvent, "start" | "end"> {
204
246
  start: dayjs.Dayjs | Date | string;
205
247
  end: dayjs.Dayjs | Date | string;
206
248
  }
249
+ /**
250
+ * Information passed to the onCellClick callback.
251
+ * Uses named properties for extensibility.
252
+ */
253
+ interface CellClickInfo {
254
+ /** Start date/time of the clicked cell */
255
+ start: dayjs.Dayjs;
256
+ /** End date/time of the clicked cell */
257
+ end: dayjs.Dayjs;
258
+ /** Resource ID if clicking on a resource calendar cell (optional) */
259
+ resourceId?: string | number;
260
+ }
207
261
  interface IlamyCalendarProps {
208
262
  /**
209
263
  * Array of events to display in the calendar.
@@ -218,12 +272,17 @@ interface IlamyCalendarProps {
218
272
  * The initial view to display when the calendar loads.
219
273
  * Defaults to 'month'.
220
274
  */
221
- initialView?: "month" | "week" | "day" | "year";
275
+ initialView?: CalendarView;
276
+ /**
277
+ * The initial date to display when the calendar loads.
278
+ * If not provided, the calendar will default to today's date.
279
+ */
280
+ initialDate?: dayjs.Dayjs | Date | string;
222
281
  /**
223
282
  * Custom render function for calendar events.
224
283
  * If provided, it will override the default event rendering.
225
284
  */
226
- renderEvent?: (event: CalendarEvent) => React2.ReactNode;
285
+ renderEvent?: (event: CalendarEvent) => React3.ReactNode;
227
286
  /**
228
287
  * Callback when an event is clicked.
229
288
  * Provides the clicked event object.
@@ -231,14 +290,14 @@ interface IlamyCalendarProps {
231
290
  onEventClick?: (event: CalendarEvent) => void;
232
291
  /**
233
292
  * Callback when a calendar cell is clicked.
234
- * Provides the start and end date of the clicked cell.
293
+ * Provides cell information including start/end dates and optional resourceId.
235
294
  */
236
- onCellClick?: (start: dayjs.Dayjs, end: dayjs.Dayjs) => void;
295
+ onCellClick?: (info: CellClickInfo) => void;
237
296
  /**
238
297
  * Callback when the calendar view changes (month, week, day, year).
239
298
  * Useful for syncing with external state or analytics.
240
299
  */
241
- onViewChange?: (view: "month" | "week" | "day" | "year") => void;
300
+ onViewChange?: (view: CalendarView) => void;
242
301
  /**
243
302
  * Callback when a new event is added to the calendar.
244
303
  * Provides the newly created event object.
@@ -314,18 +373,49 @@ interface IlamyCalendarProps {
314
373
  * Custom header component to replace the default calendar header.
315
374
  * Useful for adding custom branding or additional controls.
316
375
  */
317
- headerComponent?: React2.ReactNode;
376
+ headerComponent?: React3.ReactNode;
318
377
  /**
319
378
  * Custom class name for the calendar header.
320
379
  * Useful for applying custom styles to the header.
321
380
  */
322
381
  headerClassName?: string;
382
+ /**
383
+ * Configuration for business hours.
384
+ * Defines the working hours to be highlighted on the calendar.
385
+ */
386
+ businessHours?: BusinessHours;
387
+ /**
388
+ * Custom render function for the event form.
389
+ * If provided, it will override the default event form component.
390
+ * The function receives EventFormProps and should return a React node.
391
+ */
392
+ renderEventForm?: (props: EventFormProps) => React3.ReactNode;
393
+ /**
394
+ * Time format for displaying times in the calendar.
395
+ * - "12-hour": Times displayed as "1:00 PM" (default)
396
+ * - "24-hour": Times displayed as "13:00"
397
+ */
398
+ timeFormat?: TimeFormat;
323
399
  }
324
- declare const IlamyCalendar: React3.FC<IlamyCalendarProps>;
325
- import React4 from "react";
326
- interface IlamyResourceCalendarProps extends IlamyCalendarProps {
400
+ declare const IlamyCalendar: React4.FC<IlamyCalendarProps>;
401
+ import React5 from "react";
402
+ /**
403
+ * Public-facing resource calendar event interface with flexible date types.
404
+ * Similar to IlamyCalendarPropEvent but with resource assignment fields.
405
+ * Dates can be provided as dayjs.Dayjs, Date, or string and will be normalized internally.
406
+ *
407
+ * @interface IlamyResourceCalendarPropEvent
408
+ * @extends {IlamyCalendarPropEvent}
409
+ */
410
+ interface IlamyResourceCalendarPropEvent extends IlamyCalendarPropEvent {
411
+ /** Single resource assignment */
412
+ resourceId?: string | number;
413
+ /** Multiple resource assignment (cross-resource events) */
414
+ resourceIds?: (string | number)[];
415
+ }
416
+ interface IlamyResourceCalendarProps extends Omit<IlamyCalendarProps, "events"> {
327
417
  /** Array of events to display */
328
- events?: ResourceCalendarEvent[];
418
+ events?: IlamyResourceCalendarPropEvent[];
329
419
  /** Array of resources */
330
420
  resources?: Resource[];
331
421
  /** Custom render function for resources */
@@ -352,23 +442,14 @@ interface Resource {
352
442
  /** Optional position for resource display */
353
443
  position?: number;
354
444
  }
355
- /**
356
- * Resource calendar event interface extending CalendarEvent with resource assignment
357
- */
358
- interface ResourceCalendarEvent extends CalendarEvent {
359
- /** Single resource assignment */
360
- resourceId?: string | number;
361
- /** Multiple resource assignment (cross-resource events) */
362
- resourceIds?: (string | number)[];
363
- }
364
- declare const IlamyResourceCalendar: React4.FC<IlamyResourceCalendarProps>;
445
+ declare const IlamyResourceCalendar: React5.FC<IlamyResourceCalendarProps>;
365
446
  /**
366
447
  * Simplified calendar context type for external use
367
448
  * Contains only the most commonly used calendar operations
368
449
  */
369
450
  interface UseIlamyCalendarContextReturn {
370
451
  readonly currentDate: dayjs.Dayjs;
371
- readonly view: "month" | "week" | "day" | "year";
452
+ readonly view: CalendarView;
372
453
  readonly events: CalendarEvent[];
373
454
  readonly isEventFormOpen: boolean;
374
455
  readonly selectedEvent: CalendarEvent | null;
@@ -376,24 +457,25 @@ interface UseIlamyCalendarContextReturn {
376
457
  readonly firstDayOfWeek: number;
377
458
  readonly setCurrentDate: (date: dayjs.Dayjs) => void;
378
459
  readonly selectDate: (date: dayjs.Dayjs) => void;
379
- readonly setView: (view: "month" | "week" | "day" | "year") => void;
460
+ readonly setView: (view: CalendarView) => void;
380
461
  readonly nextPeriod: () => void;
381
462
  readonly prevPeriod: () => void;
382
463
  readonly today: () => void;
383
464
  readonly addEvent: (event: CalendarEvent) => void;
384
465
  readonly updateEvent: (eventId: string | number, event: Partial<CalendarEvent>) => void;
385
466
  readonly deleteEvent: (eventId: string | number) => void;
386
- readonly openEventForm: (date?: dayjs.Dayjs) => void;
467
+ readonly openEventForm: (eventData?: Partial<CalendarEvent>) => void;
387
468
  readonly closeEventForm: () => void;
469
+ readonly businessHours?: BusinessHours;
388
470
  }
389
471
  declare const useIlamyCalendarContext: () => UseIlamyCalendarContextReturn;
390
472
  /**
391
473
  * Simplified resource calendar context type for external use
392
474
  */
393
475
  interface UseIlamyResourceCalendarContextReturn extends UseIlamyCalendarContextReturn {
394
- readonly events: ResourceCalendarEvent[];
476
+ readonly events: CalendarEvent[];
395
477
  readonly resources: Resource[];
396
- readonly getEventsForResource: (resourceId: string | number) => ResourceCalendarEvent[];
478
+ readonly getEventsForResource: (resourceId: string | number) => CalendarEvent[];
397
479
  }
398
480
  declare const useIlamyResourceCalendarContext: () => UseIlamyResourceCalendarContextReturn;
399
481
  declare const isRecurringEvent: (event: CalendarEvent) => boolean;
@@ -407,4 +489,4 @@ declare const generateRecurringEvents: ({ event, currentEvents, startDate, endDa
407
489
  import { Frequency, Weekday } from "rrule";
408
490
  import { RRule } from "rrule";
409
491
  declare const defaultTranslations: Translations;
410
- export { useIlamyResourceCalendarContext, useIlamyCalendarContext, isRecurringEvent, generateRecurringEvents, defaultTranslations, Weekday, WeekDays, UseIlamyResourceCalendarContextReturn, UseIlamyCalendarContextReturn, TranslatorFunction, Translations, TranslationKey, ResourceCalendarEvent, Resource, RRuleOptions, RRule, IlamyResourceCalendarProps, IlamyResourceCalendar, IlamyCalendarProps, IlamyCalendar, Frequency, CalendarEvent };
492
+ export { useIlamyResourceCalendarContext, useIlamyCalendarContext, isRecurringEvent, generateRecurringEvents, defaultTranslations, Weekday, WeekDays, UseIlamyResourceCalendarContextReturn, UseIlamyCalendarContextReturn, TranslatorFunction, Translations, TranslationKey, TimeFormat, Resource, RRuleOptions, RRule, IlamyResourceCalendarProps, IlamyResourceCalendar, IlamyCalendarProps, IlamyCalendar, Frequency, EventFormProps, CellClickInfo, CalendarView, CalendarEvent };