@ilamy/calendar 1.0.2 → 1.1.1
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/README.md +7 -0
- package/dist/index.d.ts +149 -62
- package/dist/index.js +6 -7
- package/package.json +116 -114
package/README.md
CHANGED
|
@@ -41,3 +41,10 @@ A powerful, full-featured React calendar component library built with TypeScript
|
|
|
41
41
|
## Documentation
|
|
42
42
|
|
|
43
43
|
For comprehensive documentation, examples, and interactive demos, visit [ilamy.dev](https://ilamy.dev)
|
|
44
|
+
|
|
45
|
+
## Code Example
|
|
46
|
+
|
|
47
|
+
Check out the [examples directory](./examples) for complete project setups:
|
|
48
|
+
|
|
49
|
+
- [Next.js Example](./examples/nextjs) - Full-featured Next.js integration
|
|
50
|
+
- [Astro Example](./examples/astro) - Static site integration with Astro
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Frequency, Weekday } from "rrule";
|
|
2
|
+
import { RRule } from "rrule";
|
|
2
3
|
import { Options } from "rrule";
|
|
3
4
|
/**
|
|
4
5
|
* Re-rrule.js Options with practical TypeScript interface.
|
|
@@ -20,6 +21,9 @@ type RRuleOptions = {
|
|
|
20
21
|
*/
|
|
21
22
|
dtstart: Date;
|
|
22
23
|
} & Partial<Omit<Options, "freq" | "dtstart">>;
|
|
24
|
+
import React4 from "react";
|
|
25
|
+
import React3 from "react";
|
|
26
|
+
import dayjs2 from "dayjs";
|
|
23
27
|
/**
|
|
24
28
|
* Core calendar event interface representing a single calendar event.
|
|
25
29
|
* This is the primary data structure for calendar events.
|
|
@@ -30,9 +34,9 @@ interface CalendarEvent {
|
|
|
30
34
|
/** Display title of the event */
|
|
31
35
|
title: string;
|
|
32
36
|
/** Start date and time of the event */
|
|
33
|
-
start:
|
|
37
|
+
start: dayjs2.Dayjs;
|
|
34
38
|
/** End date and time of the event */
|
|
35
|
-
end:
|
|
39
|
+
end: dayjs2.Dayjs;
|
|
36
40
|
/**
|
|
37
41
|
* Color for the event (supports CSS color values, hex, rgb, hsl, or CSS class names)
|
|
38
42
|
* @example "#3b82f6", "blue-500", "rgb(59, 130, 246)"
|
|
@@ -80,6 +84,10 @@ interface CalendarEvent {
|
|
|
80
84
|
* Unique identifier across calendar systems
|
|
81
85
|
*/
|
|
82
86
|
uid?: string;
|
|
87
|
+
/** Single resource assignment */
|
|
88
|
+
resourceId?: string | number;
|
|
89
|
+
/** Multiple resource assignment (cross-resource events) */
|
|
90
|
+
resourceIds?: (string | number)[];
|
|
83
91
|
/**
|
|
84
92
|
* Custom data associated with the event
|
|
85
93
|
* Use this to store additional metadata specific to your application
|
|
@@ -92,7 +100,35 @@ interface CalendarEvent {
|
|
|
92
100
|
* Used for setting the first day of the week and other week-related settings.
|
|
93
101
|
*/
|
|
94
102
|
type WeekDays = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
|
|
95
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for business hours.
|
|
105
|
+
* Defines the working hours to be highlighted on the calendar.
|
|
106
|
+
*/
|
|
107
|
+
interface BusinessHours {
|
|
108
|
+
/**
|
|
109
|
+
* Days of the week to apply business hours to.
|
|
110
|
+
* @default ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
|
|
111
|
+
*/
|
|
112
|
+
daysOfWeek?: WeekDays[];
|
|
113
|
+
/**
|
|
114
|
+
* Start time for business hours in 24-hour format (0-24).
|
|
115
|
+
* @default 9
|
|
116
|
+
*/
|
|
117
|
+
startTime?: number;
|
|
118
|
+
/**
|
|
119
|
+
* End time for business hours in 24-hour format (0-24).
|
|
120
|
+
* @default 17
|
|
121
|
+
*/
|
|
122
|
+
endTime?: number;
|
|
123
|
+
}
|
|
124
|
+
interface EventFormProps {
|
|
125
|
+
open?: boolean;
|
|
126
|
+
selectedEvent?: CalendarEvent | null;
|
|
127
|
+
onAdd?: (event: CalendarEvent) => void;
|
|
128
|
+
onUpdate?: (event: CalendarEvent) => void;
|
|
129
|
+
onDelete?: (event: CalendarEvent) => void;
|
|
130
|
+
onClose: () => void;
|
|
131
|
+
}
|
|
96
132
|
interface Translations {
|
|
97
133
|
today: string;
|
|
98
134
|
create: string;
|
|
@@ -197,6 +233,23 @@ type TranslatorFunction = (key: TranslationKey | string) => string;
|
|
|
197
233
|
*/
|
|
198
234
|
type CalendarView = "month" | "week" | "day" | "year";
|
|
199
235
|
/**
|
|
236
|
+
* Time format options for displaying times in the calendar.
|
|
237
|
+
*/
|
|
238
|
+
type TimeFormat = "12-hour" | "24-hour";
|
|
239
|
+
/**
|
|
240
|
+
* Custom class names for calendar styling.
|
|
241
|
+
* Allows users to override default styles for various calendar elements.
|
|
242
|
+
*/
|
|
243
|
+
interface CalendarClassesOverride {
|
|
244
|
+
/**
|
|
245
|
+
* Class name for disabled cells (non-business hours).
|
|
246
|
+
* Replaces the DISABLED_CELL_CLASSNAME constant.
|
|
247
|
+
* @default "bg-secondary text-muted-foreground pointer-events-none"
|
|
248
|
+
* @example "bg-gray-100 text-gray-400 cursor-not-allowed"
|
|
249
|
+
*/
|
|
250
|
+
disabledCell?: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
200
253
|
* This interface extends the base CalendarEvent but allows more flexible date types
|
|
201
254
|
* for the start and end properties. The component will automatically convert these
|
|
202
255
|
* to dayjs objects internally for consistent date handling.
|
|
@@ -205,8 +258,20 @@ type CalendarView = "month" | "week" | "day" | "year";
|
|
|
205
258
|
* @extends {Omit<CalendarEvent, 'start' | 'end'>}
|
|
206
259
|
*/
|
|
207
260
|
interface IlamyCalendarPropEvent extends Omit<CalendarEvent, "start" | "end"> {
|
|
208
|
-
start:
|
|
209
|
-
end:
|
|
261
|
+
start: dayjs2.Dayjs | Date | string;
|
|
262
|
+
end: dayjs2.Dayjs | Date | string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Information passed to the onCellClick callback.
|
|
266
|
+
* Uses named properties for extensibility.
|
|
267
|
+
*/
|
|
268
|
+
interface CellClickInfo {
|
|
269
|
+
/** Start date/time of the clicked cell */
|
|
270
|
+
start: dayjs2.Dayjs;
|
|
271
|
+
/** End date/time of the clicked cell */
|
|
272
|
+
end: dayjs2.Dayjs;
|
|
273
|
+
/** Resource ID if clicking on a resource calendar cell (optional) */
|
|
274
|
+
resourceId?: string | number;
|
|
210
275
|
}
|
|
211
276
|
interface IlamyCalendarProps {
|
|
212
277
|
/**
|
|
@@ -227,12 +292,12 @@ interface IlamyCalendarProps {
|
|
|
227
292
|
* The initial date to display when the calendar loads.
|
|
228
293
|
* If not provided, the calendar will default to today's date.
|
|
229
294
|
*/
|
|
230
|
-
initialDate?:
|
|
295
|
+
initialDate?: dayjs2.Dayjs | Date | string;
|
|
231
296
|
/**
|
|
232
297
|
* Custom render function for calendar events.
|
|
233
298
|
* If provided, it will override the default event rendering.
|
|
234
299
|
*/
|
|
235
|
-
renderEvent?: (event: CalendarEvent) =>
|
|
300
|
+
renderEvent?: (event: CalendarEvent) => React3.ReactNode;
|
|
236
301
|
/**
|
|
237
302
|
* Callback when an event is clicked.
|
|
238
303
|
* Provides the clicked event object.
|
|
@@ -240,9 +305,9 @@ interface IlamyCalendarProps {
|
|
|
240
305
|
onEventClick?: (event: CalendarEvent) => void;
|
|
241
306
|
/**
|
|
242
307
|
* Callback when a calendar cell is clicked.
|
|
243
|
-
* Provides
|
|
308
|
+
* Provides cell information including start/end dates and optional resourceId.
|
|
244
309
|
*/
|
|
245
|
-
onCellClick?: (
|
|
310
|
+
onCellClick?: (info: CellClickInfo) => void;
|
|
246
311
|
/**
|
|
247
312
|
* Callback when the calendar view changes (month, week, day, year).
|
|
248
313
|
* Useful for syncing with external state or analytics.
|
|
@@ -267,7 +332,7 @@ interface IlamyCalendarProps {
|
|
|
267
332
|
* Callback when the current date changes (navigation).
|
|
268
333
|
* Provides the new current date.
|
|
269
334
|
*/
|
|
270
|
-
onDateChange?: (date:
|
|
335
|
+
onDateChange?: (date: dayjs2.Dayjs) => void;
|
|
271
336
|
/**
|
|
272
337
|
* Locale to use for formatting dates and times.
|
|
273
338
|
* If not provided, the default locale will be used.
|
|
@@ -310,6 +375,13 @@ interface IlamyCalendarProps {
|
|
|
310
375
|
*/
|
|
311
376
|
dayMaxEvents?: number;
|
|
312
377
|
/**
|
|
378
|
+
* Vertical spacing between stacked events in pixels.
|
|
379
|
+
* Controls the gap between events when multiple events are displayed in the same view.
|
|
380
|
+
* Defaults to 1 pixel if not specified.
|
|
381
|
+
* Recommended range: 1-8 pixels for optimal readability.
|
|
382
|
+
*/
|
|
383
|
+
eventSpacing?: number;
|
|
384
|
+
/**
|
|
313
385
|
* Whether to stick the view header to the top of the calendar.
|
|
314
386
|
* Useful for keeping the header visible while scrolling.
|
|
315
387
|
*/
|
|
@@ -323,15 +395,73 @@ interface IlamyCalendarProps {
|
|
|
323
395
|
* Custom header component to replace the default calendar header.
|
|
324
396
|
* Useful for adding custom branding or additional controls.
|
|
325
397
|
*/
|
|
326
|
-
headerComponent?:
|
|
398
|
+
headerComponent?: React3.ReactNode;
|
|
327
399
|
/**
|
|
328
400
|
* Custom class name for the calendar header.
|
|
329
401
|
* Useful for applying custom styles to the header.
|
|
330
402
|
*/
|
|
331
403
|
headerClassName?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Configuration for business hours.
|
|
406
|
+
* Defines the working hours to be highlighted on the calendar.
|
|
407
|
+
* Can be a single BusinessHours object (applies to all specified days)
|
|
408
|
+
* or an array of BusinessHours objects (for different hours on different days).
|
|
409
|
+
*/
|
|
410
|
+
businessHours?: BusinessHours | BusinessHours[];
|
|
411
|
+
/**
|
|
412
|
+
* Custom render function for the event form.
|
|
413
|
+
* If provided, it will override the default event form component.
|
|
414
|
+
* The function receives EventFormProps and should return a React node.
|
|
415
|
+
*/
|
|
416
|
+
renderEventForm?: (props: EventFormProps) => React3.ReactNode;
|
|
417
|
+
/**
|
|
418
|
+
* Time format for displaying times in the calendar.
|
|
419
|
+
* - "12-hour": Times displayed as "1:00 PM" (default)
|
|
420
|
+
* - "24-hour": Times displayed as "13:00"
|
|
421
|
+
*/
|
|
422
|
+
timeFormat?: TimeFormat;
|
|
423
|
+
/**
|
|
424
|
+
* Custom class names for overriding default calendar element styles.
|
|
425
|
+
* Allows fine-grained control over the appearance of different calendar elements.
|
|
426
|
+
* @example { disabledCell: "bg-gray-100 text-gray-400" }
|
|
427
|
+
*/
|
|
428
|
+
classesOverride?: CalendarClassesOverride;
|
|
332
429
|
}
|
|
333
|
-
declare const IlamyCalendar:
|
|
334
|
-
|
|
430
|
+
declare const IlamyCalendar: React4.FC<IlamyCalendarProps>;
|
|
431
|
+
declare const isRecurringEvent: (event: CalendarEvent) => boolean;
|
|
432
|
+
interface GenerateRecurringEventsProps {
|
|
433
|
+
event: CalendarEvent;
|
|
434
|
+
currentEvents: CalendarEvent[];
|
|
435
|
+
startDate: dayjs2.Dayjs;
|
|
436
|
+
endDate: dayjs2.Dayjs;
|
|
437
|
+
}
|
|
438
|
+
declare const generateRecurringEvents: ({ event, currentEvents, startDate, endDate }: GenerateRecurringEventsProps) => CalendarEvent[];
|
|
439
|
+
/**
|
|
440
|
+
* Simplified calendar context type for external use
|
|
441
|
+
* Contains only the most commonly used calendar operations
|
|
442
|
+
*/
|
|
443
|
+
interface UseIlamyCalendarContextReturn {
|
|
444
|
+
readonly currentDate: dayjs2.Dayjs;
|
|
445
|
+
readonly view: CalendarView;
|
|
446
|
+
readonly events: CalendarEvent[];
|
|
447
|
+
readonly isEventFormOpen: boolean;
|
|
448
|
+
readonly selectedEvent: CalendarEvent | null;
|
|
449
|
+
readonly selectedDate: dayjs2.Dayjs | null;
|
|
450
|
+
readonly firstDayOfWeek: number;
|
|
451
|
+
readonly setCurrentDate: (date: dayjs2.Dayjs) => void;
|
|
452
|
+
readonly selectDate: (date: dayjs2.Dayjs) => void;
|
|
453
|
+
readonly setView: (view: CalendarView) => void;
|
|
454
|
+
readonly nextPeriod: () => void;
|
|
455
|
+
readonly prevPeriod: () => void;
|
|
456
|
+
readonly today: () => void;
|
|
457
|
+
readonly addEvent: (event: CalendarEvent) => void;
|
|
458
|
+
readonly updateEvent: (eventId: string | number, event: Partial<CalendarEvent>) => void;
|
|
459
|
+
readonly deleteEvent: (eventId: string | number) => void;
|
|
460
|
+
readonly openEventForm: (eventData?: Partial<CalendarEvent>) => void;
|
|
461
|
+
readonly closeEventForm: () => void;
|
|
462
|
+
readonly businessHours?: BusinessHours | BusinessHours[];
|
|
463
|
+
}
|
|
464
|
+
declare const useIlamyCalendarContext: () => UseIlamyCalendarContextReturn;
|
|
335
465
|
/**
|
|
336
466
|
* Public-facing resource calendar event interface with flexible date types.
|
|
337
467
|
* Similar to IlamyCalendarPropEvent but with resource assignment fields.
|
|
@@ -375,59 +505,16 @@ interface Resource {
|
|
|
375
505
|
/** Optional position for resource display */
|
|
376
506
|
position?: number;
|
|
377
507
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
*/
|
|
381
|
-
interface ResourceCalendarEvent extends CalendarEvent {
|
|
382
|
-
/** Single resource assignment */
|
|
383
|
-
resourceId?: string | number;
|
|
384
|
-
/** Multiple resource assignment (cross-resource events) */
|
|
385
|
-
resourceIds?: (string | number)[];
|
|
386
|
-
}
|
|
387
|
-
declare const IlamyResourceCalendar: React4.FC<IlamyResourceCalendarProps>;
|
|
388
|
-
/**
|
|
389
|
-
* Simplified calendar context type for external use
|
|
390
|
-
* Contains only the most commonly used calendar operations
|
|
391
|
-
*/
|
|
392
|
-
interface UseIlamyCalendarContextReturn {
|
|
393
|
-
readonly currentDate: dayjs.Dayjs;
|
|
394
|
-
readonly view: CalendarView;
|
|
395
|
-
readonly events: CalendarEvent[];
|
|
396
|
-
readonly isEventFormOpen: boolean;
|
|
397
|
-
readonly selectedEvent: CalendarEvent | null;
|
|
398
|
-
readonly selectedDate: dayjs.Dayjs | null;
|
|
399
|
-
readonly firstDayOfWeek: number;
|
|
400
|
-
readonly setCurrentDate: (date: dayjs.Dayjs) => void;
|
|
401
|
-
readonly selectDate: (date: dayjs.Dayjs) => void;
|
|
402
|
-
readonly setView: (view: CalendarView) => void;
|
|
403
|
-
readonly nextPeriod: () => void;
|
|
404
|
-
readonly prevPeriod: () => void;
|
|
405
|
-
readonly today: () => void;
|
|
406
|
-
readonly addEvent: (event: CalendarEvent) => void;
|
|
407
|
-
readonly updateEvent: (eventId: string | number, event: Partial<CalendarEvent>) => void;
|
|
408
|
-
readonly deleteEvent: (eventId: string | number) => void;
|
|
409
|
-
readonly openEventForm: (date?: dayjs.Dayjs) => void;
|
|
410
|
-
readonly closeEventForm: () => void;
|
|
411
|
-
}
|
|
412
|
-
declare const useIlamyCalendarContext: () => UseIlamyCalendarContextReturn;
|
|
508
|
+
import React5 from "react";
|
|
509
|
+
declare const IlamyResourceCalendar: React5.FC<IlamyResourceCalendarProps>;
|
|
413
510
|
/**
|
|
414
511
|
* Simplified resource calendar context type for external use
|
|
415
512
|
*/
|
|
416
513
|
interface UseIlamyResourceCalendarContextReturn extends UseIlamyCalendarContextReturn {
|
|
417
|
-
readonly events:
|
|
514
|
+
readonly events: CalendarEvent[];
|
|
418
515
|
readonly resources: Resource[];
|
|
419
|
-
readonly getEventsForResource: (resourceId: string | number) =>
|
|
516
|
+
readonly getEventsForResource: (resourceId: string | number) => CalendarEvent[];
|
|
420
517
|
}
|
|
421
518
|
declare const useIlamyResourceCalendarContext: () => UseIlamyResourceCalendarContextReturn;
|
|
422
|
-
declare const isRecurringEvent: (event: CalendarEvent) => boolean;
|
|
423
|
-
interface GenerateRecurringEventsProps {
|
|
424
|
-
event: CalendarEvent;
|
|
425
|
-
currentEvents: CalendarEvent[];
|
|
426
|
-
startDate: dayjs.Dayjs;
|
|
427
|
-
endDate: dayjs.Dayjs;
|
|
428
|
-
}
|
|
429
|
-
declare const generateRecurringEvents: ({ event, currentEvents, startDate, endDate }: GenerateRecurringEventsProps) => CalendarEvent[];
|
|
430
|
-
import { Frequency, Weekday } from "rrule";
|
|
431
|
-
import { RRule } from "rrule";
|
|
432
519
|
declare const defaultTranslations: Translations;
|
|
433
|
-
export { useIlamyResourceCalendarContext, useIlamyCalendarContext, isRecurringEvent, generateRecurringEvents, defaultTranslations, Weekday, WeekDays, UseIlamyResourceCalendarContextReturn, UseIlamyCalendarContextReturn, TranslatorFunction, Translations, TranslationKey,
|
|
520
|
+
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 };
|