@super-calendar/dom 2.0.0 → 2.1.3
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 +65 -0
- package/dist/index.d.mts +89 -8
- package/dist/index.d.ts +89 -8
- package/dist/index.js +25 -1
- package/dist/index.mjs +25 -1
- package/package.json +5 -5
- package/src/Agenda.tsx +17 -2
- package/src/Calendar.tsx +12 -2
- package/src/MonthList.tsx +11 -2
- package/src/MonthView.tsx +16 -2
- package/src/TimeGrid.tsx +31 -2
- package/src/index.ts +21 -4
- package/src/theme.ts +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @super-calendar/dom
|
|
2
|
+
|
|
3
|
+
[](https://jsr.io/@super-calendar/dom) [](https://jsr.io/@super-calendar/dom)
|
|
4
|
+
|
|
5
|
+
The react-dom renderer for [super-calendar](https://github.com/afonsojramos/react-native-super-calendar): a virtualized **month / week / day** calendar and date picker built from real DOM components. No React Native, no react-native-web.
|
|
6
|
+
|
|
7
|
+
It is built on the headless [`@super-calendar/core`](https://jsr.io/@super-calendar/core) and Legend List's DOM renderer.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
# Deno
|
|
13
|
+
deno add jsr:@super-calendar/dom
|
|
14
|
+
|
|
15
|
+
# npm / pnpm / yarn / bun
|
|
16
|
+
npx jsr add @super-calendar/dom
|
|
17
|
+
pnpm dlx jsr add @super-calendar/dom
|
|
18
|
+
bunx jsr add @super-calendar/dom
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Peer dependencies: `@legendapp/list` (>=3), `date-fns` (>=3), `react` (>=19), and `react-dom` (>=19).
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useState } from "react";
|
|
27
|
+
import { Calendar, type CalendarEvent } from "@super-calendar/dom";
|
|
28
|
+
|
|
29
|
+
type MyEvent = { id: string; color: string };
|
|
30
|
+
|
|
31
|
+
const events: CalendarEvent<MyEvent>[] = [
|
|
32
|
+
{
|
|
33
|
+
id: "1",
|
|
34
|
+
color: "#1F6FEB",
|
|
35
|
+
title: "Lecture",
|
|
36
|
+
start: new Date(2026, 5, 19, 10, 0),
|
|
37
|
+
end: new Date(2026, 5, 19, 11, 30),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
export function MyCalendar() {
|
|
42
|
+
const [date, setDate] = useState(new Date());
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Calendar
|
|
46
|
+
mode="week"
|
|
47
|
+
date={date}
|
|
48
|
+
events={events}
|
|
49
|
+
weekStartsOn={1}
|
|
50
|
+
onPressDay={setDate}
|
|
51
|
+
onPressEvent={(event) => console.log(event.id)}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For a custom picker, pair the headless hooks (`useDateRange`, `useMonthGrid`) with `MonthList` and `TimeGrid`, all re-exported from this package.
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
See the [full documentation](https://super-calendar.afonsojramos.me), the [quickstart](https://super-calendar.afonsojramos.me/quickstart), and the [API reference](https://super-calendar.afonsojramos.me/reference/api).
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Locale } from "date-fns";
|
|
2
|
-
import { CSSProperties, ComponentType, ReactNode } from "react";
|
|
2
|
+
import { CSSProperties, ComponentType, ReactElement, ReactNode } from "react";
|
|
3
3
|
import { BusinessHours, BusinessHours as BusinessHours$1, CalendarColors, CalendarEvent, CalendarEvent as CalendarEvent$1, CalendarMode, CalendarMode as CalendarMode$1, DateRange, DateRange as DateRange$1, DateSelectionConstraints, DateSelectionConstraints as DateSelectionConstraints$1, DaySelectionState, ICalendarEvent, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, TimeGridMode, TimeGridMode as TimeGridMode$1, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekStartsOn as WeekStartsOn$1, buildMonthGrid, daySelectionState, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
|
|
4
4
|
|
|
5
5
|
//#region src/theme.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Theme for the react-dom renderer. Combines the shared color palette from
|
|
8
|
+
* `@super-calendar/core` with the DOM-specific pixel metrics and font stack.
|
|
9
|
+
*/
|
|
6
10
|
type DomCalendarTheme = CalendarColors & {
|
|
7
11
|
/** Row height of a day cell, in px. */cellHeight: number; /** Diameter of the day badge, in px. */
|
|
8
12
|
dayBadgeSize: number;
|
|
@@ -14,7 +18,9 @@ type DomCalendarTheme = CalendarColors & {
|
|
|
14
18
|
rangeBandHeight: number; /** Font stack for the calendar. */
|
|
15
19
|
fontFamily: string;
|
|
16
20
|
};
|
|
21
|
+
/** The default light theme: the core light palette plus the DOM metrics. */
|
|
17
22
|
declare const defaultDomTheme: DomCalendarTheme;
|
|
23
|
+
/** The dark theme: the core dark palette plus the DOM metrics. */
|
|
18
24
|
declare const darkDomTheme: DomCalendarTheme;
|
|
19
25
|
/** Merge a partial override onto a base theme (defaults to {@link defaultDomTheme}). */
|
|
20
26
|
declare function mergeDomTheme(overrides?: Partial<DomCalendarTheme>, base?: DomCalendarTheme): DomCalendarTheme;
|
|
@@ -22,32 +28,42 @@ declare function mergeDomTheme(overrides?: Partial<DomCalendarTheme>, base?: Dom
|
|
|
22
28
|
//#region src/Agenda.d.ts
|
|
23
29
|
/** Props passed to a custom agenda (schedule) event renderer. */
|
|
24
30
|
interface DomAgendaEventArgs<T = unknown> {
|
|
31
|
+
/** The event to render. */
|
|
25
32
|
event: CalendarEvent$1<T>;
|
|
26
33
|
/** Always "schedule"; lets a renderer shared with other views branch on it. */
|
|
27
34
|
mode: "schedule";
|
|
35
|
+
/** Whether the event is all-day. */
|
|
28
36
|
isAllDay: boolean;
|
|
29
37
|
/** Render the time range in 12-hour AM/PM. */
|
|
30
38
|
ampm?: boolean;
|
|
39
|
+
/** Call to fire the view's `onPressEvent` for this row. */
|
|
31
40
|
onPress: () => void;
|
|
32
41
|
}
|
|
42
|
+
/** A component that renders a single agenda (schedule) event row. */
|
|
33
43
|
type DomAgendaEvent<T = unknown> = ComponentType<DomAgendaEventArgs<T>>;
|
|
44
|
+
/** Props for {@link Agenda}. */
|
|
34
45
|
interface AgendaProps<T = unknown> {
|
|
35
46
|
/** Events to list. The consumer controls which (and therefore the date range). */
|
|
36
47
|
events: CalendarEvent$1<T>[];
|
|
48
|
+
/** date-fns locale for the day headers and time labels. */
|
|
37
49
|
locale?: Locale;
|
|
38
50
|
/** Render times in 12-hour AM/PM (default false, 24h). */
|
|
39
51
|
ampm?: boolean;
|
|
40
52
|
/** Highlight this date's header instead of the real "today". */
|
|
41
53
|
activeDate?: Date;
|
|
54
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
42
55
|
theme?: Partial<DomCalendarTheme>;
|
|
43
56
|
/** Height of the scroll viewport, in px (default 480). */
|
|
44
57
|
height?: number | string;
|
|
45
58
|
/** Replace the built-in event row. */
|
|
46
59
|
renderEvent?: DomAgendaEvent<T>;
|
|
60
|
+
/** Tap an event row. */
|
|
47
61
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
48
62
|
/** Tap a day's header. */
|
|
49
63
|
onPressDay?: (date: Date) => void;
|
|
64
|
+
/** Class applied to the root element. */
|
|
50
65
|
className?: string;
|
|
66
|
+
/** Inline styles applied to the root element. */
|
|
51
67
|
style?: CSSProperties;
|
|
52
68
|
}
|
|
53
69
|
/**
|
|
@@ -55,6 +71,11 @@ interface AgendaProps<T = unknown> {
|
|
|
55
71
|
* elements. Events are sorted by start and grouped under a date header per day;
|
|
56
72
|
* the consumer controls which events (and therefore which dates) are shown. The
|
|
57
73
|
* react-dom counterpart of the React Native `Agenda`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
78
|
+
* ```
|
|
58
79
|
*/
|
|
59
80
|
declare function Agenda<T = unknown>({
|
|
60
81
|
events,
|
|
@@ -68,15 +89,19 @@ declare function Agenda<T = unknown>({
|
|
|
68
89
|
onPressDay,
|
|
69
90
|
className,
|
|
70
91
|
style
|
|
71
|
-
}: AgendaProps<T>):
|
|
92
|
+
}: AgendaProps<T>): ReactElement;
|
|
72
93
|
//#endregion
|
|
73
94
|
//#region src/MonthView.d.ts
|
|
74
95
|
/** Props passed to a custom month event chip renderer. */
|
|
75
96
|
interface DomMonthEventArgs<T = unknown> {
|
|
97
|
+
/** The event to render. */
|
|
76
98
|
event: CalendarEvent$1<T>;
|
|
99
|
+
/** Call to fire the view's `onPressEvent` for this chip. */
|
|
77
100
|
onPress: () => void;
|
|
78
101
|
}
|
|
102
|
+
/** A component that renders a single month-grid event chip. */
|
|
79
103
|
type DomMonthEvent<T = unknown> = ComponentType<DomMonthEventArgs<T>>;
|
|
104
|
+
/** Props for {@link MonthView}. */
|
|
80
105
|
interface MonthViewProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
81
106
|
/** Any day within the month to render. */
|
|
82
107
|
date: Date;
|
|
@@ -126,13 +151,22 @@ interface MonthViewProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
126
151
|
* (rendered without `events`) is always navigable regardless of this flag.
|
|
127
152
|
*/
|
|
128
153
|
keyboardDayNavigation?: boolean;
|
|
154
|
+
/** Class applied to the root element. */
|
|
129
155
|
className?: string;
|
|
156
|
+
/** Inline styles applied to the root element. */
|
|
130
157
|
style?: CSSProperties;
|
|
131
158
|
}
|
|
132
159
|
interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
133
160
|
eventsByDay?: ReadonlyMap<string, CalendarEvent$1<T>[]>;
|
|
134
161
|
}
|
|
135
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* A single static month grid, rendered with plain DOM elements.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```tsx
|
|
167
|
+
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
136
170
|
declare function MonthView<T = unknown>({
|
|
137
171
|
date,
|
|
138
172
|
weekStartsOn,
|
|
@@ -158,28 +192,41 @@ declare function MonthView<T = unknown>({
|
|
|
158
192
|
keyboardDayNavigation,
|
|
159
193
|
className,
|
|
160
194
|
style
|
|
161
|
-
}: MonthViewInternalProps<T>):
|
|
195
|
+
}: MonthViewInternalProps<T>): ReactElement;
|
|
162
196
|
//#endregion
|
|
163
197
|
//#region src/TimeGrid.d.ts
|
|
164
198
|
/** Props passed to a custom time-grid event renderer. */
|
|
165
199
|
interface DomRenderEventArgs<T = unknown> {
|
|
200
|
+
/** The event to render. */
|
|
166
201
|
event: CalendarEvent$1<T>;
|
|
202
|
+
/** The current view mode. */
|
|
167
203
|
mode: CalendarMode$1;
|
|
204
|
+
/** Whether the event is all-day. */
|
|
168
205
|
isAllDay: boolean;
|
|
206
|
+
/** Pixel height of the event box (timed events only). */
|
|
169
207
|
boxHeight?: number;
|
|
208
|
+
/** The event started before the visible day and continues into it. */
|
|
170
209
|
continuesBefore?: boolean;
|
|
210
|
+
/** The event continues past the visible day. */
|
|
171
211
|
continuesAfter?: boolean;
|
|
172
212
|
/** Show the time range in 12-hour AM/PM. */
|
|
173
213
|
ampm?: boolean;
|
|
214
|
+
/** Call to fire the view's `onPressEvent` for this event. */
|
|
174
215
|
onPress: () => void;
|
|
175
216
|
}
|
|
217
|
+
/** A component that renders a single time-grid event box. */
|
|
176
218
|
type DomRenderEvent<T = unknown> = ComponentType<DomRenderEventArgs<T>>;
|
|
219
|
+
/** Props for {@link TimeGrid}. */
|
|
177
220
|
interface TimeGridProps<T = unknown> {
|
|
221
|
+
/** Anchor date; the visible columns are derived from it and `mode`. */
|
|
178
222
|
date: Date;
|
|
223
|
+
/** Events to lay out on the grid. */
|
|
179
224
|
events?: CalendarEvent$1<T>[];
|
|
180
225
|
/** "day" (default), "3days", "week", or "custom" (with `numberOfDays`). */
|
|
181
226
|
mode?: TimeGridMode$1;
|
|
227
|
+
/** Column count for `mode="custom"`. */
|
|
182
228
|
numberOfDays?: number;
|
|
229
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
183
230
|
weekStartsOn?: WeekStartsOn$1;
|
|
184
231
|
/** Initial pixels per hour (default 48). */
|
|
185
232
|
hourHeight?: number;
|
|
@@ -187,7 +234,9 @@ interface TimeGridProps<T = unknown> {
|
|
|
187
234
|
scrollOffsetMinutes?: number;
|
|
188
235
|
/** Pinch / Ctrl-⌘-scroll to zoom the grid (default true). */
|
|
189
236
|
zoomable?: boolean;
|
|
237
|
+
/** Lower bound for pixels per hour when zooming. */
|
|
190
238
|
minHourHeight?: number;
|
|
239
|
+
/** Upper bound for pixels per hour when zooming. */
|
|
191
240
|
maxHourHeight?: number;
|
|
192
241
|
/** Snap dragged events to this many minutes (default 15). */
|
|
193
242
|
dragStepMinutes?: number;
|
|
@@ -201,13 +250,19 @@ interface TimeGridProps<T = unknown> {
|
|
|
201
250
|
showNowIndicator?: boolean;
|
|
202
251
|
/** Show the all-day lane above the grid (default true). */
|
|
203
252
|
showAllDayEventCell?: boolean;
|
|
253
|
+
/** date-fns locale for the column headers and time labels. */
|
|
204
254
|
locale?: Locale;
|
|
255
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
205
256
|
theme?: Partial<DomCalendarTheme>;
|
|
257
|
+
/** Height of the scroll viewport, in px. */
|
|
206
258
|
height?: number | string;
|
|
259
|
+
/** Custom event renderer; falls back to the built-in event box. */
|
|
207
260
|
renderEvent?: DomRenderEvent<T>;
|
|
208
|
-
/** Replace the hour-axis label. Receives the hour (0
|
|
261
|
+
/** Replace the hour-axis label. Receives the hour (0-23) and the `ampm` flag. */
|
|
209
262
|
hourComponent?: (hour: number, ampm: boolean) => ReactNode;
|
|
263
|
+
/** Tap an event. */
|
|
210
264
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
265
|
+
/** Tap a day's column header. */
|
|
211
266
|
onPressDateHeader?: (day: Date) => void;
|
|
212
267
|
/** Tap empty grid space; called with the date and time at the press. */
|
|
213
268
|
onPressCell?: (date: Date) => void;
|
|
@@ -220,7 +275,9 @@ interface TimeGridProps<T = unknown> {
|
|
|
220
275
|
* Return `false` to reject the drop (the event snaps back).
|
|
221
276
|
*/
|
|
222
277
|
onDragEvent?: (event: CalendarEvent$1<T>, start: Date, end: Date) => void | boolean;
|
|
278
|
+
/** Class applied to the root element. */
|
|
223
279
|
className?: string;
|
|
280
|
+
/** Inline styles applied to the root element. */
|
|
224
281
|
style?: CSSProperties;
|
|
225
282
|
}
|
|
226
283
|
/**
|
|
@@ -228,6 +285,11 @@ interface TimeGridProps<T = unknown> {
|
|
|
228
285
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
229
286
|
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
230
287
|
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
292
|
+
* ```
|
|
231
293
|
*/
|
|
232
294
|
declare function TimeGrid<T = unknown>({
|
|
233
295
|
date,
|
|
@@ -259,9 +321,10 @@ declare function TimeGrid<T = unknown>({
|
|
|
259
321
|
onDragEvent,
|
|
260
322
|
className,
|
|
261
323
|
style
|
|
262
|
-
}: TimeGridProps<T>):
|
|
324
|
+
}: TimeGridProps<T>): ReactElement;
|
|
263
325
|
//#endregion
|
|
264
326
|
//#region src/Calendar.d.ts
|
|
327
|
+
/** Props for {@link Calendar}. */
|
|
265
328
|
interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
266
329
|
/**
|
|
267
330
|
* The view to render (default "week"). `month` renders a month grid, `schedule`
|
|
@@ -276,11 +339,15 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
276
339
|
weekStartsOn?: WeekStartsOn$1;
|
|
277
340
|
/** Column count for `mode="custom"`. */
|
|
278
341
|
numberOfDays?: number;
|
|
342
|
+
/** date-fns locale for titles, headers, and time labels. */
|
|
279
343
|
locale?: Locale;
|
|
344
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
280
345
|
theme?: Partial<DomCalendarTheme>;
|
|
281
346
|
/** Height of the scroll viewport, in px. */
|
|
282
347
|
height?: number | string;
|
|
348
|
+
/** Class applied to the root element. */
|
|
283
349
|
className?: string;
|
|
350
|
+
/** Inline styles applied to the root element. */
|
|
284
351
|
style?: CSSProperties;
|
|
285
352
|
/** Tap an event (both layouts). */
|
|
286
353
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
@@ -346,6 +413,11 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
346
413
|
* view for `mode`. `month` renders a single {@link MonthView}; `schedule` renders
|
|
347
414
|
* an {@link Agenda}; the time-grid modes render a {@link TimeGrid}. For a
|
|
348
415
|
* scrolling month picker, use {@link MonthList} directly.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```tsx
|
|
419
|
+
* <Calendar mode="week" date={new Date()} events={events} />
|
|
420
|
+
* ```
|
|
349
421
|
*/
|
|
350
422
|
declare function Calendar<T = unknown>({
|
|
351
423
|
mode,
|
|
@@ -388,9 +460,10 @@ declare function Calendar<T = unknown>({
|
|
|
388
460
|
onPressMore,
|
|
389
461
|
renderMonthEvent,
|
|
390
462
|
renderScheduleEvent
|
|
391
|
-
}: CalendarProps<T>):
|
|
463
|
+
}: CalendarProps<T>): ReactElement;
|
|
392
464
|
//#endregion
|
|
393
465
|
//#region src/MonthList.d.ts
|
|
466
|
+
/** Props for {@link MonthList}. */
|
|
394
467
|
interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
395
468
|
/** Anchor month; the list spans `pastMonths` before to `futureMonths` after. */
|
|
396
469
|
date: Date;
|
|
@@ -398,6 +471,7 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
398
471
|
pastMonths?: number;
|
|
399
472
|
/** Months to render after the anchor (default 12). */
|
|
400
473
|
futureMonths?: number;
|
|
474
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
401
475
|
weekStartsOn?: WeekStartsOn$1;
|
|
402
476
|
/** Events to render as chips in each day cell (calendar layout when provided). */
|
|
403
477
|
events?: CalendarEvent$1<T>[];
|
|
@@ -411,11 +485,15 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
411
485
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
412
486
|
/** Tap the "+N more" overflow row. */
|
|
413
487
|
onPressMore?: (events: CalendarEvent$1<T>[], date: Date) => void;
|
|
488
|
+
/** Selected span; days between the endpoints get the range band. */
|
|
414
489
|
selectedRange?: DateRange$1;
|
|
490
|
+
/** Discrete selected days (single / multiple). */
|
|
415
491
|
selectedDates?: Date[];
|
|
416
492
|
/** Fill the whole cell on selection instead of the default rounded pill band. */
|
|
417
493
|
fillCellOnSelection?: boolean;
|
|
494
|
+
/** date-fns locale for the month titles and weekday labels. */
|
|
418
495
|
locale?: Locale;
|
|
496
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
419
497
|
theme?: Partial<DomCalendarTheme>;
|
|
420
498
|
/** Height of the scroll viewport, in px (default 480). */
|
|
421
499
|
height?: number | string;
|
|
@@ -425,8 +503,11 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
425
503
|
* layout (no `events`) is always navigable regardless.
|
|
426
504
|
*/
|
|
427
505
|
keyboardDayNavigation?: boolean;
|
|
506
|
+
/** Fired when a selectable day is clicked. */
|
|
428
507
|
onPressDay?: (date: Date) => void;
|
|
508
|
+
/** Class applied to the root element. */
|
|
429
509
|
className?: string;
|
|
510
|
+
/** Inline styles applied to the root element. */
|
|
430
511
|
style?: CSSProperties;
|
|
431
512
|
}
|
|
432
513
|
/**
|
|
@@ -458,6 +539,6 @@ declare function MonthList<T = unknown>({
|
|
|
458
539
|
onPressDay,
|
|
459
540
|
className,
|
|
460
541
|
style
|
|
461
|
-
}: MonthListProps<T>):
|
|
542
|
+
}: MonthListProps<T>): ReactElement;
|
|
462
543
|
//#endregion
|
|
463
544
|
export { Agenda, type AgendaProps, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type DateRange, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthView, type MonthViewProps, type PositionedEvent, TimeGrid, type TimeGridMode, type TimeGridProps, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, useDateRange, useMonthGrid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Locale } from "date-fns";
|
|
2
|
-
import { CSSProperties, ComponentType, ReactNode } from "react";
|
|
2
|
+
import { CSSProperties, ComponentType, ReactElement, ReactNode } from "react";
|
|
3
3
|
import { BusinessHours, BusinessHours as BusinessHours$1, CalendarColors, CalendarEvent, CalendarEvent as CalendarEvent$1, CalendarMode, CalendarMode as CalendarMode$1, DateRange, DateRange as DateRange$1, DateSelectionConstraints, DateSelectionConstraints as DateSelectionConstraints$1, DaySelectionState, ICalendarEvent, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, TimeGridMode, TimeGridMode as TimeGridMode$1, UseDateRangeOptions, UseMonthGridOptions, WeekStartsOn, WeekStartsOn as WeekStartsOn$1, buildMonthGrid, daySelectionState, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, nextDateRange, useDateRange, useMonthGrid } from "@super-calendar/core";
|
|
4
4
|
|
|
5
5
|
//#region src/theme.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Theme for the react-dom renderer. Combines the shared color palette from
|
|
8
|
+
* `@super-calendar/core` with the DOM-specific pixel metrics and font stack.
|
|
9
|
+
*/
|
|
6
10
|
type DomCalendarTheme = CalendarColors & {
|
|
7
11
|
/** Row height of a day cell, in px. */cellHeight: number; /** Diameter of the day badge, in px. */
|
|
8
12
|
dayBadgeSize: number;
|
|
@@ -14,7 +18,9 @@ type DomCalendarTheme = CalendarColors & {
|
|
|
14
18
|
rangeBandHeight: number; /** Font stack for the calendar. */
|
|
15
19
|
fontFamily: string;
|
|
16
20
|
};
|
|
21
|
+
/** The default light theme: the core light palette plus the DOM metrics. */
|
|
17
22
|
declare const defaultDomTheme: DomCalendarTheme;
|
|
23
|
+
/** The dark theme: the core dark palette plus the DOM metrics. */
|
|
18
24
|
declare const darkDomTheme: DomCalendarTheme;
|
|
19
25
|
/** Merge a partial override onto a base theme (defaults to {@link defaultDomTheme}). */
|
|
20
26
|
declare function mergeDomTheme(overrides?: Partial<DomCalendarTheme>, base?: DomCalendarTheme): DomCalendarTheme;
|
|
@@ -22,32 +28,42 @@ declare function mergeDomTheme(overrides?: Partial<DomCalendarTheme>, base?: Dom
|
|
|
22
28
|
//#region src/Agenda.d.ts
|
|
23
29
|
/** Props passed to a custom agenda (schedule) event renderer. */
|
|
24
30
|
interface DomAgendaEventArgs<T = unknown> {
|
|
31
|
+
/** The event to render. */
|
|
25
32
|
event: CalendarEvent$1<T>;
|
|
26
33
|
/** Always "schedule"; lets a renderer shared with other views branch on it. */
|
|
27
34
|
mode: "schedule";
|
|
35
|
+
/** Whether the event is all-day. */
|
|
28
36
|
isAllDay: boolean;
|
|
29
37
|
/** Render the time range in 12-hour AM/PM. */
|
|
30
38
|
ampm?: boolean;
|
|
39
|
+
/** Call to fire the view's `onPressEvent` for this row. */
|
|
31
40
|
onPress: () => void;
|
|
32
41
|
}
|
|
42
|
+
/** A component that renders a single agenda (schedule) event row. */
|
|
33
43
|
type DomAgendaEvent<T = unknown> = ComponentType<DomAgendaEventArgs<T>>;
|
|
44
|
+
/** Props for {@link Agenda}. */
|
|
34
45
|
interface AgendaProps<T = unknown> {
|
|
35
46
|
/** Events to list. The consumer controls which (and therefore the date range). */
|
|
36
47
|
events: CalendarEvent$1<T>[];
|
|
48
|
+
/** date-fns locale for the day headers and time labels. */
|
|
37
49
|
locale?: Locale;
|
|
38
50
|
/** Render times in 12-hour AM/PM (default false, 24h). */
|
|
39
51
|
ampm?: boolean;
|
|
40
52
|
/** Highlight this date's header instead of the real "today". */
|
|
41
53
|
activeDate?: Date;
|
|
54
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
42
55
|
theme?: Partial<DomCalendarTheme>;
|
|
43
56
|
/** Height of the scroll viewport, in px (default 480). */
|
|
44
57
|
height?: number | string;
|
|
45
58
|
/** Replace the built-in event row. */
|
|
46
59
|
renderEvent?: DomAgendaEvent<T>;
|
|
60
|
+
/** Tap an event row. */
|
|
47
61
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
48
62
|
/** Tap a day's header. */
|
|
49
63
|
onPressDay?: (date: Date) => void;
|
|
64
|
+
/** Class applied to the root element. */
|
|
50
65
|
className?: string;
|
|
66
|
+
/** Inline styles applied to the root element. */
|
|
51
67
|
style?: CSSProperties;
|
|
52
68
|
}
|
|
53
69
|
/**
|
|
@@ -55,6 +71,11 @@ interface AgendaProps<T = unknown> {
|
|
|
55
71
|
* elements. Events are sorted by start and grouped under a date header per day;
|
|
56
72
|
* the consumer controls which events (and therefore which dates) are shown. The
|
|
57
73
|
* react-dom counterpart of the React Native `Agenda`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
78
|
+
* ```
|
|
58
79
|
*/
|
|
59
80
|
declare function Agenda<T = unknown>({
|
|
60
81
|
events,
|
|
@@ -68,15 +89,19 @@ declare function Agenda<T = unknown>({
|
|
|
68
89
|
onPressDay,
|
|
69
90
|
className,
|
|
70
91
|
style
|
|
71
|
-
}: AgendaProps<T>):
|
|
92
|
+
}: AgendaProps<T>): ReactElement;
|
|
72
93
|
//#endregion
|
|
73
94
|
//#region src/MonthView.d.ts
|
|
74
95
|
/** Props passed to a custom month event chip renderer. */
|
|
75
96
|
interface DomMonthEventArgs<T = unknown> {
|
|
97
|
+
/** The event to render. */
|
|
76
98
|
event: CalendarEvent$1<T>;
|
|
99
|
+
/** Call to fire the view's `onPressEvent` for this chip. */
|
|
77
100
|
onPress: () => void;
|
|
78
101
|
}
|
|
102
|
+
/** A component that renders a single month-grid event chip. */
|
|
79
103
|
type DomMonthEvent<T = unknown> = ComponentType<DomMonthEventArgs<T>>;
|
|
104
|
+
/** Props for {@link MonthView}. */
|
|
80
105
|
interface MonthViewProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
81
106
|
/** Any day within the month to render. */
|
|
82
107
|
date: Date;
|
|
@@ -126,13 +151,22 @@ interface MonthViewProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
126
151
|
* (rendered without `events`) is always navigable regardless of this flag.
|
|
127
152
|
*/
|
|
128
153
|
keyboardDayNavigation?: boolean;
|
|
154
|
+
/** Class applied to the root element. */
|
|
129
155
|
className?: string;
|
|
156
|
+
/** Inline styles applied to the root element. */
|
|
130
157
|
style?: CSSProperties;
|
|
131
158
|
}
|
|
132
159
|
interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
133
160
|
eventsByDay?: ReadonlyMap<string, CalendarEvent$1<T>[]>;
|
|
134
161
|
}
|
|
135
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* A single static month grid, rendered with plain DOM elements.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```tsx
|
|
167
|
+
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
136
170
|
declare function MonthView<T = unknown>({
|
|
137
171
|
date,
|
|
138
172
|
weekStartsOn,
|
|
@@ -158,28 +192,41 @@ declare function MonthView<T = unknown>({
|
|
|
158
192
|
keyboardDayNavigation,
|
|
159
193
|
className,
|
|
160
194
|
style
|
|
161
|
-
}: MonthViewInternalProps<T>):
|
|
195
|
+
}: MonthViewInternalProps<T>): ReactElement;
|
|
162
196
|
//#endregion
|
|
163
197
|
//#region src/TimeGrid.d.ts
|
|
164
198
|
/** Props passed to a custom time-grid event renderer. */
|
|
165
199
|
interface DomRenderEventArgs<T = unknown> {
|
|
200
|
+
/** The event to render. */
|
|
166
201
|
event: CalendarEvent$1<T>;
|
|
202
|
+
/** The current view mode. */
|
|
167
203
|
mode: CalendarMode$1;
|
|
204
|
+
/** Whether the event is all-day. */
|
|
168
205
|
isAllDay: boolean;
|
|
206
|
+
/** Pixel height of the event box (timed events only). */
|
|
169
207
|
boxHeight?: number;
|
|
208
|
+
/** The event started before the visible day and continues into it. */
|
|
170
209
|
continuesBefore?: boolean;
|
|
210
|
+
/** The event continues past the visible day. */
|
|
171
211
|
continuesAfter?: boolean;
|
|
172
212
|
/** Show the time range in 12-hour AM/PM. */
|
|
173
213
|
ampm?: boolean;
|
|
214
|
+
/** Call to fire the view's `onPressEvent` for this event. */
|
|
174
215
|
onPress: () => void;
|
|
175
216
|
}
|
|
217
|
+
/** A component that renders a single time-grid event box. */
|
|
176
218
|
type DomRenderEvent<T = unknown> = ComponentType<DomRenderEventArgs<T>>;
|
|
219
|
+
/** Props for {@link TimeGrid}. */
|
|
177
220
|
interface TimeGridProps<T = unknown> {
|
|
221
|
+
/** Anchor date; the visible columns are derived from it and `mode`. */
|
|
178
222
|
date: Date;
|
|
223
|
+
/** Events to lay out on the grid. */
|
|
179
224
|
events?: CalendarEvent$1<T>[];
|
|
180
225
|
/** "day" (default), "3days", "week", or "custom" (with `numberOfDays`). */
|
|
181
226
|
mode?: TimeGridMode$1;
|
|
227
|
+
/** Column count for `mode="custom"`. */
|
|
182
228
|
numberOfDays?: number;
|
|
229
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
183
230
|
weekStartsOn?: WeekStartsOn$1;
|
|
184
231
|
/** Initial pixels per hour (default 48). */
|
|
185
232
|
hourHeight?: number;
|
|
@@ -187,7 +234,9 @@ interface TimeGridProps<T = unknown> {
|
|
|
187
234
|
scrollOffsetMinutes?: number;
|
|
188
235
|
/** Pinch / Ctrl-⌘-scroll to zoom the grid (default true). */
|
|
189
236
|
zoomable?: boolean;
|
|
237
|
+
/** Lower bound for pixels per hour when zooming. */
|
|
190
238
|
minHourHeight?: number;
|
|
239
|
+
/** Upper bound for pixels per hour when zooming. */
|
|
191
240
|
maxHourHeight?: number;
|
|
192
241
|
/** Snap dragged events to this many minutes (default 15). */
|
|
193
242
|
dragStepMinutes?: number;
|
|
@@ -201,13 +250,19 @@ interface TimeGridProps<T = unknown> {
|
|
|
201
250
|
showNowIndicator?: boolean;
|
|
202
251
|
/** Show the all-day lane above the grid (default true). */
|
|
203
252
|
showAllDayEventCell?: boolean;
|
|
253
|
+
/** date-fns locale for the column headers and time labels. */
|
|
204
254
|
locale?: Locale;
|
|
255
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
205
256
|
theme?: Partial<DomCalendarTheme>;
|
|
257
|
+
/** Height of the scroll viewport, in px. */
|
|
206
258
|
height?: number | string;
|
|
259
|
+
/** Custom event renderer; falls back to the built-in event box. */
|
|
207
260
|
renderEvent?: DomRenderEvent<T>;
|
|
208
|
-
/** Replace the hour-axis label. Receives the hour (0
|
|
261
|
+
/** Replace the hour-axis label. Receives the hour (0-23) and the `ampm` flag. */
|
|
209
262
|
hourComponent?: (hour: number, ampm: boolean) => ReactNode;
|
|
263
|
+
/** Tap an event. */
|
|
210
264
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
265
|
+
/** Tap a day's column header. */
|
|
211
266
|
onPressDateHeader?: (day: Date) => void;
|
|
212
267
|
/** Tap empty grid space; called with the date and time at the press. */
|
|
213
268
|
onPressCell?: (date: Date) => void;
|
|
@@ -220,7 +275,9 @@ interface TimeGridProps<T = unknown> {
|
|
|
220
275
|
* Return `false` to reject the drop (the event snaps back).
|
|
221
276
|
*/
|
|
222
277
|
onDragEvent?: (event: CalendarEvent$1<T>, start: Date, end: Date) => void | boolean;
|
|
278
|
+
/** Class applied to the root element. */
|
|
223
279
|
className?: string;
|
|
280
|
+
/** Inline styles applied to the root element. */
|
|
224
281
|
style?: CSSProperties;
|
|
225
282
|
}
|
|
226
283
|
/**
|
|
@@ -228,6 +285,11 @@ interface TimeGridProps<T = unknown> {
|
|
|
228
285
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
229
286
|
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
230
287
|
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
292
|
+
* ```
|
|
231
293
|
*/
|
|
232
294
|
declare function TimeGrid<T = unknown>({
|
|
233
295
|
date,
|
|
@@ -259,9 +321,10 @@ declare function TimeGrid<T = unknown>({
|
|
|
259
321
|
onDragEvent,
|
|
260
322
|
className,
|
|
261
323
|
style
|
|
262
|
-
}: TimeGridProps<T>):
|
|
324
|
+
}: TimeGridProps<T>): ReactElement;
|
|
263
325
|
//#endregion
|
|
264
326
|
//#region src/Calendar.d.ts
|
|
327
|
+
/** Props for {@link Calendar}. */
|
|
265
328
|
interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
266
329
|
/**
|
|
267
330
|
* The view to render (default "week"). `month` renders a month grid, `schedule`
|
|
@@ -276,11 +339,15 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
276
339
|
weekStartsOn?: WeekStartsOn$1;
|
|
277
340
|
/** Column count for `mode="custom"`. */
|
|
278
341
|
numberOfDays?: number;
|
|
342
|
+
/** date-fns locale for titles, headers, and time labels. */
|
|
279
343
|
locale?: Locale;
|
|
344
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
280
345
|
theme?: Partial<DomCalendarTheme>;
|
|
281
346
|
/** Height of the scroll viewport, in px. */
|
|
282
347
|
height?: number | string;
|
|
348
|
+
/** Class applied to the root element. */
|
|
283
349
|
className?: string;
|
|
350
|
+
/** Inline styles applied to the root element. */
|
|
284
351
|
style?: CSSProperties;
|
|
285
352
|
/** Tap an event (both layouts). */
|
|
286
353
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
@@ -346,6 +413,11 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
346
413
|
* view for `mode`. `month` renders a single {@link MonthView}; `schedule` renders
|
|
347
414
|
* an {@link Agenda}; the time-grid modes render a {@link TimeGrid}. For a
|
|
348
415
|
* scrolling month picker, use {@link MonthList} directly.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```tsx
|
|
419
|
+
* <Calendar mode="week" date={new Date()} events={events} />
|
|
420
|
+
* ```
|
|
349
421
|
*/
|
|
350
422
|
declare function Calendar<T = unknown>({
|
|
351
423
|
mode,
|
|
@@ -388,9 +460,10 @@ declare function Calendar<T = unknown>({
|
|
|
388
460
|
onPressMore,
|
|
389
461
|
renderMonthEvent,
|
|
390
462
|
renderScheduleEvent
|
|
391
|
-
}: CalendarProps<T>):
|
|
463
|
+
}: CalendarProps<T>): ReactElement;
|
|
392
464
|
//#endregion
|
|
393
465
|
//#region src/MonthList.d.ts
|
|
466
|
+
/** Props for {@link MonthList}. */
|
|
394
467
|
interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
395
468
|
/** Anchor month; the list spans `pastMonths` before to `futureMonths` after. */
|
|
396
469
|
date: Date;
|
|
@@ -398,6 +471,7 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
398
471
|
pastMonths?: number;
|
|
399
472
|
/** Months to render after the anchor (default 12). */
|
|
400
473
|
futureMonths?: number;
|
|
474
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
401
475
|
weekStartsOn?: WeekStartsOn$1;
|
|
402
476
|
/** Events to render as chips in each day cell (calendar layout when provided). */
|
|
403
477
|
events?: CalendarEvent$1<T>[];
|
|
@@ -411,11 +485,15 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
411
485
|
onPressEvent?: (event: CalendarEvent$1<T>) => void;
|
|
412
486
|
/** Tap the "+N more" overflow row. */
|
|
413
487
|
onPressMore?: (events: CalendarEvent$1<T>[], date: Date) => void;
|
|
488
|
+
/** Selected span; days between the endpoints get the range band. */
|
|
414
489
|
selectedRange?: DateRange$1;
|
|
490
|
+
/** Discrete selected days (single / multiple). */
|
|
415
491
|
selectedDates?: Date[];
|
|
416
492
|
/** Fill the whole cell on selection instead of the default rounded pill band. */
|
|
417
493
|
fillCellOnSelection?: boolean;
|
|
494
|
+
/** date-fns locale for the month titles and weekday labels. */
|
|
418
495
|
locale?: Locale;
|
|
496
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
419
497
|
theme?: Partial<DomCalendarTheme>;
|
|
420
498
|
/** Height of the scroll viewport, in px (default 480). */
|
|
421
499
|
height?: number | string;
|
|
@@ -425,8 +503,11 @@ interface MonthListProps<T = unknown> extends DateSelectionConstraints$1 {
|
|
|
425
503
|
* layout (no `events`) is always navigable regardless.
|
|
426
504
|
*/
|
|
427
505
|
keyboardDayNavigation?: boolean;
|
|
506
|
+
/** Fired when a selectable day is clicked. */
|
|
428
507
|
onPressDay?: (date: Date) => void;
|
|
508
|
+
/** Class applied to the root element. */
|
|
429
509
|
className?: string;
|
|
510
|
+
/** Inline styles applied to the root element. */
|
|
430
511
|
style?: CSSProperties;
|
|
431
512
|
}
|
|
432
513
|
/**
|
|
@@ -458,6 +539,6 @@ declare function MonthList<T = unknown>({
|
|
|
458
539
|
onPressDay,
|
|
459
540
|
className,
|
|
460
541
|
style
|
|
461
|
-
}: MonthListProps<T>):
|
|
542
|
+
}: MonthListProps<T>): ReactElement;
|
|
462
543
|
//#endregion
|
|
463
544
|
export { Agenda, type AgendaProps, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type DateRange, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, MonthView, type MonthViewProps, type PositionedEvent, TimeGrid, type TimeGridMode, type TimeGridProps, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, useDateRange, useMonthGrid };
|
package/dist/index.js
CHANGED
|
@@ -11,10 +11,12 @@ const METRICS = {
|
|
|
11
11
|
rangeBandHeight: 32,
|
|
12
12
|
fontFamily: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif"
|
|
13
13
|
};
|
|
14
|
+
/** The default light theme: the core light palette plus the DOM metrics. */
|
|
14
15
|
const defaultDomTheme = {
|
|
15
16
|
..._super_calendar_core.lightColors,
|
|
16
17
|
...METRICS
|
|
17
18
|
};
|
|
19
|
+
/** The dark theme: the core dark palette plus the DOM metrics. */
|
|
18
20
|
const darkDomTheme = {
|
|
19
21
|
..._super_calendar_core.darkColors,
|
|
20
22
|
...METRICS
|
|
@@ -64,6 +66,11 @@ function DefaultAgendaRow({ event, isAllDay, ampm = false, theme }) {
|
|
|
64
66
|
* elements. Events are sorted by start and grouped under a date header per day;
|
|
65
67
|
* the consumer controls which events (and therefore which dates) are shown. The
|
|
66
68
|
* react-dom counterpart of the React Native `Agenda`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
73
|
+
* ```
|
|
67
74
|
*/
|
|
68
75
|
function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, onPressEvent, onPressDay, className, style }) {
|
|
69
76
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
@@ -330,7 +337,14 @@ function moreButtonStyle(theme) {
|
|
|
330
337
|
color: theme.textMuted
|
|
331
338
|
};
|
|
332
339
|
}
|
|
333
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* A single static month grid, rendered with plain DOM elements.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```tsx
|
|
345
|
+
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
334
348
|
function MonthView({ date, weekStartsOn = 0, events, eventsByDay: eventsByDayProp, renderEvent, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, keyboardDayNavigation = false, className, style }) {
|
|
335
349
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
336
350
|
const eventsMode = events !== void 0;
|
|
@@ -613,6 +627,11 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
|
|
|
613
627
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
614
628
|
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
615
629
|
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```tsx
|
|
633
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
634
|
+
* ```
|
|
616
635
|
*/
|
|
617
636
|
function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, dragStepMinutes = 15, ampm = false, timeslots = 1, businessHours, showNowIndicator = true, showAllDayEventCell = true, locale, theme: themeOverrides, height = 600, renderEvent, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, className, style }) {
|
|
618
637
|
const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
@@ -1148,6 +1167,11 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1148
1167
|
* view for `mode`. `month` renders a single {@link MonthView}; `schedule` renders
|
|
1149
1168
|
* an {@link Agenda}; the time-grid modes render a {@link TimeGrid}. For a
|
|
1150
1169
|
* scrolling month picker, use {@link MonthList} directly.
|
|
1170
|
+
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```tsx
|
|
1173
|
+
* <Calendar mode="week" date={new Date()} events={events} />
|
|
1174
|
+
* ```
|
|
1151
1175
|
*/
|
|
1152
1176
|
function Calendar({ mode = "week", date, events, weekStartsOn = 0, numberOfDays, locale, theme, height, className, style, onPressEvent, ampm, hourHeight, scrollOffsetMinutes, timeslots, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, maxVisibleEventCount, moreLabel, showAdjacentMonths, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent }) {
|
|
1153
1177
|
if (mode === "schedule") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
|
package/dist/index.mjs
CHANGED
|
@@ -10,10 +10,12 @@ const METRICS = {
|
|
|
10
10
|
rangeBandHeight: 32,
|
|
11
11
|
fontFamily: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif"
|
|
12
12
|
};
|
|
13
|
+
/** The default light theme: the core light palette plus the DOM metrics. */
|
|
13
14
|
const defaultDomTheme = {
|
|
14
15
|
...lightColors,
|
|
15
16
|
...METRICS
|
|
16
17
|
};
|
|
18
|
+
/** The dark theme: the core dark palette plus the DOM metrics. */
|
|
17
19
|
const darkDomTheme = {
|
|
18
20
|
...darkColors,
|
|
19
21
|
...METRICS
|
|
@@ -63,6 +65,11 @@ function DefaultAgendaRow({ event, isAllDay, ampm = false, theme }) {
|
|
|
63
65
|
* elements. Events are sorted by start and grouped under a date header per day;
|
|
64
66
|
* the consumer controls which events (and therefore which dates) are shown. The
|
|
65
67
|
* react-dom counterpart of the React Native `Agenda`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
72
|
+
* ```
|
|
66
73
|
*/
|
|
67
74
|
function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverrides, height = 480, renderEvent, onPressEvent, onPressDay, className, style }) {
|
|
68
75
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
@@ -329,7 +336,14 @@ function moreButtonStyle(theme) {
|
|
|
329
336
|
color: theme.textMuted
|
|
330
337
|
};
|
|
331
338
|
}
|
|
332
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* A single static month grid, rendered with plain DOM elements.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```tsx
|
|
344
|
+
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
333
347
|
function MonthView({ date, weekStartsOn = 0, events, eventsByDay: eventsByDayProp, renderEvent, maxVisibleEventCount = 3, moreLabel = "{moreCount} More", onPressEvent, onPressMore, selectedRange, selectedDates, showAdjacentMonths = true, fillCellOnSelection = false, showTitle = true, showWeekdays = true, locale, theme: themeOverrides, minDate, maxDate, isDateDisabled, onPressDay, keyboardDayNavigation = false, className, style }) {
|
|
334
348
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
335
349
|
const eventsMode = events !== void 0;
|
|
@@ -612,6 +626,11 @@ function DefaultDomEvent({ event, mode, isAllDay, boxHeight, ampm = false, theme
|
|
|
612
626
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
613
627
|
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
614
628
|
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```tsx
|
|
632
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
633
|
+
* ```
|
|
615
634
|
*/
|
|
616
635
|
function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStartsOn = 0, hourHeight: initialHourHeight = 48, scrollOffsetMinutes = 480, zoomable = true, minHourHeight = 24, maxHourHeight = 160, dragStepMinutes = 15, ampm = false, timeslots = 1, businessHours, showNowIndicator = true, showAllDayEventCell = true, locale, theme: themeOverrides, height = 600, renderEvent, hourComponent, onPressEvent, onPressDateHeader, onPressCell, onCreateEvent, onDragStart, onDragEvent, className, style }) {
|
|
617
636
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
@@ -1147,6 +1166,11 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
|
|
|
1147
1166
|
* view for `mode`. `month` renders a single {@link MonthView}; `schedule` renders
|
|
1148
1167
|
* an {@link Agenda}; the time-grid modes render a {@link TimeGrid}. For a
|
|
1149
1168
|
* scrolling month picker, use {@link MonthList} directly.
|
|
1169
|
+
*
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```tsx
|
|
1172
|
+
* <Calendar mode="week" date={new Date()} events={events} />
|
|
1173
|
+
* ```
|
|
1150
1174
|
*/
|
|
1151
1175
|
function Calendar({ mode = "week", date, events, weekStartsOn = 0, numberOfDays, locale, theme, height, className, style, onPressEvent, ampm, hourHeight, scrollOffsetMinutes, timeslots, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, maxVisibleEventCount, moreLabel, showAdjacentMonths, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent }) {
|
|
1152
1176
|
if (mode === "schedule") return /* @__PURE__ */ jsx(Agenda, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-calendar/dom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Virtualized month / week / day calendar and date picker for react-dom. No React Native, no react-native-web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calendar",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"web",
|
|
12
12
|
"week-view"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://super-calendar.afonsojramos.me",
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/afonsojramos/
|
|
16
|
+
"url": "https://github.com/afonsojramos/super-calendar/issues"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/afonsojramos/
|
|
21
|
+
"url": "git+https://github.com/afonsojramos/super-calendar.git",
|
|
22
22
|
"directory": "packages/dom"
|
|
23
23
|
},
|
|
24
24
|
"source": "./src/index.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@super-calendar/core": "2.
|
|
51
|
+
"@super-calendar/core": "2.1.3"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@legendapp/list": ">=3",
|
package/src/Agenda.tsx
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
1
|
import { LegendList } from "@legendapp/list/react";
|
|
2
2
|
import { format, isSameDay, type Locale, startOfDay } from "date-fns";
|
|
3
|
-
import { type ComponentType, type CSSProperties, useMemo } from "react";
|
|
3
|
+
import { type ComponentType, type CSSProperties, type ReactElement, useMemo } from "react";
|
|
4
4
|
import type { CalendarEvent } from "@super-calendar/core";
|
|
5
5
|
import { eventTimeLabel, getIsToday, isAllDayEvent } from "@super-calendar/core";
|
|
6
6
|
import { type DomCalendarTheme, mergeDomTheme } from "./theme";
|
|
7
7
|
|
|
8
8
|
/** Props passed to a custom agenda (schedule) event renderer. */
|
|
9
9
|
export interface DomAgendaEventArgs<T = unknown> {
|
|
10
|
+
/** The event to render. */
|
|
10
11
|
event: CalendarEvent<T>;
|
|
11
12
|
/** Always "schedule"; lets a renderer shared with other views branch on it. */
|
|
12
13
|
mode: "schedule";
|
|
14
|
+
/** Whether the event is all-day. */
|
|
13
15
|
isAllDay: boolean;
|
|
14
16
|
/** Render the time range in 12-hour AM/PM. */
|
|
15
17
|
ampm?: boolean;
|
|
18
|
+
/** Call to fire the view's `onPressEvent` for this row. */
|
|
16
19
|
onPress: () => void;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
/** A component that renders a single agenda (schedule) event row. */
|
|
19
23
|
export type DomAgendaEvent<T = unknown> = ComponentType<DomAgendaEventArgs<T>>;
|
|
20
24
|
|
|
25
|
+
/** Props for {@link Agenda}. */
|
|
21
26
|
export interface AgendaProps<T = unknown> {
|
|
22
27
|
/** Events to list. The consumer controls which (and therefore the date range). */
|
|
23
28
|
events: CalendarEvent<T>[];
|
|
29
|
+
/** date-fns locale for the day headers and time labels. */
|
|
24
30
|
locale?: Locale;
|
|
25
31
|
/** Render times in 12-hour AM/PM (default false, 24h). */
|
|
26
32
|
ampm?: boolean;
|
|
27
33
|
/** Highlight this date's header instead of the real "today". */
|
|
28
34
|
activeDate?: Date;
|
|
35
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
29
36
|
theme?: Partial<DomCalendarTheme>;
|
|
30
37
|
/** Height of the scroll viewport, in px (default 480). */
|
|
31
38
|
height?: number | string;
|
|
32
39
|
/** Replace the built-in event row. */
|
|
33
40
|
renderEvent?: DomAgendaEvent<T>;
|
|
41
|
+
/** Tap an event row. */
|
|
34
42
|
onPressEvent?: (event: CalendarEvent<T>) => void;
|
|
35
43
|
/** Tap a day's header. */
|
|
36
44
|
onPressDay?: (date: Date) => void;
|
|
45
|
+
/** Class applied to the root element. */
|
|
37
46
|
className?: string;
|
|
47
|
+
/** Inline styles applied to the root element. */
|
|
38
48
|
style?: CSSProperties;
|
|
39
49
|
}
|
|
40
50
|
|
|
@@ -79,6 +89,11 @@ function DefaultAgendaRow<T>({
|
|
|
79
89
|
* elements. Events are sorted by start and grouped under a date header per day;
|
|
80
90
|
* the consumer controls which events (and therefore which dates) are shown. The
|
|
81
91
|
* react-dom counterpart of the React Native `Agenda`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <Agenda events={events} onPressEvent={(e) => console.log(e.title)} />
|
|
96
|
+
* ```
|
|
82
97
|
*/
|
|
83
98
|
export function Agenda<T = unknown>({
|
|
84
99
|
events,
|
|
@@ -92,7 +107,7 @@ export function Agenda<T = unknown>({
|
|
|
92
107
|
onPressDay,
|
|
93
108
|
className,
|
|
94
109
|
style,
|
|
95
|
-
}: AgendaProps<T>) {
|
|
110
|
+
}: AgendaProps<T>): ReactElement {
|
|
96
111
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
97
112
|
const Renderer = renderEvent;
|
|
98
113
|
|
package/src/Calendar.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Locale } from "date-fns";
|
|
2
|
-
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
import type { CSSProperties, ReactElement, ReactNode } from "react";
|
|
3
3
|
import type {
|
|
4
4
|
BusinessHours,
|
|
5
5
|
CalendarEvent,
|
|
@@ -13,6 +13,7 @@ import { type DomMonthEvent, MonthView } from "./MonthView";
|
|
|
13
13
|
import { type DomRenderEvent, TimeGrid } from "./TimeGrid";
|
|
14
14
|
import type { DomCalendarTheme } from "./theme";
|
|
15
15
|
|
|
16
|
+
/** Props for {@link Calendar}. */
|
|
16
17
|
export interface CalendarProps<T = unknown> extends DateSelectionConstraints {
|
|
17
18
|
/**
|
|
18
19
|
* The view to render (default "week"). `month` renders a month grid, `schedule`
|
|
@@ -27,11 +28,15 @@ export interface CalendarProps<T = unknown> extends DateSelectionConstraints {
|
|
|
27
28
|
weekStartsOn?: WeekStartsOn;
|
|
28
29
|
/** Column count for `mode="custom"`. */
|
|
29
30
|
numberOfDays?: number;
|
|
31
|
+
/** date-fns locale for titles, headers, and time labels. */
|
|
30
32
|
locale?: Locale;
|
|
33
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
31
34
|
theme?: Partial<DomCalendarTheme>;
|
|
32
35
|
/** Height of the scroll viewport, in px. */
|
|
33
36
|
height?: number | string;
|
|
37
|
+
/** Class applied to the root element. */
|
|
34
38
|
className?: string;
|
|
39
|
+
/** Inline styles applied to the root element. */
|
|
35
40
|
style?: CSSProperties;
|
|
36
41
|
|
|
37
42
|
/** Tap an event (both layouts). */
|
|
@@ -105,6 +110,11 @@ export interface CalendarProps<T = unknown> extends DateSelectionConstraints {
|
|
|
105
110
|
* view for `mode`. `month` renders a single {@link MonthView}; `schedule` renders
|
|
106
111
|
* an {@link Agenda}; the time-grid modes render a {@link TimeGrid}. For a
|
|
107
112
|
* scrolling month picker, use {@link MonthList} directly.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* <Calendar mode="week" date={new Date()} events={events} />
|
|
117
|
+
* ```
|
|
108
118
|
*/
|
|
109
119
|
export function Calendar<T = unknown>({
|
|
110
120
|
mode = "week",
|
|
@@ -150,7 +160,7 @@ export function Calendar<T = unknown>({
|
|
|
150
160
|
renderMonthEvent,
|
|
151
161
|
// schedule
|
|
152
162
|
renderScheduleEvent,
|
|
153
|
-
}: CalendarProps<T>) {
|
|
163
|
+
}: CalendarProps<T>): ReactElement {
|
|
154
164
|
if (mode === "schedule") {
|
|
155
165
|
return (
|
|
156
166
|
<Agenda<T>
|
package/src/MonthList.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LegendList } from "@legendapp/list/react";
|
|
2
2
|
import { addMonths, type Locale, startOfMonth } from "date-fns";
|
|
3
|
-
import { type CSSProperties, useMemo } from "react";
|
|
3
|
+
import { type CSSProperties, type ReactElement, useMemo } from "react";
|
|
4
4
|
import {
|
|
5
5
|
buildMonthGrid,
|
|
6
6
|
type CalendarEvent,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { type DomMonthEvent, MonthView } from "./MonthView";
|
|
14
14
|
import { type DomCalendarTheme, mergeDomTheme } from "./theme";
|
|
15
15
|
|
|
16
|
+
/** Props for {@link MonthList}. */
|
|
16
17
|
export interface MonthListProps<T = unknown> extends DateSelectionConstraints {
|
|
17
18
|
/** Anchor month; the list spans `pastMonths` before to `futureMonths` after. */
|
|
18
19
|
date: Date;
|
|
@@ -20,6 +21,7 @@ export interface MonthListProps<T = unknown> extends DateSelectionConstraints {
|
|
|
20
21
|
pastMonths?: number;
|
|
21
22
|
/** Months to render after the anchor (default 12). */
|
|
22
23
|
futureMonths?: number;
|
|
24
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
23
25
|
weekStartsOn?: WeekStartsOn;
|
|
24
26
|
/** Events to render as chips in each day cell (calendar layout when provided). */
|
|
25
27
|
events?: CalendarEvent<T>[];
|
|
@@ -33,11 +35,15 @@ export interface MonthListProps<T = unknown> extends DateSelectionConstraints {
|
|
|
33
35
|
onPressEvent?: (event: CalendarEvent<T>) => void;
|
|
34
36
|
/** Tap the "+N more" overflow row. */
|
|
35
37
|
onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
|
|
38
|
+
/** Selected span; days between the endpoints get the range band. */
|
|
36
39
|
selectedRange?: DateRange;
|
|
40
|
+
/** Discrete selected days (single / multiple). */
|
|
37
41
|
selectedDates?: Date[];
|
|
38
42
|
/** Fill the whole cell on selection instead of the default rounded pill band. */
|
|
39
43
|
fillCellOnSelection?: boolean;
|
|
44
|
+
/** date-fns locale for the month titles and weekday labels. */
|
|
40
45
|
locale?: Locale;
|
|
46
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
41
47
|
theme?: Partial<DomCalendarTheme>;
|
|
42
48
|
/** Height of the scroll viewport, in px (default 480). */
|
|
43
49
|
height?: number | string;
|
|
@@ -47,8 +53,11 @@ export interface MonthListProps<T = unknown> extends DateSelectionConstraints {
|
|
|
47
53
|
* layout (no `events`) is always navigable regardless.
|
|
48
54
|
*/
|
|
49
55
|
keyboardDayNavigation?: boolean;
|
|
56
|
+
/** Fired when a selectable day is clicked. */
|
|
50
57
|
onPressDay?: (date: Date) => void;
|
|
58
|
+
/** Class applied to the root element. */
|
|
51
59
|
className?: string;
|
|
60
|
+
/** Inline styles applied to the root element. */
|
|
52
61
|
style?: CSSProperties;
|
|
53
62
|
}
|
|
54
63
|
|
|
@@ -81,7 +90,7 @@ export function MonthList<T = unknown>({
|
|
|
81
90
|
onPressDay,
|
|
82
91
|
className,
|
|
83
92
|
style,
|
|
84
|
-
}: MonthListProps<T>) {
|
|
93
|
+
}: MonthListProps<T>): ReactElement {
|
|
85
94
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
86
95
|
|
|
87
96
|
const months = useMemo(() => {
|
package/src/MonthView.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type ComponentType,
|
|
12
12
|
type CSSProperties,
|
|
13
13
|
type KeyboardEvent as ReactKeyboardEvent,
|
|
14
|
+
type ReactElement,
|
|
14
15
|
useEffect,
|
|
15
16
|
useMemo,
|
|
16
17
|
useRef,
|
|
@@ -40,12 +41,16 @@ const CELL_PAD = 4;
|
|
|
40
41
|
|
|
41
42
|
/** Props passed to a custom month event chip renderer. */
|
|
42
43
|
export interface DomMonthEventArgs<T = unknown> {
|
|
44
|
+
/** The event to render. */
|
|
43
45
|
event: CalendarEvent<T>;
|
|
46
|
+
/** Call to fire the view's `onPressEvent` for this chip. */
|
|
44
47
|
onPress: () => void;
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
/** A component that renders a single month-grid event chip. */
|
|
47
51
|
export type DomMonthEvent<T = unknown> = ComponentType<DomMonthEventArgs<T>>;
|
|
48
52
|
|
|
53
|
+
/** Props for {@link MonthView}. */
|
|
49
54
|
export interface MonthViewProps<T = unknown> extends DateSelectionConstraints {
|
|
50
55
|
/** Any day within the month to render. */
|
|
51
56
|
date: Date;
|
|
@@ -95,7 +100,9 @@ export interface MonthViewProps<T = unknown> extends DateSelectionConstraints {
|
|
|
95
100
|
* (rendered without `events`) is always navigable regardless of this flag.
|
|
96
101
|
*/
|
|
97
102
|
keyboardDayNavigation?: boolean;
|
|
103
|
+
/** Class applied to the root element. */
|
|
98
104
|
className?: string;
|
|
105
|
+
/** Inline styles applied to the root element. */
|
|
99
106
|
style?: CSSProperties;
|
|
100
107
|
}
|
|
101
108
|
|
|
@@ -281,7 +288,14 @@ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
|
281
288
|
eventsByDay?: ReadonlyMap<string, CalendarEvent<T>[]>;
|
|
282
289
|
}
|
|
283
290
|
|
|
284
|
-
/**
|
|
291
|
+
/**
|
|
292
|
+
* A single static month grid, rendered with plain DOM elements.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```tsx
|
|
296
|
+
* <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
285
299
|
export function MonthView<T = unknown>({
|
|
286
300
|
date,
|
|
287
301
|
weekStartsOn = 0,
|
|
@@ -307,7 +321,7 @@ export function MonthView<T = unknown>({
|
|
|
307
321
|
keyboardDayNavigation = false,
|
|
308
322
|
className,
|
|
309
323
|
style,
|
|
310
|
-
}: MonthViewInternalProps<T>) {
|
|
324
|
+
}: MonthViewInternalProps<T>): ReactElement {
|
|
311
325
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
312
326
|
|
|
313
327
|
// Calendar layout (date in the corner + event chips) is on whenever `events`
|
package/src/TimeGrid.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type ComponentType,
|
|
4
4
|
type CSSProperties,
|
|
5
5
|
type PointerEvent as ReactPointerEvent,
|
|
6
|
+
type ReactElement,
|
|
6
7
|
type ReactNode,
|
|
7
8
|
useEffect,
|
|
8
9
|
useMemo,
|
|
@@ -36,25 +37,38 @@ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v
|
|
|
36
37
|
|
|
37
38
|
/** Props passed to a custom time-grid event renderer. */
|
|
38
39
|
export interface DomRenderEventArgs<T = unknown> {
|
|
40
|
+
/** The event to render. */
|
|
39
41
|
event: CalendarEvent<T>;
|
|
42
|
+
/** The current view mode. */
|
|
40
43
|
mode: CalendarMode;
|
|
44
|
+
/** Whether the event is all-day. */
|
|
41
45
|
isAllDay: boolean;
|
|
46
|
+
/** Pixel height of the event box (timed events only). */
|
|
42
47
|
boxHeight?: number;
|
|
48
|
+
/** The event started before the visible day and continues into it. */
|
|
43
49
|
continuesBefore?: boolean;
|
|
50
|
+
/** The event continues past the visible day. */
|
|
44
51
|
continuesAfter?: boolean;
|
|
45
52
|
/** Show the time range in 12-hour AM/PM. */
|
|
46
53
|
ampm?: boolean;
|
|
54
|
+
/** Call to fire the view's `onPressEvent` for this event. */
|
|
47
55
|
onPress: () => void;
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
/** A component that renders a single time-grid event box. */
|
|
50
59
|
export type DomRenderEvent<T = unknown> = ComponentType<DomRenderEventArgs<T>>;
|
|
51
60
|
|
|
61
|
+
/** Props for {@link TimeGrid}. */
|
|
52
62
|
export interface TimeGridProps<T = unknown> {
|
|
63
|
+
/** Anchor date; the visible columns are derived from it and `mode`. */
|
|
53
64
|
date: Date;
|
|
65
|
+
/** Events to lay out on the grid. */
|
|
54
66
|
events?: CalendarEvent<T>[];
|
|
55
67
|
/** "day" (default), "3days", "week", or "custom" (with `numberOfDays`). */
|
|
56
68
|
mode?: TimeGridMode;
|
|
69
|
+
/** Column count for `mode="custom"`. */
|
|
57
70
|
numberOfDays?: number;
|
|
71
|
+
/** First day of the week. Sunday = 0 (default) ... Saturday = 6. */
|
|
58
72
|
weekStartsOn?: WeekStartsOn;
|
|
59
73
|
/** Initial pixels per hour (default 48). */
|
|
60
74
|
hourHeight?: number;
|
|
@@ -62,7 +76,9 @@ export interface TimeGridProps<T = unknown> {
|
|
|
62
76
|
scrollOffsetMinutes?: number;
|
|
63
77
|
/** Pinch / Ctrl-⌘-scroll to zoom the grid (default true). */
|
|
64
78
|
zoomable?: boolean;
|
|
79
|
+
/** Lower bound for pixels per hour when zooming. */
|
|
65
80
|
minHourHeight?: number;
|
|
81
|
+
/** Upper bound for pixels per hour when zooming. */
|
|
66
82
|
maxHourHeight?: number;
|
|
67
83
|
/** Snap dragged events to this many minutes (default 15). */
|
|
68
84
|
dragStepMinutes?: number;
|
|
@@ -76,13 +92,19 @@ export interface TimeGridProps<T = unknown> {
|
|
|
76
92
|
showNowIndicator?: boolean;
|
|
77
93
|
/** Show the all-day lane above the grid (default true). */
|
|
78
94
|
showAllDayEventCell?: boolean;
|
|
95
|
+
/** date-fns locale for the column headers and time labels. */
|
|
79
96
|
locale?: Locale;
|
|
97
|
+
/** Theme overrides; falls back to the default light theme. */
|
|
80
98
|
theme?: Partial<DomCalendarTheme>;
|
|
99
|
+
/** Height of the scroll viewport, in px. */
|
|
81
100
|
height?: number | string;
|
|
101
|
+
/** Custom event renderer; falls back to the built-in event box. */
|
|
82
102
|
renderEvent?: DomRenderEvent<T>;
|
|
83
|
-
/** Replace the hour-axis label. Receives the hour (0
|
|
103
|
+
/** Replace the hour-axis label. Receives the hour (0-23) and the `ampm` flag. */
|
|
84
104
|
hourComponent?: (hour: number, ampm: boolean) => ReactNode;
|
|
105
|
+
/** Tap an event. */
|
|
85
106
|
onPressEvent?: (event: CalendarEvent<T>) => void;
|
|
107
|
+
/** Tap a day's column header. */
|
|
86
108
|
onPressDateHeader?: (day: Date) => void;
|
|
87
109
|
/** Tap empty grid space; called with the date and time at the press. */
|
|
88
110
|
onPressCell?: (date: Date) => void;
|
|
@@ -95,7 +117,9 @@ export interface TimeGridProps<T = unknown> {
|
|
|
95
117
|
* Return `false` to reject the drop (the event snaps back).
|
|
96
118
|
*/
|
|
97
119
|
onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
|
|
120
|
+
/** Class applied to the root element. */
|
|
98
121
|
className?: string;
|
|
122
|
+
/** Inline styles applied to the root element. */
|
|
99
123
|
style?: CSSProperties;
|
|
100
124
|
}
|
|
101
125
|
|
|
@@ -190,6 +214,11 @@ function DefaultDomEvent<T>({
|
|
|
190
214
|
* positioned with the library's pure `layoutDayEvents`, so overlap columns and
|
|
191
215
|
* multi-day clipping match the React Native renderer. Supports Ctrl/⌘-scroll and
|
|
192
216
|
* two-finger pinch to zoom, and pointer drag to move / resize events.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* <TimeGrid mode="week" date={new Date()} events={events} />
|
|
221
|
+
* ```
|
|
193
222
|
*/
|
|
194
223
|
export function TimeGrid<T = unknown>({
|
|
195
224
|
date,
|
|
@@ -221,7 +250,7 @@ export function TimeGrid<T = unknown>({
|
|
|
221
250
|
onDragEvent,
|
|
222
251
|
className,
|
|
223
252
|
style,
|
|
224
|
-
}: TimeGridProps<T>) {
|
|
253
|
+
}: TimeGridProps<T>): ReactElement {
|
|
225
254
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
226
255
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
227
256
|
const dfns = locale ? { locale } : undefined;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The react-dom renderer for super-calendar: real DOM components, no React
|
|
3
|
+
* Native and no react-native-web.
|
|
4
|
+
*
|
|
5
|
+
* Built on the headless core and Legend List's DOM renderer. The headless hooks
|
|
6
|
+
* (`useDateRange`, `useMonthGrid`) are re-exported below for selection state and
|
|
7
|
+
* custom layouts.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { Calendar } from "@super-calendar/dom";
|
|
12
|
+
*
|
|
13
|
+
* export function App() {
|
|
14
|
+
* return <Calendar mode="month" />;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://super-calendar.afonsojramos.me
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
5
22
|
export { Agenda, type AgendaProps, type DomAgendaEvent, type DomAgendaEventArgs } from "./Agenda";
|
|
6
23
|
export { Calendar, type CalendarProps } from "./Calendar";
|
|
7
24
|
export {
|
package/src/theme.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
// DOM-specific pixel metrics and font stack live here.
|
|
6
6
|
import { type CalendarColors, darkColors, lightColors } from "@super-calendar/core";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Theme for the react-dom renderer. Combines the shared color palette from
|
|
10
|
+
* `@super-calendar/core` with the DOM-specific pixel metrics and font stack.
|
|
11
|
+
*/
|
|
8
12
|
export type DomCalendarTheme = CalendarColors & {
|
|
9
13
|
/** Row height of a day cell, in px. */
|
|
10
14
|
cellHeight: number;
|
|
@@ -25,8 +29,10 @@ const SYSTEM_FONT =
|
|
|
25
29
|
|
|
26
30
|
const METRICS = { cellHeight: 48, dayBadgeSize: 34, rangeBandHeight: 32, fontFamily: SYSTEM_FONT };
|
|
27
31
|
|
|
32
|
+
/** The default light theme: the core light palette plus the DOM metrics. */
|
|
28
33
|
export const defaultDomTheme: DomCalendarTheme = { ...lightColors, ...METRICS };
|
|
29
34
|
|
|
35
|
+
/** The dark theme: the core dark palette plus the DOM metrics. */
|
|
30
36
|
export const darkDomTheme: DomCalendarTheme = { ...darkColors, ...METRICS };
|
|
31
37
|
|
|
32
38
|
/** Merge a partial override onto a base theme (defaults to {@link defaultDomTheme}). */
|