calendar-simple 1.2.0 → 2.0.0-beta.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/LICENSE +1 -1
- package/README.md +371 -62
- package/dist/calendar-simple.css +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +7588 -978
- package/dist/index.es.js.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/src/Calendar.d.ts +19 -0
- package/dist/src/Calendar.test.d.ts +1 -0
- package/dist/src/assets/LeftArrow.d.ts +3 -0
- package/dist/src/assets/RightArrow.d.ts +3 -0
- package/dist/src/components/core/all_day_banner/AllDayBanner.d.ts +9 -0
- package/dist/src/components/core/all_day_banner/AllDayBanner.test.d.ts +1 -0
- package/dist/src/components/core/current_time_line/CurrentTimeLine.d.ts +7 -0
- package/dist/src/components/core/current_time_line/CurrentTimeLine.test.d.ts +1 -0
- package/dist/src/components/core/day_column/DayColumn.d.ts +11 -0
- package/dist/src/components/core/day_column/DayColumn.test.d.ts +1 -0
- package/dist/src/components/core/day_event_item/DayWeekEventItem.d.ts +8 -0
- package/dist/src/components/core/day_event_item/DayWeekEventItem.test.d.ts +1 -0
- package/dist/src/components/core/month_event_item/MonthEventItem.d.ts +21 -0
- package/dist/src/components/core/month_event_item/MonthEventItem.test.d.ts +1 -0
- package/dist/src/components/core/time_column/TimeColumn.d.ts +6 -0
- package/dist/src/components/core/time_column/TimeColumn.test.d.ts +1 -0
- package/dist/src/components/layout/Header.d.ts +7 -0
- package/dist/src/components/layout/Header.test.d.ts +1 -0
- package/dist/src/components/ui/CalendarErrorBoundary.d.ts +14 -0
- package/dist/src/components/ui/popover/Popover.d.ts +11 -0
- package/dist/src/components/ui/popover/Popover.test.d.ts +1 -0
- package/dist/src/components/ui/skeleton/MonthSkeleton.d.ts +2 -0
- package/dist/src/components/ui/skeleton/MonthSkeleton.test.d.ts +1 -0
- package/dist/src/components/ui/skeleton/ScheduleSkeleton.d.ts +2 -0
- package/dist/src/components/ui/skeleton/ScheduleSkeleton.test.d.ts +1 -0
- package/dist/src/components/ui/skeleton/TimeGridSkeleton.d.ts +2 -0
- package/dist/src/components/ui/skeleton/TimeGridSkeleton.test.d.ts +1 -0
- package/dist/src/components/views/View.d.ts +4 -0
- package/dist/src/components/views/View.test.d.ts +1 -0
- package/dist/src/components/views/custom_days_view/CustomDaysView.d.ts +5 -0
- package/dist/src/components/views/custom_days_view/CustomDaysView.test.d.ts +1 -0
- package/dist/src/components/views/day_view/DayView.d.ts +5 -0
- package/dist/src/components/views/day_view/DayView.test.d.ts +1 -0
- package/dist/src/components/views/month_view/MonthView.d.ts +5 -0
- package/dist/src/components/views/month_view/MonthView.test.d.ts +1 -0
- package/dist/src/components/views/schedule_view/ScheduleView.d.ts +4 -0
- package/dist/src/components/views/schedule_view/ScheduleView.test.d.ts +1 -0
- package/dist/src/components/views/week_view/WeekView.d.ts +5 -0
- package/dist/src/components/views/week_view/WeekView.test.d.ts +1 -0
- package/dist/src/constants/calendar.d.ts +96 -0
- package/dist/src/constants/index.d.ts +2 -0
- package/dist/src/constants/theme.d.ts +38 -0
- package/dist/src/context/CalendarContext.d.ts +83 -0
- package/dist/src/context/CalendarContext.test.d.ts +1 -0
- package/dist/src/hooks/useAllDayBanner.d.ts +48 -0
- package/dist/src/hooks/useAllDayBanner.test.d.ts +1 -0
- package/dist/src/hooks/useCalendarProps.d.ts +10 -0
- package/dist/src/hooks/useColorScheme.d.ts +2 -0
- package/dist/src/hooks/useColorScheme.test.d.ts +1 -0
- package/dist/src/hooks/useDayEventLayout.d.ts +27 -0
- package/dist/src/hooks/useDayEventLayout.test.d.ts +1 -0
- package/dist/src/hooks/useEvents.d.ts +16 -0
- package/dist/src/hooks/useEvents.test.d.ts +1 -0
- package/dist/src/hooks/useMonthGrid.d.ts +44 -0
- package/dist/src/hooks/useMonthGrid.test.d.ts +1 -0
- package/dist/src/hooks/useResizeObserver.d.ts +13 -0
- package/dist/src/hooks/useResizeObserver.test.d.ts +1 -0
- package/dist/src/hooks/useScheduleView.d.ts +24 -0
- package/dist/src/hooks/useScheduleView.test.d.ts +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/setupTests.d.ts +0 -0
- package/dist/src/stories/Accessibility.stories.d.ts +10 -0
- package/dist/src/stories/CustomDayView.stories.d.ts +10 -0
- package/dist/src/stories/Customization.stories.d.ts +29 -0
- package/dist/src/stories/DayView.stories.d.ts +11 -0
- package/dist/src/stories/Features.stories.d.ts +25 -0
- package/dist/src/stories/Localization.stories.d.ts +22 -0
- package/dist/src/stories/MonthView.stories.d.ts +13 -0
- package/dist/src/stories/QA/EdgeCases.stories.d.ts +12 -0
- package/dist/src/stories/QA/Interactions.stories.d.ts +8 -0
- package/dist/src/stories/QA/LayoutLimits.stories.d.ts +11 -0
- package/dist/src/stories/QA/Performance.stories.d.ts +9 -0
- package/dist/src/stories/QA/TimeFormatting.stories.d.ts +11 -0
- package/dist/src/stories/QA/Views.stories.d.ts +10 -0
- package/dist/src/stories/ScheduleView.stories.d.ts +10 -0
- package/dist/src/stories/WeekView.stories.d.ts +14 -0
- package/dist/src/types/calendar.d.ts +213 -0
- package/dist/src/types/events.d.ts +34 -0
- package/dist/src/types/index.d.ts +3 -0
- package/dist/src/types/theme.d.ts +81 -0
- package/dist/src/utils/common.d.ts +48 -0
- package/dist/src/utils/common.test.d.ts +1 -0
- package/dist/src/utils/contrast.d.ts +18 -0
- package/dist/src/utils/contrast.test.d.ts +1 -0
- package/dist/src/utils/date.d.ts +55 -0
- package/dist/src/utils/date.test.d.ts +1 -0
- package/dist/src/utils/formatting.d.ts +21 -0
- package/dist/src/utils/formatting.test.d.ts +1 -0
- package/dist/src/utils/index.d.ts +9 -0
- package/dist/stats.html +4950 -0
- package/package.json +56 -16
- package/dist/index.d.ts +0 -60
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Theme and CSS class name customization types for the calendar.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* CSS class name overrides for individual calendar elements.
|
|
6
|
+
* Each key targets a specific DOM element; assign a custom class to override default styles.
|
|
7
|
+
*/
|
|
8
|
+
export interface CalendarClassNames {
|
|
9
|
+
/** Root calendar container. */
|
|
10
|
+
root?: string;
|
|
11
|
+
/** Header bar containing navigation controls and view switcher. */
|
|
12
|
+
header?: string;
|
|
13
|
+
/** Month view table grid. */
|
|
14
|
+
table?: string;
|
|
15
|
+
/** Day-of-week header row in the month grid. */
|
|
16
|
+
tableHeader?: string;
|
|
17
|
+
/** Individual date cell in the month grid. */
|
|
18
|
+
tableDate?: string;
|
|
19
|
+
/** Week number label in the leftmost column (requires `showWeekNumbers`). */
|
|
20
|
+
weekNumber?: string;
|
|
21
|
+
/** Event chip element — applies across all views. */
|
|
22
|
+
event?: string;
|
|
23
|
+
/** Date cell or event marked as currently selected. */
|
|
24
|
+
selected?: string;
|
|
25
|
+
/** Date cell or event representing today. */
|
|
26
|
+
today?: string;
|
|
27
|
+
/** Date column header in Week / Day views. */
|
|
28
|
+
dayHeader?: string;
|
|
29
|
+
/** Day name label (e.g. "Mon") inside the column header. */
|
|
30
|
+
dayName?: string;
|
|
31
|
+
/** Day number label inside the column header. */
|
|
32
|
+
dayNumber?: string;
|
|
33
|
+
/** Left-side time label column in the time grid. */
|
|
34
|
+
timeColumn?: string;
|
|
35
|
+
/** Individual hour row in the time grid. */
|
|
36
|
+
timeSlot?: string;
|
|
37
|
+
/** Vertical day column in the time grid. */
|
|
38
|
+
dayColumn?: string;
|
|
39
|
+
/** Date group header row in Schedule view. */
|
|
40
|
+
scheduleDateGroup?: string;
|
|
41
|
+
/** Date number within the Schedule view group header. */
|
|
42
|
+
scheduleDateNumber?: string;
|
|
43
|
+
/** Sub-info text (day name / relative label) in the Schedule group header. */
|
|
44
|
+
scheduleDateSubInfo?: string;
|
|
45
|
+
/** Time label on a Schedule event row. */
|
|
46
|
+
scheduleTime?: string;
|
|
47
|
+
/** Title label on a Schedule event row. */
|
|
48
|
+
scheduleTitle?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A color pair (text + background) used for theme state overrides.
|
|
52
|
+
*/
|
|
53
|
+
export interface ThemeStyle {
|
|
54
|
+
/** Text / foreground color (any valid CSS color value). */
|
|
55
|
+
color?: string;
|
|
56
|
+
/** Background color (any valid CSS color value). */
|
|
57
|
+
bgColor?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Per-state color overrides for a single color scheme.
|
|
61
|
+
*/
|
|
62
|
+
export interface ThemeScheme {
|
|
63
|
+
/** Colors for standard, unselected, non-today date cells. */
|
|
64
|
+
default?: ThemeStyle;
|
|
65
|
+
/** Colors for the currently selected date. */
|
|
66
|
+
selected?: ThemeStyle;
|
|
67
|
+
/** Colors for today's date cell. */
|
|
68
|
+
today?: ThemeStyle;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Color overrides applied to key calendar states.
|
|
72
|
+
* Flat keys apply to both schemes unless overridden.
|
|
73
|
+
* `dark` / `light` sub-objects take precedence over flat keys
|
|
74
|
+
* when the resolved color scheme matches.
|
|
75
|
+
*/
|
|
76
|
+
export interface CalendarTheme extends ThemeScheme {
|
|
77
|
+
/** Overrides applied only when the resolved scheme is "dark". */
|
|
78
|
+
dark?: ThemeScheme;
|
|
79
|
+
/** Overrides applied only when the resolved scheme is "light". */
|
|
80
|
+
light?: ThemeScheme;
|
|
81
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react';
|
|
2
|
+
import { CalendarEvent } from '../types';
|
|
3
|
+
import { DateType } from './date';
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the maximum number of events that can be displayed in a cell based on the calendar height.
|
|
6
|
+
*
|
|
7
|
+
* @param height - The total height of the calendar
|
|
8
|
+
* @returns The maximum number of events to display
|
|
9
|
+
*/
|
|
10
|
+
export declare function calculateMaxEvents(height: number, rowsInView: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Helper to determine if an event is an all-day event.
|
|
13
|
+
* An event is considered "all-day" if its start and end date strings
|
|
14
|
+
* contain only a date (e.g. yyyy-MM-dd) and no time component (no 'T' or space).
|
|
15
|
+
*
|
|
16
|
+
* @param event - The calendar event to check.
|
|
17
|
+
* @returns True if the event has no time payload.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isAllDayEvent(event: CalendarEvent): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Helper to determine if an event spans across multiple distinct calendar days.
|
|
22
|
+
* Compares the start of the day for both startDate and endDate.
|
|
23
|
+
*
|
|
24
|
+
* @param event - The calendar event to check.
|
|
25
|
+
* @returns True if the event starts and ends on different days.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isMultiDay(event: CalendarEvent): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Calculates the overlap duration in hours of an event with a specific calendar day boundary (00:00 to 23:59).
|
|
30
|
+
*
|
|
31
|
+
* @param event - The calendar event.
|
|
32
|
+
* @param date - The day to check the overlap against.
|
|
33
|
+
* @returns The overlap duration in hours (e.g., 2.5). Returns 24 for all-day events.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getEventOverlapInHours(event: CalendarEvent, date: DateType): number;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves layout direction. Explicit `direction` prop wins; otherwise infers from
|
|
38
|
+
* the locale's primary subtag. Defaults to `'ltr'` when both are undefined.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveDirection(direction: "ltr" | "rtl" | undefined, locale: string | undefined): "ltr" | "rtl";
|
|
41
|
+
/**
|
|
42
|
+
* Wraps a handler so it only fires on Enter or Space — the standard keyboard activation keys.
|
|
43
|
+
* Prevents default and stops propagation to avoid scroll or form submission side effects.
|
|
44
|
+
*
|
|
45
|
+
* @param handler - The callback to invoke on activation.
|
|
46
|
+
* @returns A keyboard event handler suitable for `onKeyDown`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function handleKeyboardActivation(handler: (e: KeyboardEvent) => void): (e: KeyboardEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CalendarTheme, ThemeScheme } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines the best contrast color (black or white) for a given background color.
|
|
4
|
+
* Follows WCAG 2.1 standards for readability.
|
|
5
|
+
*
|
|
6
|
+
* @param bgColor - The CSS background color (Hex, RGB, or named color).
|
|
7
|
+
* @returns "#FFFFFF" or "#212529" (a very dark gray, softer than pure black).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getContrastColor(bgColor?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Merges flat CalendarTheme values with the scheme-specific sub-object.
|
|
12
|
+
* Scheme-specific values win on a per-field basis.
|
|
13
|
+
*
|
|
14
|
+
* @param theme - Raw theme from CalendarProps (may be undefined or {}).
|
|
15
|
+
* @param scheme - Resolved color scheme ("light" | "dark") from context.
|
|
16
|
+
* @returns A flat ThemeScheme with no nested keys.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveTheme(theme: CalendarTheme | undefined, scheme: "light" | "dark"): ThemeScheme;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
export type DateType = DateTime;
|
|
3
|
+
export type DateInputType = Date | DateTime | string | number;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes various date inputs into a Luxon DateTime object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dateFn(date?: DateInputType): DateTime;
|
|
8
|
+
export declare function getStartOfDay(date: DateInputType): DateType;
|
|
9
|
+
export declare function getStartOfMonth(date: DateType): DateType;
|
|
10
|
+
export declare function addDays(date: DateType, days: number): DateType;
|
|
11
|
+
export declare function subDays(date: DateType, days: number): DateType;
|
|
12
|
+
export declare function getDiffDays(date1: DateInputType, date2: DateInputType): number;
|
|
13
|
+
export declare function setDate(date: DateType, day: number): DateType;
|
|
14
|
+
export declare function setMonth(date: DateType, month: number): DateType;
|
|
15
|
+
export declare function setYear(date: DateType, year: number): DateType;
|
|
16
|
+
export declare function getDate(date: DateType): number;
|
|
17
|
+
export declare function getMonth(date: DateType): number;
|
|
18
|
+
export declare function getYear(date: DateType): number;
|
|
19
|
+
export declare function isBeforeDate(date1: DateInputType, date2: DateInputType): boolean;
|
|
20
|
+
export declare function isAfterDate(date1: DateInputType, date2: DateInputType): boolean;
|
|
21
|
+
export declare function isSameDate(date1: DateInputType, date2: DateInputType): boolean;
|
|
22
|
+
export declare function formatDate(date: DateInputType, format: string, locale?: string): string;
|
|
23
|
+
export declare function convertToDate(luxonDate: DateType): Date;
|
|
24
|
+
/**
|
|
25
|
+
* Determines the day of the week (0-6)
|
|
26
|
+
*
|
|
27
|
+
* @param date - A DateType representing the target date.
|
|
28
|
+
* @returns The numeric index of the day (0 = Sunday, 1 = Monday, etc.).
|
|
29
|
+
*/
|
|
30
|
+
export declare function getDayOfWeek(date: DateType): number;
|
|
31
|
+
/**
|
|
32
|
+
* Determines the day of the week (0-6) on which a given month starts.
|
|
33
|
+
*
|
|
34
|
+
* @param date - A DateType representing the target month.
|
|
35
|
+
* @returns The numeric index of the starting day (0 = Sunday, 1 = Monday, etc.).
|
|
36
|
+
*/
|
|
37
|
+
export declare function getMonthStartingDay(date: DateType): number;
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether a specific numeric date within a targeted month matches today's date.
|
|
40
|
+
*
|
|
41
|
+
* @param selectedDate - The base month/year context.
|
|
42
|
+
* @param dates - The specific numeric day of the month (1-31).
|
|
43
|
+
* @returns True if the assembled date is the exact current calendar day.
|
|
44
|
+
*/
|
|
45
|
+
export declare function checkIsToday(selectedDate: DateType, dates: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Generates an array of years centered around or including the `selectedYear`.
|
|
48
|
+
* Useful for populating year-selection dropdowns or pickers.
|
|
49
|
+
*
|
|
50
|
+
* @param pastLength - Number of historical years to include from the current date.
|
|
51
|
+
* @param futureLength - Number of future years to include from the current date.
|
|
52
|
+
* @param selectedYear - Ensures this year is included in the array if it falls outside the requested bounds.
|
|
53
|
+
* @returns An array of numeric years.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getYearList(pastLength: number, futureLength: number, selectedYear: number): number[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CalendarEvent, ECalendarViewType, EDayType, MonthListType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the tooltip text for an event based on the view type.
|
|
4
|
+
* Adapts the formatting (whether to include explicit dates, times, or both)
|
|
5
|
+
* dynamically based on if it's month/week view, or all-day vs timed.
|
|
6
|
+
*
|
|
7
|
+
* @param event - The calendar event hovering over.
|
|
8
|
+
* @param viewType - The current enum view mode of the calendar.
|
|
9
|
+
* @param is12Hour - Boolean indicating if the user is employing a 12-hour clock.
|
|
10
|
+
* @returns A formatted string ready for tooltip display.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateTooltipText(event: CalendarEvent, viewType: ECalendarViewType, is12Hour?: boolean, locale?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a formatted GMT offset string based on the user's local timezone.
|
|
15
|
+
* Useful for displaying timezone indicators on the calendar grid.
|
|
16
|
+
*
|
|
17
|
+
* @returns A formatted string like "GMT+05:30" or "GMT-08".
|
|
18
|
+
*/
|
|
19
|
+
export declare function getGmtOffset(): string;
|
|
20
|
+
export declare function getDayListNames(dayType: EDayType, locale?: string): string[];
|
|
21
|
+
export declare function getMonthList(locale?: string): MonthListType[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel file exporting all shared utility functions to abstract away
|
|
4
|
+
* internal file structures from consumers.
|
|
5
|
+
*/
|
|
6
|
+
export * from './date';
|
|
7
|
+
export * from './common';
|
|
8
|
+
export * from './formatting';
|
|
9
|
+
export * from './contrast';
|