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,44 @@
|
|
|
1
|
+
import { DateType } from '../utils/date';
|
|
2
|
+
import { CalendarEvent, EventListType } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the information for a single day in the calendar grid.
|
|
5
|
+
*/
|
|
6
|
+
interface CalendarDayInfo {
|
|
7
|
+
/** The full date object */
|
|
8
|
+
currentDate: DateType;
|
|
9
|
+
/** Whether the day belongs to the currently selected month (for styling) */
|
|
10
|
+
isCurrentMonth: boolean;
|
|
11
|
+
/** The day number to display (1-31) */
|
|
12
|
+
displayDay: number;
|
|
13
|
+
/** List of events or spacers for this day's slots */
|
|
14
|
+
events: (EventListType | null)[];
|
|
15
|
+
/** Total number of events on this day (including hidden ones) */
|
|
16
|
+
totalEvents: number;
|
|
17
|
+
/** Whether this day is today */
|
|
18
|
+
isToday: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 2D array representing the calendar grid: [week][day]
|
|
22
|
+
*/
|
|
23
|
+
type CalendarMatrix = CalendarDayInfo[][];
|
|
24
|
+
/**
|
|
25
|
+
* Generates the grid of days and events for the monthly view.
|
|
26
|
+
*
|
|
27
|
+
* This function handles:
|
|
28
|
+
* 1. Grid Generation: Calculates the days for each week, handling previous/next month overlap.
|
|
29
|
+
* 2. Event Processing: Filters events for each week and sorts them.
|
|
30
|
+
* 3. Slot Assignment: Uses a "tetris-like" algorithm to stack overlapping events into available vertical slots.
|
|
31
|
+
* 4. Data Preparation: Formats the data for the UI, including calculating event continuity across days.
|
|
32
|
+
*
|
|
33
|
+
* @param selectedDate - The currently selected date (determining the month to show)
|
|
34
|
+
* @returns A structured matrix of weeks and days with assigned events
|
|
35
|
+
*/
|
|
36
|
+
export interface UseMonthGridOptions {
|
|
37
|
+
enableEnrichedEvents?: boolean;
|
|
38
|
+
enrichedEventsByDate?: Record<string, CalendarEvent[]>;
|
|
39
|
+
eventsAreSorted?: boolean;
|
|
40
|
+
isEventOrderingEnabled?: boolean;
|
|
41
|
+
sortedMonthView?: boolean | ((a: CalendarEvent, b: CalendarEvent) => number);
|
|
42
|
+
}
|
|
43
|
+
export default function useMonthGrid(selectedDate: DateType, events: CalendarEvent[], weekStartsOn: number, weekEndsOn: number, options?: UseMonthGridOptions): CalendarMatrix;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to observe the size of an element.
|
|
4
|
+
*
|
|
5
|
+
* @param ref - React ref object attached to the element to observe.
|
|
6
|
+
* @param notNeeded - Optional flag to bypass the observer. Useful for performance
|
|
7
|
+
* if the observer is conditionally required.
|
|
8
|
+
* @returns An object containing the observed `width` and `height`.
|
|
9
|
+
*/
|
|
10
|
+
export default function useResizeObserver(ref: RefObject<HTMLElement | null>, notNeeded?: boolean): {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CalendarEvent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Properties for configuring the schedule view hook.
|
|
4
|
+
*/
|
|
5
|
+
interface UseScheduleViewProps {
|
|
6
|
+
events: CalendarEvent[];
|
|
7
|
+
autoScrollToCurrentTime?: boolean;
|
|
8
|
+
is12Hour?: boolean;
|
|
9
|
+
locale?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook to process calendar events into grouped daily lists for the Schedule agenda.
|
|
13
|
+
*
|
|
14
|
+
* @param props - Configuration properties { events, autoScrollToCurrentTime, is12Hour }
|
|
15
|
+
* @returns Object with a ref to attach to "today", the grouped event map, and formatters.
|
|
16
|
+
*/
|
|
17
|
+
export default function useScheduleView({ events, autoScrollToCurrentTime, is12Hour, locale, }: UseScheduleViewProps): {
|
|
18
|
+
todayRef: import('react').RefObject<HTMLDivElement | null>;
|
|
19
|
+
containerRef: import('react').RefObject<HTMLDivElement | null>;
|
|
20
|
+
groupedEvents: Record<string, CalendarEvent[]>;
|
|
21
|
+
renderEventTime: (event: CalendarEvent, dateKey: string) => string;
|
|
22
|
+
renderEventTitle: (event: CalendarEvent, dateKey: string) => string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as Calendar } from './Calendar';
|
|
2
|
+
export { EDayType, ECalendarViewType } from './types';
|
|
3
|
+
export type { CalendarProps, CalendarEvent, CalendarContentProps, ColorScheme, CalendarTheme, ThemeScheme, } from './types';
|
|
4
|
+
export type { HeaderProps } from './components/layout/Header';
|
|
5
|
+
export type { ViewProps } from './components/views/View';
|
|
6
|
+
export type { MonthViewProps } from './components/views/month_view/MonthView';
|
|
7
|
+
export type { WeekViewProps } from './components/views/week_view/WeekView';
|
|
8
|
+
export type { DayViewProps } from './components/views/day_view/DayView';
|
|
9
|
+
export type { ScheduleViewProps } from './components/views/schedule_view/ScheduleView';
|
|
10
|
+
export type { CustomViewProps } from './components/views/custom_days_view/CustomDaysView';
|
|
11
|
+
export { CalendarProvider, useCalendar } from './context/CalendarContext';
|
|
12
|
+
export { CALENDAR_ACTIONS } from './constants';
|
|
13
|
+
export default Calendar;
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const MonthViewKeyboardNav: Story;
|
|
7
|
+
export declare const WeekViewKeyboardNav: Story;
|
|
8
|
+
export declare const DayViewCreatableSlots: Story;
|
|
9
|
+
export declare const ScheduleViewKeyboardNav: Story;
|
|
10
|
+
export declare const PopoverFocusTrap: Story;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithEvents: Story;
|
|
8
|
+
export declare const FiveDays: Story;
|
|
9
|
+
export declare const OneDay: Story;
|
|
10
|
+
export declare const TenDays: Story;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const EventStyle: Story;
|
|
7
|
+
export declare const EventClassNames: Story;
|
|
8
|
+
export declare const ScheduleViewCustomization: Story;
|
|
9
|
+
export declare const CustomRenderers: Story;
|
|
10
|
+
export declare const PagerResets: Story;
|
|
11
|
+
export declare const ConcurrentEventStacking: Story;
|
|
12
|
+
export declare const ScheduleViewCustomSeparator: Story;
|
|
13
|
+
/** Forces the light palette regardless of OS preference. */
|
|
14
|
+
export declare const ColorSchemeLight: Story;
|
|
15
|
+
/** Forces the dark palette regardless of OS preference. */
|
|
16
|
+
export declare const ColorSchemeDark: Story;
|
|
17
|
+
/**
|
|
18
|
+
* Auto mode (default): follows the OS `prefers-color-scheme` preference.
|
|
19
|
+
* To verify the live-update behavior, change the OS theme (or use Chrome DevTools →
|
|
20
|
+
* Rendering → "Emulate CSS prefers-color-scheme") and watch the calendar reflow.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ColorSchemeAuto: Story;
|
|
23
|
+
/** Month view in dark mode — verifies grid borders, week number column, and adjacent-month cells. */
|
|
24
|
+
export declare const ColorSchemeDarkMonth: Story;
|
|
25
|
+
/** Schedule view in dark mode — verifies date number, event row, and divider colors. */
|
|
26
|
+
export declare const ColorSchemeDarkSchedule: Story;
|
|
27
|
+
/** Per-scheme theme overrides: dark mode uses a different selected/today color than light mode. */
|
|
28
|
+
export declare const ColorSchemePerSchemTheme: Story;
|
|
29
|
+
export declare const HideAllDayRow: Story;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithEvents: Story;
|
|
8
|
+
export declare const OverlappingEvents: Story;
|
|
9
|
+
export declare const Format12Hour: Story;
|
|
10
|
+
export declare const AutoScrollToCurrentTime: Story;
|
|
11
|
+
export declare const WithTimeLimits: Story;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const TimeFormat12Hour: Story;
|
|
7
|
+
export declare const TimeFormat24Hour: Story;
|
|
8
|
+
export declare const InteractiveEvents: Story;
|
|
9
|
+
export declare const InteractiveDates: Story;
|
|
10
|
+
export declare const NavigationCallback: Story;
|
|
11
|
+
export declare const MaxEventsOverflowLimit: Story;
|
|
12
|
+
export declare const CustomTheming: Story;
|
|
13
|
+
export declare const AutoScrollToCurrentTime: Story;
|
|
14
|
+
export declare const ShowAdjacentMonthsEnabled: Story;
|
|
15
|
+
export declare const ShowAdjacentMonthsDisabled: Story;
|
|
16
|
+
export declare const ClickToCreateTimeGrid: Story;
|
|
17
|
+
export declare const ClickToCreateMonth: Story;
|
|
18
|
+
export declare const ClickToCreateWithSelectable: Story;
|
|
19
|
+
export declare const CompoundComponentPattern: Story;
|
|
20
|
+
export declare const LoadingSkeletonMonth: Story;
|
|
21
|
+
export declare const LoadingSkeletonWeek: Story;
|
|
22
|
+
export declare const LoadingSkeletonDay: Story;
|
|
23
|
+
export declare const LoadingSkeletonSchedule: Story;
|
|
24
|
+
export declare const LoadingWithExistingEvents: Story;
|
|
25
|
+
export declare const LoadingCustomRenderer: Story;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const DynamicLocale: Story;
|
|
7
|
+
export declare const French: Story;
|
|
8
|
+
/**
|
|
9
|
+
* Arabic locale auto-derives `direction: "rtl"`. The calendar layout flips:
|
|
10
|
+
* navigation arrows mirror, time column moves to the right, day columns flow right-to-left.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ArabicRTL: Story;
|
|
13
|
+
/**
|
|
14
|
+
* Arabic content with explicit LTR layout — proves the `direction` prop overrides
|
|
15
|
+
* the locale auto-fallback.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ArabicLTR: Story;
|
|
18
|
+
/** Hebrew locale auto-derives RTL; shows month view flipped. */
|
|
19
|
+
export declare const HebrewRTL: Story;
|
|
20
|
+
export declare const WeekStartSaturday: Story;
|
|
21
|
+
export declare const JapaneseSchedule: Story;
|
|
22
|
+
export declare const CustomMessagesFull: Story;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithEvents: Story;
|
|
8
|
+
export declare const ManyEventsOverflow: Story;
|
|
9
|
+
export declare const ReadOnly: Story;
|
|
10
|
+
export declare const FullDayNames: Story;
|
|
11
|
+
export declare const CustomWeekStartEnd: Story;
|
|
12
|
+
export declare const ShowWeekNumbers: Story;
|
|
13
|
+
export declare const SortedMonthView: Story;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const AbsoluteOverlap: Story;
|
|
7
|
+
export declare const ConcurrentStress: Story;
|
|
8
|
+
export declare const NestedOverlaps: Story;
|
|
9
|
+
export declare const LayoutOverlapOffset: Story;
|
|
10
|
+
export declare const DurationOddities: Story;
|
|
11
|
+
export declare const MultiDayOvernight: Story;
|
|
12
|
+
export declare const MissingDataFields: Story;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const CallbacksAndSelectable: Story;
|
|
7
|
+
export declare const DisabledSelectable: Story;
|
|
8
|
+
export declare const ControlledState: Story;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const AllDayBannerConstraints: Story;
|
|
7
|
+
export declare const HideAllDayRow: Story;
|
|
8
|
+
export declare const AdjacentMonthsHidden: Story;
|
|
9
|
+
export declare const WorkWeekBoundaries: Story;
|
|
10
|
+
export declare const TimeRangeLimits: Story;
|
|
11
|
+
export declare const PastFutureYearBounds: Story;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const BaselineUnoptimized3000: Story;
|
|
7
|
+
export declare const SortedEventsBypass: Story;
|
|
8
|
+
export declare const FastUnorderedPlacement: Story;
|
|
9
|
+
export declare const EnrichedDictionaryFastPath: Story;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const TwelveHourFormat: Story;
|
|
7
|
+
export declare const TwentyFourHourFormat: Story;
|
|
8
|
+
export declare const ShowCurrentTimeIndicator: Story;
|
|
9
|
+
export declare const HideCurrentTimeIndicator: Story;
|
|
10
|
+
export declare const AutoScrollEnabled: Story;
|
|
11
|
+
export declare const AutoScrollDisabled: Story;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../../index';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const MonthViewTest: Story;
|
|
7
|
+
export declare const WeekViewTest: Story;
|
|
8
|
+
export declare const DayViewTest: Story;
|
|
9
|
+
export declare const CustomDaysTest: Story;
|
|
10
|
+
export declare const ScheduleViewTest: Story;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithEvents: Story;
|
|
8
|
+
export declare const Format12Hour: Story;
|
|
9
|
+
export declare const CustomTheme: Story;
|
|
10
|
+
export declare const AutoScrollToCurrentTime: Story;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as Calendar } from '../';
|
|
3
|
+
declare const meta: Meta<typeof Calendar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Calendar>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithEvents: Story;
|
|
8
|
+
export declare const OverlappingEvents: Story;
|
|
9
|
+
export declare const Format12Hour: Story;
|
|
10
|
+
export declare const FullDayNames: Story;
|
|
11
|
+
export declare const AutoScrollToCurrentTime: Story;
|
|
12
|
+
export declare const WithTimeLimits: Story;
|
|
13
|
+
export declare const CustomWeekStartEnd: Story;
|
|
14
|
+
export declare const MultiDayArrowTest: Story;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { CalendarEvent } from './events';
|
|
3
|
+
import { CalendarTheme, CalendarClassNames } from './theme';
|
|
4
|
+
/** Color palette modes accepted by `CalendarProps.colorScheme`. */
|
|
5
|
+
export type ColorScheme = "light" | "dark" | "auto";
|
|
6
|
+
/**
|
|
7
|
+
* Makes a specific subset of keys required while leaving the rest unchanged.
|
|
8
|
+
* Used to enforce that `CalendarContentProps` always has defaults applied.
|
|
9
|
+
*/
|
|
10
|
+
export type RequiredSome<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
11
|
+
/**
|
|
12
|
+
* Available calendar view modes.
|
|
13
|
+
* Use as values for the `view` prop or `onViewChange` callback.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ECalendarViewType: {
|
|
16
|
+
readonly month: "month";
|
|
17
|
+
readonly week: "week";
|
|
18
|
+
readonly day: "day";
|
|
19
|
+
readonly schedule: "schedule";
|
|
20
|
+
readonly customDays: "customDays";
|
|
21
|
+
};
|
|
22
|
+
export type ECalendarViewType = (typeof ECalendarViewType)[keyof typeof ECalendarViewType];
|
|
23
|
+
/**
|
|
24
|
+
* Controls how much of the day is shown in the time grid.
|
|
25
|
+
* `full` shows all 24 hours; `half` shows 12 hours (combined with `minHour`/`maxHour`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const EDayType: {
|
|
28
|
+
readonly full: "full";
|
|
29
|
+
readonly half: "half";
|
|
30
|
+
};
|
|
31
|
+
export type EDayType = (typeof EDayType)[keyof typeof EDayType];
|
|
32
|
+
/**
|
|
33
|
+
* Props passed to the `renderHeader` custom renderer.
|
|
34
|
+
* Provides the current navigation state and handlers to build a fully custom header.
|
|
35
|
+
*/
|
|
36
|
+
export interface RenderHeaderProps {
|
|
37
|
+
/** The currently displayed date (first day of the visible period). */
|
|
38
|
+
currentDate: Date;
|
|
39
|
+
/** The active view mode. */
|
|
40
|
+
view: ECalendarViewType;
|
|
41
|
+
/** Call with a target date to programmatically navigate the calendar. */
|
|
42
|
+
onNavigate: (date: Date) => void;
|
|
43
|
+
/** Call to switch the active view. */
|
|
44
|
+
onViewChange: (view: ECalendarViewType) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Props passed to the `renderDateCell` custom renderer in Month view.
|
|
48
|
+
* Allows replacing the default date number with a fully custom cell.
|
|
49
|
+
*/
|
|
50
|
+
export interface RenderDateCellProps {
|
|
51
|
+
/** The date this cell represents. */
|
|
52
|
+
date: Date;
|
|
53
|
+
/** Whether this cell is today's date. */
|
|
54
|
+
isToday: boolean;
|
|
55
|
+
/** Whether this cell is the currently selected date. */
|
|
56
|
+
isSelected?: boolean;
|
|
57
|
+
/** Whether this date belongs to the currently displayed month (false for adjacent-month cells). */
|
|
58
|
+
isCurrentMonth?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Top-level props for the `<Calendar>` component.
|
|
62
|
+
*/
|
|
63
|
+
export interface CalendarProps {
|
|
64
|
+
/** Child components rendered inside the calendar layout (e.g. custom header). */
|
|
65
|
+
children?: ReactNode;
|
|
66
|
+
/** Events to display. Each must have at minimum `startDate` and `title`. */
|
|
67
|
+
events?: CalendarEvent[];
|
|
68
|
+
/** Initially selected date. Defaults to today if omitted. */
|
|
69
|
+
selectedDate?: Date;
|
|
70
|
+
/** Active view mode. Defaults to `month`. */
|
|
71
|
+
view?: ECalendarViewType;
|
|
72
|
+
/** `data-testid` attribute placed on the root element for testing. */
|
|
73
|
+
testId?: string;
|
|
74
|
+
/**
|
|
75
|
+
* When `true`, activates loading mode. Behaviour depends on whether events are present:
|
|
76
|
+
* - **No events:** replaces the calendar body with a skeleton (or `renderLoading()` if provided).
|
|
77
|
+
* - **Events present:** keeps the calendar visible but wraps it in a non-interactive overlay
|
|
78
|
+
* so existing data stays on screen during a background refresh (DI-3).
|
|
79
|
+
*/
|
|
80
|
+
isLoading?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Custom loading indicator renderer. Called only when `isLoading=true` and no events are
|
|
83
|
+
* present. Falls back to a built-in view-specific skeleton when omitted.
|
|
84
|
+
*/
|
|
85
|
+
renderLoading?: () => ReactNode;
|
|
86
|
+
/** Use 12-hour clock format (AM/PM) in time grids. Defaults to `false`. */
|
|
87
|
+
is12Hour?: boolean;
|
|
88
|
+
/** Allow date cells to be clicked and selected. Defaults to `true`. */
|
|
89
|
+
selectable?: boolean;
|
|
90
|
+
/** Maximum number of events shown per day cell before a "+N more" overflow link appears. */
|
|
91
|
+
maxEvents?: number;
|
|
92
|
+
/** Controls time-grid range. `full` = all 24 h; `half` = respects `minHour`/`maxHour`. */
|
|
93
|
+
dayType?: EDayType;
|
|
94
|
+
/** Number of years before today available in the year picker. */
|
|
95
|
+
pastYearLength?: number;
|
|
96
|
+
/** Number of years after today available in the year picker. */
|
|
97
|
+
futureYearLength?: number;
|
|
98
|
+
/** Show a line indicating the current time in Week / Day views. */
|
|
99
|
+
showCurrentTime?: boolean;
|
|
100
|
+
/** Scroll the time grid to the current time on initial render. */
|
|
101
|
+
autoScrollToCurrentTime?: boolean;
|
|
102
|
+
/** Earliest hour shown in the time grid (0–23). */
|
|
103
|
+
minHour?: number;
|
|
104
|
+
/** Latest hour shown in the time grid (0–23). */
|
|
105
|
+
maxHour?: number;
|
|
106
|
+
/** First day of the week: 0 = Sunday, 1 = Monday … 6 = Saturday. */
|
|
107
|
+
weekStartsOn?: number;
|
|
108
|
+
/** Last day of the week: 0–6, must be after `weekStartsOn`. */
|
|
109
|
+
weekEndsOn?: number;
|
|
110
|
+
/** Show dates from the previous / next month in the month grid. */
|
|
111
|
+
showAdjacentMonths?: boolean;
|
|
112
|
+
/** Show ISO week numbers in the leftmost column of the month grid. */
|
|
113
|
+
showWeekNumbers?: boolean;
|
|
114
|
+
/** Number of days shown in the CustomDays view. */
|
|
115
|
+
customDays?: number;
|
|
116
|
+
/** Reset the selected date to today when switching views. */
|
|
117
|
+
resetDateOnViewChange?: boolean;
|
|
118
|
+
/** Show the all-day event banner row in Week / Day views. */
|
|
119
|
+
showAllDayRow?: boolean;
|
|
120
|
+
/** Custom renderer for the date separator in Schedule view. */
|
|
121
|
+
renderScheduleSeparator?: (date: Date) => ReactNode;
|
|
122
|
+
/** Pixel offset added between overlapping events in the time grid to keep them readable. */
|
|
123
|
+
eventOverlapOffset?: number;
|
|
124
|
+
/** CSS width of the calendar container (number = px, string = any CSS value). */
|
|
125
|
+
width?: number | string;
|
|
126
|
+
/** CSS height of the calendar container (number = px, string = any CSS value). */
|
|
127
|
+
height?: number | string;
|
|
128
|
+
/** Called when a date cell is clicked. */
|
|
129
|
+
onDateClick?: (date: Date) => void;
|
|
130
|
+
/** Called when an event chip is clicked. */
|
|
131
|
+
onEventClick?: (event: CalendarEvent) => void;
|
|
132
|
+
/** Called when the "+N more" overflow link is clicked. Receives the date and the hidden events. */
|
|
133
|
+
onMoreClick?: (date: Date, hiddenEvents?: CalendarEvent[]) => void;
|
|
134
|
+
/** Called when the calendar navigates to a different date. */
|
|
135
|
+
onNavigate?: (date: Date) => void;
|
|
136
|
+
/** Called when the user switches views. */
|
|
137
|
+
onViewChange?: (view: ECalendarViewType) => void;
|
|
138
|
+
/** Allow clicking empty time slots to create new events. */
|
|
139
|
+
creatable?: boolean;
|
|
140
|
+
/** Called when an empty time slot is clicked; receives the slot's start and end date. */
|
|
141
|
+
onSlotClick?: (startDate: Date, endDate: Date) => void;
|
|
142
|
+
/** Color theme overrides for selected, today, and default states. */
|
|
143
|
+
theme?: CalendarTheme;
|
|
144
|
+
/** CSS class name overrides for individual calendar elements. */
|
|
145
|
+
classNames?: CalendarClassNames;
|
|
146
|
+
/** Replaces the default event chip with a fully custom renderer. */
|
|
147
|
+
renderEvent?: (event: CalendarEvent) => ReactNode;
|
|
148
|
+
/** Replaces the entire header bar with a custom renderer. */
|
|
149
|
+
renderHeader?: (props: RenderHeaderProps) => ReactNode;
|
|
150
|
+
/** Replaces the default hour label in the time grid left column. */
|
|
151
|
+
renderHourCell?: (date: Date) => ReactNode;
|
|
152
|
+
/** Replaces the default date number in Month view cells. */
|
|
153
|
+
renderDateCell?: (props: RenderDateCellProps) => ReactNode;
|
|
154
|
+
/** Pre-built O(1) lookup map of events keyed by date string. Avoids re-filtering on each render. */
|
|
155
|
+
enrichedEventsByDate?: Record<string, CalendarEvent[]>;
|
|
156
|
+
/** Enable O(1) event lookup via `enrichedEventsByDate`. */
|
|
157
|
+
enableEnrichedEvents?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Skip internal validation when events are already sorted by `startDate` ascending.
|
|
160
|
+
*
|
|
161
|
+
* **Known caveat:** the library does not re-sort the array. If unsorted events are
|
|
162
|
+
* passed with this flag set to `true`, they will render in the order provided.
|
|
163
|
+
* Only set this flag when the input is guaranteed to be sorted.
|
|
164
|
+
*/
|
|
165
|
+
eventsAreSorted?: boolean;
|
|
166
|
+
/** Maintain stable visual ordering of overlapping events across re-renders. */
|
|
167
|
+
isEventOrderingEnabled?: boolean;
|
|
168
|
+
/** Sort events within Month view cells. Pass `true` for default sort or a comparator for custom order. */
|
|
169
|
+
sortedMonthView?: boolean | ((a: CalendarEvent, b: CalendarEvent) => number);
|
|
170
|
+
/** Luxon locale code (e.g. `'en'`, `'fr'`, `'es-MX'`). Controls date formatting language. */
|
|
171
|
+
locale?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Layout direction. When omitted, falls back to `'rtl'` if `locale` is in the RTL locale list
|
|
174
|
+
* (ar, he, fa, ur, ps, sd, ckb, yi); otherwise `'ltr'`.
|
|
175
|
+
*/
|
|
176
|
+
direction?: "ltr" | "rtl";
|
|
177
|
+
/**
|
|
178
|
+
* Controls the color palette of the calendar.
|
|
179
|
+
* - `'auto'` (default): follows the OS `prefers-color-scheme` preference and updates live
|
|
180
|
+
* when the user toggles their OS theme.
|
|
181
|
+
* - `'light'` / `'dark'`: forces the palette regardless of OS preference.
|
|
182
|
+
*
|
|
183
|
+
* The resolved scheme is applied as `data-color-scheme="light"|"dark"` on the calendar root,
|
|
184
|
+
* which switches the CSS custom-property palette via attribute-selector overrides in
|
|
185
|
+
* `src/styles/variables.css`. The `theme` prop (per-event inline color overrides) still wins.
|
|
186
|
+
*/
|
|
187
|
+
colorScheme?: ColorScheme;
|
|
188
|
+
/** Overrides for built-in UI strings (navigation buttons, view names, etc.). */
|
|
189
|
+
localeMessages?: {
|
|
190
|
+
today?: string;
|
|
191
|
+
day?: string;
|
|
192
|
+
week?: string;
|
|
193
|
+
month?: string;
|
|
194
|
+
schedule?: string;
|
|
195
|
+
/** Label suffix in the custom days dropdown (e.g. `'Days'` → "3 Days"). */
|
|
196
|
+
days?: string;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Internal props type used by all view components after defaults have been applied.
|
|
201
|
+
* Extends `CalendarProps` with a required subset of keys so views never need to null-check defaults.
|
|
202
|
+
*/
|
|
203
|
+
export interface CalendarContentProps extends RequiredSome<CalendarProps, "events" | "view" | "is12Hour" | "selectable" | "creatable" | "dayType" | "pastYearLength" | "futureYearLength" | "showCurrentTime" | "autoScrollToCurrentTime" | "minHour" | "maxHour" | "weekStartsOn" | "weekEndsOn" | "showAdjacentMonths" | "showWeekNumbers" | "resetDateOnViewChange" | "showAllDayRow" | "width" | "height" | "theme" | "classNames" | "eventOverlapOffset" | "enableEnrichedEvents" | "eventsAreSorted" | "isEventOrderingEnabled" | "sortedMonthView" | "testId" | "locale" | "localeMessages"> {
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A month entry used in the month picker dropdown.
|
|
207
|
+
*/
|
|
208
|
+
export interface MonthListType {
|
|
209
|
+
/** Localized month name (e.g. "January"). */
|
|
210
|
+
label: string;
|
|
211
|
+
/** 1-based month number (1 = January … 12 = December). */
|
|
212
|
+
value: number;
|
|
213
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a single calendar event.
|
|
4
|
+
*/
|
|
5
|
+
export interface CalendarEvent {
|
|
6
|
+
/** Unique identifier for the event. Used for deduplication and React keying. */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** ISO 8601 start date. Use `YYYY-MM-DD` for all-day events, `YYYY-MM-DDTHH:mm:ss` for timed events. */
|
|
9
|
+
startDate: string;
|
|
10
|
+
/**
|
|
11
|
+
* ISO 8601 end date. Omit for single-day events; set to a later date for multi-day
|
|
12
|
+
* spanning events. If set to a date before `startDate`, the event is silently filtered
|
|
13
|
+
* by `useEvents` (negative-duration guard, C-TC3).
|
|
14
|
+
*/
|
|
15
|
+
endDate?: string;
|
|
16
|
+
/** Display title shown on the event chip. */
|
|
17
|
+
title: string;
|
|
18
|
+
/** Inline styles applied directly to the event element. */
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
/** Allows arbitrary custom fields to be attached and accessed in custom renderers. */
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Internal enriched event type used by layout algorithms.
|
|
25
|
+
* Extends `CalendarEvent` with week-boundary clipping fields, or marks the slot as a spacer
|
|
26
|
+
* to preserve grid positions when events overflow the visible row limit.
|
|
27
|
+
*/
|
|
28
|
+
export type EventListType = (CalendarEvent & {
|
|
29
|
+
startDateWeek: string;
|
|
30
|
+
endDateWeek?: string;
|
|
31
|
+
isSpacer?: false;
|
|
32
|
+
}) | (CalendarEvent & {
|
|
33
|
+
isSpacer: true;
|
|
34
|
+
});
|