@super-calendar/solid 0.0.0-stage → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1936 @@
1
+ import { Dynamic, type JSX } from "@solidjs/web";
2
+ import {
3
+ bandRounding,
4
+ buildMonthGrid,
5
+ buildMultiWeekGrid,
6
+ type CalendarEvent,
7
+ type CalendarLabels,
8
+ compareDayEvents,
9
+ type DateRange,
10
+ type DateSelectionConstraints,
11
+ dayAccessibilityLabel,
12
+ dayBadgeKind,
13
+ type EventAccessibilityLabeler,
14
+ groupEventsByDay,
15
+ isAllDayEvent,
16
+ isBackgroundEvent,
17
+ layoutMonthWeek,
18
+ monthCreateRange,
19
+ monthDropBounds,
20
+ type MonthGridWeekday,
21
+ type MultiWeekGridDay,
22
+ overlapsOtherEvents,
23
+ rangeBandKind,
24
+ resolveCalendarLabels,
25
+ type WeekdayFormat,
26
+ type WeekStartsOn,
27
+ } from "@super-calendar/core/vanilla";
28
+ import {
29
+ addDays,
30
+ endOfMonth,
31
+ format,
32
+ isSameMonth,
33
+ type Locale,
34
+ startOfDay,
35
+ startOfMonth,
36
+ } from "date-fns";
37
+ import {
38
+ type Component,
39
+ createEffect,
40
+ createMemo,
41
+ createSignal,
42
+ For,
43
+ Show,
44
+ untrack,
45
+ } from "solid-js";
46
+ import { holdDateDrag } from "./touch";
47
+ import { withDefaults } from "./props";
48
+ import { createSlots, dataState, type SlotDefault, type SlotStyleProps } from "./slots";
49
+ import { css, type CSSProperties, type DomKeyboardEvent, type ElementRef } from "./styles";
50
+ import { mergeSolidTheme, type SolidCalendarTheme } from "./theme";
51
+
52
+ /**
53
+ * Styleable parts of {@link MonthView}. Pass a class or inline style per slot via
54
+ * the `classNames` / `styles` props to restyle just that part.
55
+ */
56
+ export type MonthViewSlot =
57
+ | "title"
58
+ | "weekdays"
59
+ | "weekday"
60
+ | "grid"
61
+ | "week"
62
+ | "day"
63
+ | "dayBadge"
64
+ | "rangeBand"
65
+ | "events"
66
+ | "chipButton"
67
+ | "chip"
68
+ | "more"
69
+ | "morePopover";
70
+
71
+ // Stable empty layout for rows with no events (avoids a fresh object per render).
72
+ const EMPTY_LAYOUT = {
73
+ segments: [],
74
+ laneCount: 0,
75
+ } as const;
76
+
77
+ // Chip metrics for the events layout (when `events` is provided).
78
+ const DATE_ROW = 24;
79
+ const CHIP_HEIGHT = 18;
80
+ const CHIP_GAP = 2;
81
+ const CELL_PAD = 4;
82
+ // Opacity of an event chip while it is being dragged to another day.
83
+ const DRAGGED_CHIP_OPACITY = 0.4;
84
+
85
+ /** Props passed to a custom month event chip renderer. */
86
+ export interface SolidMonthEventArgs<T = unknown> {
87
+ /** The event to render. */
88
+ event: CalendarEvent<T>;
89
+ /** Call to fire the view's `onPressEvent` for this chip. */
90
+ onPress: () => void;
91
+ /** The current row view. Supplied by the calendar; optional for existing standalone chip callers. */
92
+ mode?: "month" | "multiweek";
93
+ }
94
+
95
+ /** A component that renders a single month-grid event chip. */
96
+ export type SolidMonthEvent<T = unknown> = Component<SolidMonthEventArgs<T>>;
97
+
98
+ // An in-progress month drag: either a day span being swept out for a new event,
99
+ // or an existing event being carried to another day. Days are held as start-of-day
100
+ // timestamps, so the reducer-ish updates compare cheaply.
101
+ type MonthDrag<T> = (
102
+ | {
103
+ kind: "create";
104
+ pointerId: number;
105
+ anchor: number;
106
+ hover: number;
107
+ }
108
+ | {
109
+ kind: "move";
110
+ pointerId: number;
111
+ event: CalendarEvent<T>;
112
+ from: number;
113
+ to: number;
114
+ }
115
+ ) & {
116
+ // The rows the drag began in, so a drag never commits into a different window.
117
+ windowKey: string;
118
+ };
119
+
120
+ // A day as the shared rows render it. Month days carry `isCurrentMonth`;
121
+ // multi-week days omit it because every one of them is inside the period.
122
+ type RowDay = MultiWeekGridDay & { isCurrentMonth?: boolean };
123
+ type RowWeek = { id: string; days: RowDay[] };
124
+
125
+ // A leading or trailing day of a neighbouring month in the month grid.
126
+ const isOutsidePeriod = (day: RowDay) => day.isCurrentMonth === false;
127
+
128
+ /** Props for {@link MonthView}. */
129
+ export interface MonthViewProps<T = unknown>
130
+ extends DateSelectionConstraints, SlotStyleProps<MonthViewSlot> {
131
+ /** Any day within the month to render. */
132
+ date: Date;
133
+ /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
134
+ weekStartsOn?: WeekStartsOn;
135
+ /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
136
+ hiddenDays?: number[];
137
+ /** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
138
+ weekdayFormat?: WeekdayFormat;
139
+ /**
140
+ * Events to render as chips in each day cell. Passing this (even `[]`) switches
141
+ * the grid to the calendar layout (date in the corner, chips below); omit it for
142
+ * the compact date-picker look.
143
+ */
144
+ events?: CalendarEvent<T>[];
145
+ /** Custom chip renderer; falls back to the built-in titled chip. */
146
+ renderEvent?: SolidMonthEvent<T>;
147
+ /**
148
+ * Override the screen-reader label for each event chip. Receives the event and a
149
+ * `{ mode: "month", isAllDay, ampm: false }` context; return the full text to
150
+ * announce. Defaults to the event title and day (e.g. "Standup, 15 July").
151
+ */
152
+ eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
153
+ /**
154
+ * Max event lanes (stacked rows) shown per week before the rest of a day's
155
+ * events collapse into a "+N more" row (default 3). Because multi-day events draw
156
+ * as one bar spanning a lane across the week, this caps lanes per row, not chips
157
+ * per day, so a long bar can push a lightly-booked day's own events into "+N more".
158
+ */
159
+ maxVisibleEventCount?: number;
160
+ /** Height of an event chip and of the "+N more" row, in px (default 18). */
161
+ chipHeight?: number;
162
+ /** Vertical gap between event chips, in px (default 2). */
163
+ chipGap?: number;
164
+ /** Template for the overflow row; `{moreCount}` is replaced (default "{moreCount} More"). */
165
+ moreLabel?: string;
166
+ /** Translations for the screen-reader words and gutter text; omitted keys use English. */
167
+ labels?: Partial<CalendarLabels>;
168
+ /** Tap an event chip. */
169
+ onPressEvent?: (event: CalendarEvent<T>) => void;
170
+ /** Tap the "+N more" overflow row. */
171
+ onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
172
+ /** Selected span; days between the endpoints get the range band. */
173
+ selectedRange?: DateRange;
174
+ /** Discrete selected days (single / multiple). */
175
+ selectedDates?: Date[];
176
+ /** Render days from the neighbouring months in the leading/trailing cells (default true). */
177
+ showAdjacentMonths?: boolean;
178
+ /** Tint weekend day cells with the theme's weekend background (default true). */
179
+ highlightWeekends?: boolean;
180
+ /**
181
+ * Fill the whole cell with the range background instead of the default
182
+ * centered rounded "pill" strip. Default false.
183
+ */
184
+ fillCellOnSelection?: boolean;
185
+ /** Render the "Month yyyy" title above the grid (default true). */
186
+ showTitle?: boolean;
187
+ /** Render the weekday header row (default true). */
188
+ showWeekdays?: boolean;
189
+ /** date-fns locale for the title and weekday labels. */
190
+ locale?: Locale;
191
+ /** Theme overrides; falls back to the default light theme. */
192
+ theme?: Partial<SolidCalendarTheme>;
193
+ /** Fired when a selectable day is clicked. */
194
+ onPressDay?: (date: Date) => void;
195
+ /**
196
+ * Fired alongside `onPressDay` when a day cell is clicked, with the same day at
197
+ * midnight, so one handler can create events across month and week/day modes.
198
+ */
199
+ onPressCell?: (date: Date) => void;
200
+ /**
201
+ * In events mode, enables drag-to-create: press on a day and drag across others
202
+ * to sketch a span, then release to fire this with the all-day range (`start` at
203
+ * midnight of the first day, `end` at midnight after the last, exclusive). A plain
204
+ * click without dragging still fires `onPressDay`, not this. Days being sketched
205
+ * carry `data-creating` for styling.
206
+ */
207
+ onCreateEvent?: (start: Date, end: Date) => void;
208
+ /**
209
+ * Reports the day span of a create sweep **as it happens**, as the ordered
210
+ * inclusive `[start, end]` days (both at midnight), so a selection highlight can
211
+ * follow the drag instead of appearing only on release. Pair it with
212
+ * `createDateRange`'s `selectRange` to drive `selectedRange`. Enables the sweep on
213
+ * its own, so it works without `onCreateEvent`.
214
+ */
215
+ onSelectDrag?: (start: Date, end: Date) => void;
216
+ /**
217
+ * In events mode, enables drag-to-reschedule: press an event chip and drop it on
218
+ * another day. Called with the event and its new `start`/`end`, both shifted by
219
+ * the whole days dragged, so the time of day and duration are preserved. Return
220
+ * `false` to reject the drop. The day under the pointer carries `data-drop` for
221
+ * styling.
222
+ */
223
+ onDragEvent?: (event: CalendarEvent<T>, start: Date, end: Date) => void | boolean;
224
+ /** Fired the instant an event is picked up for a drag, before anything is committed. */
225
+ onDragStart?: (event: CalendarEvent<T>) => void;
226
+ /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
227
+ eventStartEditable?: boolean;
228
+ /** Reject a drop that would overlap another event (default true = allowed). */
229
+ eventOverlap?: boolean;
230
+ /**
231
+ * When events are shown, also make the day cells keyboard-navigable: a single
232
+ * roving tab stop, arrow keys move the focus, Enter opens the day (`onPressDay`).
233
+ * Default false, so keyboard focus moves through events only. The date picker
234
+ * (rendered without `events`) is always navigable regardless of this flag.
235
+ */
236
+ keyboardDayNavigation?: boolean;
237
+ /** Class applied to the root element. */
238
+ className?: string;
239
+ /** Inline styles applied to the root element. */
240
+ style?: CSSProperties;
241
+ }
242
+
243
+ // Each helper returns the slot's built-in styling split into `base` (structural,
244
+ // always applied) and `themed` (colour/type/spacing, dropped when a class is set).
245
+
246
+ function dayCellDefault(
247
+ day: RowDay,
248
+ theme: SolidCalendarTheme,
249
+ highlightWeekends: boolean,
250
+ ): SlotDefault {
251
+ return {
252
+ base: {
253
+ position: "relative",
254
+ height: theme.cellHeight,
255
+ border: "none",
256
+ font: "inherit",
257
+ cursor: day.isDisabled ? "default" : "pointer",
258
+ display: "flex",
259
+ alignItems: "center",
260
+ justifyContent: "center",
261
+ padding: 0,
262
+ WebkitTapHighlightColor: "transparent",
263
+ },
264
+ themed: {
265
+ // The range band is a separate layer; the cell only carries the weekend tint.
266
+ background:
267
+ highlightWeekends && day.isWeekend && !day.isInRange
268
+ ? theme.weekendBackground
269
+ : "transparent",
270
+ fontSize: 15,
271
+ color: day.isDisabled ? theme.textDisabled : theme.text,
272
+ },
273
+ };
274
+ }
275
+
276
+ /**
277
+ * The range band behind a day, rendered as its own layer so it can be a centered
278
+ * rounded strip (the default) or fill the whole cell (`fillCell`). Returns null
279
+ * for days with no band. Endpoints get the leading/trailing pill rounding. Its
280
+ * geometry is structural; only the fill colour is themed.
281
+ *
282
+ * In events mode the strip tracks the compact date badge instead of the picker's
283
+ * tall cell, so it reads as a band across the dates rather than a block over the
284
+ * event chips (and matches the native renderer's month grid).
285
+ */
286
+ function rangeBandDefault(
287
+ day: RowDay,
288
+ theme: SolidCalendarTheme,
289
+ fillCell: boolean,
290
+ eventsMode: boolean,
291
+ ): SlotDefault | null {
292
+ const kind = rangeBandKind(day, fillCell);
293
+ if (kind === "none") return null;
294
+ const fill = kind === "fill";
295
+ const badgeSize = eventsMode ? DATE_ROW - 2 : theme.dayBadgeSize;
296
+ const bandHeight = eventsMode ? badgeSize : theme.rangeBandHeight;
297
+ const inset = fill ? 0 : eventsMode ? CELL_PAD : Math.max(0, (theme.cellHeight - bandHeight) / 2);
298
+ const radius = fill ? 0 : bandHeight / 2;
299
+ const rounding = bandRounding(kind);
300
+ // Cap the pill at the endpoint circles: a start/end band stops at the circle's
301
+ // outer edge (half a badge in from the cell centre) rather than spilling to the
302
+ // cell edge, so no band shows in the empty space beside the day circles. Events
303
+ // mode puts the badge in the cell's corner instead of its centre, so there the
304
+ // band spans the whole cell and only rounds its outer ends.
305
+ const cap = eventsMode ? 0 : `calc(50% - ${badgeSize / 2}px)`;
306
+ const base: CSSProperties = {
307
+ position: "absolute",
308
+ left: rounding.start ? cap : 0,
309
+ right: rounding.end ? cap : 0,
310
+ top: inset,
311
+ // An events cell is far taller than its date row, so the strip is sized from
312
+ // the badge rather than stretched to the cell's bottom.
313
+ ...(fill || !eventsMode
314
+ ? {
315
+ bottom: inset,
316
+ }
317
+ : {
318
+ height: bandHeight,
319
+ }),
320
+ zIndex: 0,
321
+ };
322
+ if (rounding.start) {
323
+ base.borderTopLeftRadius = radius;
324
+ base.borderBottomLeftRadius = radius;
325
+ }
326
+ if (rounding.end) {
327
+ base.borderTopRightRadius = radius;
328
+ base.borderBottomRightRadius = radius;
329
+ }
330
+ return {
331
+ base,
332
+ themed: {
333
+ background: theme.rangeBackground,
334
+ },
335
+ };
336
+ }
337
+ function badgeDefault(day: RowDay, theme: SolidCalendarTheme, hovered: boolean): SlotDefault {
338
+ const badge = dayBadgeKind(day, day.isToday);
339
+ const filled = badge !== "none";
340
+ const background = filled
341
+ ? badge === "today"
342
+ ? theme.todayBackground
343
+ : theme.selectedBackground
344
+ : hovered
345
+ ? theme.hoverBackground
346
+ : "transparent";
347
+ return {
348
+ base: {
349
+ position: "relative",
350
+ zIndex: 1,
351
+ width: theme.dayBadgeSize,
352
+ height: theme.dayBadgeSize,
353
+ borderRadius: "50%",
354
+ display: "flex",
355
+ alignItems: "center",
356
+ justifyContent: "center",
357
+ },
358
+ themed: {
359
+ background,
360
+ color: filled ? (day.isToday ? theme.todayText : theme.selectedText) : "inherit",
361
+ },
362
+ };
363
+ }
364
+
365
+ // --- Calendar (events) layout styles -------------------------------------
366
+
367
+ function eventCellDefault(
368
+ day: RowDay,
369
+ theme: SolidCalendarTheme,
370
+ height: number,
371
+ highlightWeekends: boolean,
372
+ // True while a drag is over this day: a create sweep covering it, or a move
373
+ // about to land on it. Tinted over the weekend shading so the drag reads live.
374
+ isDragTarget: boolean,
375
+ chipGap: number,
376
+ ): SlotDefault {
377
+ return {
378
+ base: {
379
+ position: "relative",
380
+ minHeight: height,
381
+ minWidth: 0,
382
+ border: "none",
383
+ cursor: day.isDisabled ? "default" : "pointer",
384
+ display: "flex",
385
+ flexDirection: "column",
386
+ gap: chipGap,
387
+ padding: CELL_PAD,
388
+ boxSizing: "border-box",
389
+ textAlign: "left",
390
+ WebkitTapHighlightColor: "transparent",
391
+ },
392
+ themed: {
393
+ borderTop: `1px solid ${theme.gridLine}`,
394
+ background: isDragTarget
395
+ ? theme.rangeBackground
396
+ : highlightWeekends && day.isWeekend && !day.isInRange
397
+ ? theme.weekendBackground
398
+ : "transparent",
399
+ color: day.isDisabled ? theme.textDisabled : theme.text,
400
+ },
401
+ };
402
+ }
403
+ function compactBadgeDefault(day: RowDay, theme: SolidCalendarTheme): SlotDefault {
404
+ const badge = dayBadgeKind(day, day.isToday);
405
+ const filled = badge !== "none";
406
+ return {
407
+ base: {
408
+ position: "relative",
409
+ zIndex: 1,
410
+ alignSelf: "flex-end",
411
+ width: DATE_ROW - 2,
412
+ height: DATE_ROW - 2,
413
+ borderRadius: "50%",
414
+ display: "flex",
415
+ alignItems: "center",
416
+ justifyContent: "center",
417
+ },
418
+ themed: {
419
+ fontSize: 13,
420
+ background: filled
421
+ ? badge === "today"
422
+ ? theme.todayBackground
423
+ : theme.selectedBackground
424
+ : "transparent",
425
+ color: filled ? (day.isToday ? theme.todayText : theme.selectedText) : "inherit",
426
+ },
427
+ };
428
+ }
429
+ const chipButtonDefault: SlotDefault = {
430
+ base: {
431
+ position: "relative",
432
+ zIndex: 1,
433
+ border: "none",
434
+ padding: 0,
435
+ margin: 0,
436
+ background: "transparent",
437
+ cursor: "pointer",
438
+ textAlign: "left",
439
+ fontFamily: "inherit",
440
+ },
441
+ };
442
+ function chipDefault(theme: SolidCalendarTheme, chipHeight: number): SlotDefault {
443
+ return {
444
+ base: {
445
+ display: "block",
446
+ height: chipHeight,
447
+ lineHeight: `${chipHeight}px`,
448
+ whiteSpace: "nowrap",
449
+ overflow: "hidden",
450
+ textOverflow: "ellipsis",
451
+ },
452
+ themed: {
453
+ padding: "0 6px",
454
+ borderRadius: 4,
455
+ background: theme.eventBackground,
456
+ color: theme.eventText,
457
+ fontSize: 11,
458
+ fontWeight: 600,
459
+ },
460
+ };
461
+ }
462
+ function moreButtonDefault(
463
+ theme: SolidCalendarTheme,
464
+ chipHeight: number,
465
+ multiWeek = false,
466
+ ): SlotDefault {
467
+ return {
468
+ base: {
469
+ position: "relative",
470
+ zIndex: 1,
471
+ border: "none",
472
+ background: "transparent",
473
+ cursor: "pointer",
474
+ textAlign: "left",
475
+ height: chipHeight,
476
+ lineHeight: `${chipHeight}px`,
477
+ fontFamily: "inherit",
478
+ ...(multiWeek ? { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } : {}),
479
+ },
480
+ themed: {
481
+ padding: "0 6px",
482
+ fontSize: 11,
483
+ fontWeight: 600,
484
+ color: theme.textMuted,
485
+ },
486
+ };
487
+ }
488
+
489
+ // Internal-only: MonthList passes a day→events index built once for the whole
490
+ // list (via `groupEventsByDay`) so each month doesn't rebuild it. Not exported,
491
+ // so it stays off the public MonthViewProps surface.
492
+ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
493
+ eventsByDay?: ReadonlyMap<string, CalendarEvent<T>[]>;
494
+ }
495
+
496
+ // The distinct events touching a week row, in the per-day index's sorted order.
497
+ // A multi-day event lives in each covered day's bucket, so dedupe by reference;
498
+ // this scans only the row's days, not every event in the month.
499
+ function collectRowEvents<T>(
500
+ week: RowWeek,
501
+ eventsByDay: ReadonlyMap<string, CalendarEvent<T>[]>,
502
+ ): CalendarEvent<T>[] {
503
+ const seen = new Set<CalendarEvent<T>>();
504
+ const out: CalendarEvent<T>[] = [];
505
+ for (const day of week.days) {
506
+ const list = eventsByDay.get(startOfDay(day.date).toISOString());
507
+ if (!list) continue;
508
+ for (const event of list) {
509
+ if (!seen.has(event)) {
510
+ seen.add(event);
511
+ out.push(event);
512
+ }
513
+ }
514
+ }
515
+ return out;
516
+ }
517
+
518
+ /**
519
+ * Which rows a {@link DateRows} grid shows. Internal to the package: the public
520
+ * views adapt their own props to it.
521
+ */
522
+ export type DateRowsSource =
523
+ | {
524
+ kind: "month";
525
+ /** Any day within the month to render. */
526
+ date: Date;
527
+ showAdjacentMonths: boolean;
528
+ }
529
+ | {
530
+ kind: "multiweek";
531
+ /** Any day within the first week to render. */
532
+ date: Date;
533
+ numberOfWeeks: number;
534
+ };
535
+
536
+ // The localized first and last displayed days, e.g. "Nov 1, 2026 – Nov 14, 2026".
537
+ function rangeTitle(start: Date, endExclusive: Date, locale?: Locale): string {
538
+ const options = locale ? { locale } : undefined;
539
+ return `${format(start, "PP", options)} – ${format(addDays(endExclusive, -1), "PP", options)}`;
540
+ }
541
+
542
+ /** Props for the private {@link DateRows} grid shared by the public row views. */
543
+ export interface DateRowsProps<T = unknown> extends Omit<
544
+ MonthViewInternalProps<T>,
545
+ "date" | "showAdjacentMonths"
546
+ > {
547
+ source: DateRowsSource;
548
+ }
549
+
550
+ /**
551
+ * A single static month grid, rendered with plain DOM elements.
552
+ *
553
+ * @example
554
+ * ```tsx
555
+ * <MonthView date={new Date()} events={events} onPressDay={(d) => setDate(d)} />
556
+ * ```
557
+ */
558
+ export function MonthView<T = unknown>(props: MonthViewInternalProps<T>): JSX.Element {
559
+ return (
560
+ <DateRows<T>
561
+ {...props}
562
+ source={{
563
+ kind: "month",
564
+ get date() {
565
+ return props.date;
566
+ },
567
+ get showAdjacentMonths() {
568
+ return props.showAdjacentMonths ?? true;
569
+ },
570
+ }}
571
+ />
572
+ );
573
+ }
574
+
575
+ /**
576
+ * The day-row grid behind the public row views: week rows of day cells with
577
+ * spanning event bars, overflow, selection, drag, and keyboard handling.
578
+ */
579
+ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
580
+ const props = withDefaults(
581
+ {
582
+ weekStartsOn: 0,
583
+ weekdayFormat: "short",
584
+ maxVisibleEventCount: 3,
585
+ chipHeight: CHIP_HEIGHT,
586
+ chipGap: CHIP_GAP,
587
+ moreLabel: "{moreCount} More",
588
+ highlightWeekends: true,
589
+ fillCellOnSelection: false,
590
+ showTitle: true,
591
+ showWeekdays: true,
592
+ eventStartEditable: true,
593
+ eventOverlap: true,
594
+ keyboardDayNavigation: false,
595
+ } satisfies Partial<DateRowsProps<T>>,
596
+ incoming,
597
+ );
598
+ const theme = createMemo(() => mergeSolidTheme(props.theme));
599
+ const labels = createMemo(() => resolveCalendarLabels(props.labels));
600
+ const slot = createSlots<MonthViewSlot>(props);
601
+ const multiWeek = createMemo(() => props.source.kind === "multiweek");
602
+ // Multi-week rows only contain days of the requested period, so nothing is blanked.
603
+ const showAdjacentMonths = createMemo(() =>
604
+ props.source.kind === "month" ? props.source.showAdjacentMonths : true,
605
+ );
606
+ const numberOfWeeks = createMemo(() =>
607
+ props.source.kind === "multiweek" ? props.source.numberOfWeeks : undefined,
608
+ );
609
+ // The mode reported to custom renderers and accessibility labels.
610
+ const viewMode = createMemo((): "month" | "multiweek" => (multiWeek() ? "multiweek" : "month"));
611
+
612
+ // Calendar layout (date in the corner + event chips) is on whenever `events`
613
+ // is provided; otherwise the compact picker badge layout is used. Multi-week
614
+ // rows always use the calendar layout.
615
+ const eventsMode = createMemo(() => props.events !== undefined || multiWeek());
616
+ // The day cells form a roving tab stop (arrow keys + Enter) in the picker
617
+ // always, and in events mode only when the consumer opts in. Otherwise events
618
+ // mode tabs through the event chips alone.
619
+ const dayRoving = createMemo(() => !eventsMode() || props.keyboardDayNavigation);
620
+ // Use the list-built index when provided (MonthList), else build it for this
621
+ // month. Either way lookups use startOfDay(date).toISOString().
622
+ const eventsByDay = createMemo(() => {
623
+ // The list (MonthList) sorts before passing its index in; only sort here when
624
+ // building our own, so each day reads all-day events first, then by start.
625
+ if (props.eventsByDay) return props.eventsByDay;
626
+ // Background events shade the time grid; the month grid ignores them.
627
+ const map = groupEventsByDay((props.events ?? []).filter((event) => !isBackgroundEvent(event)));
628
+ for (const list of map.values()) list.sort(compareDayEvents);
629
+ return map;
630
+ });
631
+ const Chip = createMemo(() => props.renderEvent);
632
+ // Built-in "+N more" popover: opens when the consumer doesn't handle
633
+ // `onPressMore` themselves. Keyed by the day id; closes on outside click,
634
+ // Escape, or picking an event.
635
+ const [moreOpenFor, setMoreOpenFor] = createSignal<string | null>(null);
636
+ const morePopoverRef: ElementRef<HTMLDivElement | null> = {
637
+ current: null,
638
+ };
639
+ // The "+N more" button that opened the popover, so focus can return to it.
640
+ const moreTriggerRef: ElementRef<HTMLButtonElement | null> = {
641
+ current: null,
642
+ };
643
+ createEffect(
644
+ () => [moreOpenFor()],
645
+ () =>
646
+ untrack(() => {
647
+ if (moreOpenFor()) {
648
+ // Move focus into the dialog so keyboard users land on the first event.
649
+ morePopoverRef.current?.querySelector<HTMLElement>("button")?.focus();
650
+ return;
651
+ }
652
+ // Return focus to the trigger when the popover closes.
653
+ moreTriggerRef.current?.focus();
654
+ moreTriggerRef.current = null;
655
+ }),
656
+ );
657
+ createEffect(
658
+ () => [moreOpenFor()],
659
+ () =>
660
+ untrack(() => {
661
+ if (!moreOpenFor()) return;
662
+ const onDocPointerDown = (e: PointerEvent) => {
663
+ if (!morePopoverRef.current?.contains(e.target as Node)) {
664
+ // A pointer dismissal moves focus to whatever was clicked; don't yank
665
+ // it back to the trigger (that's for Escape and event selection).
666
+ moreTriggerRef.current = null;
667
+ setMoreOpenFor(null);
668
+ }
669
+ };
670
+ const onKey = (e: KeyboardEvent) => {
671
+ if (e.key === "Escape") setMoreOpenFor(null);
672
+ };
673
+ document.addEventListener("pointerdown", onDocPointerDown);
674
+ document.addEventListener("keydown", onKey);
675
+ return () => {
676
+ document.removeEventListener("pointerdown", onDocPointerDown);
677
+ document.removeEventListener("keydown", onKey);
678
+ };
679
+ }),
680
+ );
681
+ // Reserve `maxVisibleEventCount` rows below the date so every cell is uniform;
682
+ // when a day overflows, the last row becomes the "+N more" affordance.
683
+ const eventRowHeight = createMemo(
684
+ () =>
685
+ CELL_PAD * 2 +
686
+ DATE_ROW +
687
+ (multiWeek() ? Math.max(1, props.maxVisibleEventCount) : props.maxVisibleEventCount) *
688
+ (props.chipHeight + props.chipGap),
689
+ );
690
+ const _grid = createMemo(
691
+ (): {
692
+ weeks: RowWeek[];
693
+ weekdays: MonthGridWeekday[];
694
+ title: string;
695
+ period: { start: Date; endExclusive: Date } | null;
696
+ } => {
697
+ const options = {
698
+ weekStartsOn: props.weekStartsOn,
699
+ hiddenDays: props.hiddenDays,
700
+ weekdayFormat: props.weekdayFormat,
701
+ selectedRange: props.selectedRange,
702
+ selectedDates: props.selectedDates,
703
+ minDate: props.minDate,
704
+ maxDate: props.maxDate,
705
+ isDateDisabled: props.isDateDisabled,
706
+ locale: props.locale,
707
+ };
708
+ const weeks = numberOfWeeks();
709
+ if (weeks === undefined) {
710
+ return {
711
+ ...buildMonthGrid(props.source.date, options),
712
+ title: format(
713
+ props.source.date,
714
+ "MMMM yyyy",
715
+ props.locale ? { locale: props.locale } : undefined,
716
+ ),
717
+ period: null,
718
+ };
719
+ }
720
+ const grid = buildMultiWeekGrid(props.source.date, { ...options, numberOfWeeks: weeks });
721
+ return {
722
+ weeks: grid.weeks,
723
+ weekdays: grid.weekdays,
724
+ title: rangeTitle(grid.visibleRange.start, grid.visibleRange.endExclusive, props.locale),
725
+ period: grid.period,
726
+ };
727
+ },
728
+ );
729
+
730
+ // Lay out each week row's spanning bars once per data change, not per render, so
731
+ // hover / popover / drag-create state changes don't relay out every row.
732
+ const weekLayouts = createMemo(() =>
733
+ eventsMode()
734
+ ? _grid().weeks.map((week) =>
735
+ layoutMonthWeek(
736
+ week.days.map((d) => d.date),
737
+ collectRowEvents(week, eventsByDay()),
738
+ ),
739
+ )
740
+ : [],
741
+ );
742
+
743
+ // Multi-week rows rove over the rendered, enabled days only (oldest first), so
744
+ // focus skips hidden and disabled days and never leaves the displayed weeks.
745
+ const focusableDays = createMemo(() =>
746
+ _grid().period
747
+ ? _grid()
748
+ .weeks.flatMap((week) => week.days)
749
+ .filter((day) => !day.isDisabled)
750
+ .map((day) => startOfDay(day.date))
751
+ .sort((a, b) => a.getTime() - b.getTime())
752
+ : null,
753
+ );
754
+ const focusableKeys = createMemo(() => {
755
+ const days = focusableDays();
756
+ return days ? new Set(days.map((d) => format(d, "yyyy-MM-dd"))) : null;
757
+ });
758
+
759
+ // Roving tabindex: only one day is in the tab order; arrow keys move focus
760
+ // within the month, so the grid is a single, sensible tab stop.
761
+ const initialFocus = createMemo((): Date | null => {
762
+ const days = focusableDays();
763
+ const keys = focusableKeys();
764
+ if (days && keys) {
765
+ // The selected day, then today, then the first enabled day; none when every
766
+ // displayed day is disabled.
767
+ const rendered = (d?: Date | null): d is Date => !!d && keys.has(format(d, "yyyy-MM-dd"));
768
+ const rangeStart = props.selectedRange?.start;
769
+ if (rendered(rangeStart)) return startOfDay(rangeStart);
770
+ const picked = props.selectedDates?.find(rendered);
771
+ if (picked) return startOfDay(picked);
772
+ const today = new Date();
773
+ if (rendered(today)) return startOfDay(today);
774
+ return days[0] ?? null;
775
+ }
776
+ const inMonth = (d?: Date | null) => !!d && isSameMonth(d, props.source.date);
777
+ if (inMonth(props.selectedRange?.start)) return startOfDay(props.selectedRange!.start);
778
+ const picked = props.selectedDates?.find(inMonth);
779
+ if (picked) return startOfDay(picked);
780
+ const today = new Date();
781
+ return isSameMonth(today, props.source.date)
782
+ ? startOfDay(today)
783
+ : startOfMonth(props.source.date);
784
+ });
785
+ const [focusedDate, setFocusedDate] = createSignal(untrack(() => initialFocus()));
786
+ const initialFocusRef = {
787
+ current: untrack(() => initialFocus()),
788
+ };
789
+ createEffect(
790
+ () => initialFocus(),
791
+ (value) => {
792
+ initialFocusRef.current = value;
793
+ },
794
+ );
795
+ // The displayed window: the month, or the first week and count of multi-week rows.
796
+ const windowKey = createMemo(() => {
797
+ const period = _grid().period;
798
+ return period
799
+ ? `${format(period.start, "yyyy-MM-dd")}+${numberOfWeeks()}:${_grid()
800
+ .weekdays.map((day) => day.date.getDay())
801
+ .join(",")}`
802
+ : format(props.source.date, "yyyy-MM");
803
+ });
804
+ let focusedWindow = untrack(windowKey);
805
+ createEffect(windowKey, (key) =>
806
+ untrack(() => {
807
+ if (key === focusedWindow) return;
808
+ focusedWindow = key;
809
+ setFocusedDate(initialFocusRef.current);
810
+ }),
811
+ );
812
+ const [hoveredKey, setHoveredKey] = createSignal<string | null>(null);
813
+ const gridRef: ElementRef<HTMLDivElement | null> = {
814
+ current: null,
815
+ };
816
+ const lastDayFocus: ElementRef<HTMLElement | null> = { current: null };
817
+ // A multi-week focus target that hidden days or new constraints removed falls
818
+ // back to the initial target, without moving DOM focus.
819
+ const focusKey = createMemo(() => {
820
+ const focused = focusedDate();
821
+ const stored = focused ? format(focused, "yyyy-MM-dd") : null;
822
+ const keys = focusableKeys();
823
+ if (!keys || (stored !== null && keys.has(stored))) return stored;
824
+ const initial = initialFocus();
825
+ return initial && format(initial, "yyyy-MM-dd");
826
+ });
827
+
828
+ createEffect(
829
+ () => ({ enabled: multiWeek(), key: focusKey() }),
830
+ ({ enabled, key }) => {
831
+ if (!enabled) return;
832
+ const active = gridRef.current?.ownerDocument.activeElement;
833
+ const removedDay =
834
+ active === gridRef.current?.ownerDocument.body &&
835
+ lastDayFocus.current !== null &&
836
+ !lastDayFocus.current.isConnected;
837
+ if (!removedDay && (!active?.hasAttribute("data-day") || !gridRef.current?.contains(active)))
838
+ return;
839
+ if (
840
+ active?.getAttribute("data-day") === key &&
841
+ active?.getAttribute("aria-disabled") !== "true"
842
+ )
843
+ return;
844
+ const next = key
845
+ ? gridRef.current?.querySelector<HTMLElement>(`[data-day="${key}"]`)
846
+ : gridRef.current;
847
+ next?.focus();
848
+ },
849
+ );
850
+
851
+ // Dragging (events mode): press a day and drag across others to sketch an
852
+ // all-day span, or press an event chip and drop it on another day. Both are
853
+ // released on a window pointerup, so letting go anywhere still commits.
854
+ const [drag, setDrag] = createSignal<MonthDrag<T> | null>(null);
855
+ const dragRef: ElementRef<MonthDrag<T> | null> = { current: null };
856
+ const applyDrag = (value: MonthDrag<T> | null) => {
857
+ dragRef.current = value;
858
+ setDrag(value);
859
+ };
860
+ const movedRef = {
861
+ current: false,
862
+ };
863
+ // Set when a drag commits, so the click the browser fires next is swallowed (it
864
+ // must not also open the day, or the event the drag landed on). A drag that ends
865
+ // over a different element than it began on gets its trailing click on their
866
+ // common ancestor instead, where no handler consumes the guard, so every press
867
+ // clears it first, keeping it scoped to the one interaction that set it.
868
+ const suppressClickRef = {
869
+ current: false,
870
+ };
871
+ const consumeSuppressedClick = () => {
872
+ if (!suppressClickRef.current) return false;
873
+ suppressClickRef.current = false;
874
+ return true;
875
+ };
876
+ // `disabled` and `draggable: false` lock an event outright; `startEditable`
877
+ // (per event, falling back to the grid default) allows or blocks a move.
878
+ const canMove = (event: CalendarEvent<T>) =>
879
+ props.onDragEvent != null &&
880
+ !event.disabled &&
881
+ event.draggable !== false &&
882
+ (event.startEditable ?? props.eventStartEditable);
883
+ // A fresh press starts a new interaction, so any guard left over from the
884
+ // previous one is stale.
885
+ const beginPress = (e: PointerEvent) => {
886
+ if (dragRef.current || e.isPrimary === false) return false;
887
+ suppressClickRef.current = false;
888
+ movedRef.current = false;
889
+ return true;
890
+ };
891
+ const beginCreate = (day: Date, pointerId: number) => {
892
+ if (!props.onCreateEvent && !props.onSelectDrag) return;
893
+ const t = startOfDay(day).getTime();
894
+ applyDrag({
895
+ kind: "create",
896
+ pointerId,
897
+ anchor: t,
898
+ hover: t,
899
+ windowKey: windowKey(),
900
+ });
901
+ };
902
+ const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number) => {
903
+ if (!canMove(event)) return;
904
+ const t = startOfDay(day).getTime();
905
+ applyDrag({
906
+ kind: "move",
907
+ pointerId,
908
+ event,
909
+ from: t,
910
+ to: t,
911
+ windowKey: windowKey(),
912
+ });
913
+ props.onDragStart?.(event);
914
+ };
915
+ const extendDrag = (day: Date, pointerId: number) => {
916
+ const current = dragRef.current;
917
+ if (!current || current.pointerId !== pointerId) return;
918
+ const t = startOfDay(day).getTime();
919
+ if (t === (current.kind === "create" ? current.hover : current.to)) return;
920
+ movedRef.current = true;
921
+ applyDrag(
922
+ current.kind === "create"
923
+ ? {
924
+ ...current,
925
+ hover: t,
926
+ }
927
+ : {
928
+ ...current,
929
+ to: t,
930
+ },
931
+ );
932
+ // A sweep reports its span live, so a selection can track the drag; a move
933
+ // has nothing to report until it is dropped.
934
+ if (current.kind === "create") {
935
+ const [lo, hi] = current.anchor <= t ? [current.anchor, t] : [t, current.anchor];
936
+ props.onSelectDrag?.(new Date(lo), new Date(hi));
937
+ }
938
+ };
939
+ let heldTouch: (() => void) | null = null;
940
+ let heldOrigin: { day: Date; event?: CalendarEvent<T> } | null = null;
941
+ const dayLookup = createMemo(
942
+ () =>
943
+ new Map(
944
+ _grid()
945
+ .weeks.flatMap((week) => week.days)
946
+ .map((day) => [day.id, day]),
947
+ ),
948
+ );
949
+ const pressRow = (
950
+ event: PointerEvent & { currentTarget: HTMLElement },
951
+ day: Date,
952
+ moving?: CalendarEvent<T>,
953
+ ) => {
954
+ if (event.button !== 0 || heldTouch || !beginPress(event)) return;
955
+ const start = () => {
956
+ if (moving) beginMove(moving, day, event.pointerId);
957
+ else beginCreate(day, event.pointerId);
958
+ };
959
+ if (!multiWeek() || !event.pointerType || event.pointerType === "mouse") {
960
+ start();
961
+ return;
962
+ }
963
+ heldOrigin = { day, event: moving };
964
+ heldTouch = holdDateDrag(
965
+ {
966
+ box: event.currentTarget,
967
+ pointerId: event.pointerId,
968
+ pointerType: event.pointerType,
969
+ clientX: event.clientX,
970
+ clientY: event.clientY,
971
+ },
972
+ start,
973
+ (x, y) => {
974
+ const element = gridRef.current?.ownerDocument
975
+ .elementFromPoint(x, y)
976
+ ?.closest<HTMLElement>("[data-day]");
977
+ if (!element || !gridRef.current?.contains(element)) return;
978
+ const day = dayLookup().get(element.dataset.day ?? "");
979
+ if (day && !day.isDisabled) extendDrag(day.date, event.pointerId);
980
+ },
981
+ () => {
982
+ applyDrag(null);
983
+ movedRef.current = false;
984
+ },
985
+ () => {
986
+ heldTouch = null;
987
+ heldOrigin = null;
988
+ },
989
+ );
990
+ };
991
+ createEffect(
992
+ () => windowKey(),
993
+ () => () => {
994
+ heldTouch?.();
995
+ },
996
+ );
997
+ createEffect(
998
+ () => ({
999
+ days: dayLookup(),
1000
+ events: props.events,
1001
+ canCreate: !!(props.onCreateEvent || props.onSelectDrag),
1002
+ canMove: !!props.onDragEvent,
1003
+ eventStartEditable: props.eventStartEditable,
1004
+ }),
1005
+ (state) => {
1006
+ const origin = heldOrigin;
1007
+ if (!origin) return;
1008
+ const current = dragRef.current;
1009
+ const destination = current
1010
+ ? new Date(current.kind === "create" ? current.hover : current.to)
1011
+ : origin.day;
1012
+ const enabled = (day: Date) => {
1013
+ const cell = state.days.get(format(day, "yyyy-MM-dd"));
1014
+ return cell != null && !cell.isDisabled;
1015
+ };
1016
+ if (
1017
+ !enabled(origin.day) ||
1018
+ !enabled(destination) ||
1019
+ (origin.event
1020
+ ? !state.canMove ||
1021
+ !state.events?.includes(origin.event) ||
1022
+ origin.event.disabled ||
1023
+ origin.event.draggable === false ||
1024
+ !(origin.event.startEditable ?? state.eventStartEditable)
1025
+ : !state.canCreate)
1026
+ ) {
1027
+ heldTouch?.();
1028
+ }
1029
+ },
1030
+ );
1031
+ const isDragging = createMemo(() => drag() !== null);
1032
+ // Whether any month drag is wired up at all, so the cells only take over touch
1033
+ // scrolling and pointer tracking when one of the handlers can actually fire.
1034
+ const dragWired = createMemo(
1035
+ () => props.onCreateEvent != null || props.onSelectDrag != null || props.onDragEvent != null,
1036
+ );
1037
+ createEffect(
1038
+ () => [isDragging(), props.onCreateEvent, props.onDragEvent, props.eventOverlap, props.events],
1039
+ () =>
1040
+ untrack(() => {
1041
+ if (!isDragging()) return;
1042
+ const finish = (e: PointerEvent) => {
1043
+ const current = dragRef.current;
1044
+ if (!current || current.pointerId !== e.pointerId) return;
1045
+ applyDrag(null);
1046
+ if (!movedRef.current) return;
1047
+ suppressClickRef.current = true;
1048
+ // Multi-week rows drop a drag whose window was replaced before release.
1049
+ if (multiWeek() && current.windowKey !== windowKey()) return;
1050
+ if (current.kind === "create") {
1051
+ const range = monthCreateRange(new Date(current.anchor), new Date(current.hover));
1052
+ props.onCreateEvent?.(range.start, range.end);
1053
+ return;
1054
+ }
1055
+ const next = monthDropBounds(current.event, new Date(current.from), new Date(current.to));
1056
+ if (!next) return;
1057
+ // Reject a drop that would land the event on top of another when
1058
+ // `eventOverlap` is off, before the consumer's handler ever sees it.
1059
+ if (
1060
+ props.eventOverlap === false &&
1061
+ overlapsOtherEvents(props.events ?? [], current.event, next.start, next.end)
1062
+ ) {
1063
+ return;
1064
+ }
1065
+ props.onDragEvent?.(current.event, next.start, next.end);
1066
+ };
1067
+ const cancel = (e: PointerEvent) => {
1068
+ if (dragRef.current?.pointerId !== e.pointerId) return;
1069
+ applyDrag(null);
1070
+ movedRef.current = false;
1071
+ suppressClickRef.current = true;
1072
+ };
1073
+ window.addEventListener("pointerup", finish);
1074
+ window.addEventListener("pointercancel", cancel);
1075
+ return () => {
1076
+ window.removeEventListener("pointerup", finish);
1077
+ window.removeEventListener("pointercancel", cancel);
1078
+ };
1079
+ }),
1080
+ );
1081
+ // Replacing the multi-week window cancels a drag and closes the overflow
1082
+ // popover, so neither acts on days that are no longer shown.
1083
+ let transientWindow = untrack(windowKey);
1084
+ createEffect(windowKey, (key) =>
1085
+ untrack(() => {
1086
+ if (key === transientWindow) return;
1087
+ transientWindow = key;
1088
+ if (!multiWeek()) return;
1089
+ applyDrag(null);
1090
+ setMoreOpenFor(null);
1091
+ }),
1092
+ );
1093
+ // Multi-week roving: the neighbouring focusable day, the same weekday in the
1094
+ // nearest week that has it enabled, or the first/last focusable day.
1095
+ const nextMultiWeekFocus = (key: string): Date | null => {
1096
+ const days = focusableDays();
1097
+ const keys = focusableKeys();
1098
+ const period = _grid().period;
1099
+ if (!days || !keys || !period) return null;
1100
+ const index = days.findIndex((d) => format(d, "yyyy-MM-dd") === focusKey());
1101
+ if (index === -1) return null;
1102
+ if (key === "ArrowLeft") return days[index - 1] ?? null;
1103
+ if (key === "ArrowRight") return days[index + 1] ?? null;
1104
+ if (key === "Home") return days[0];
1105
+ if (key === "End") return days[days.length - 1];
1106
+ const step = key === "ArrowUp" ? -7 : 7;
1107
+ for (
1108
+ let cursor = addDays(days[index], step);
1109
+ cursor >= period.start && cursor < period.endExclusive;
1110
+ cursor = addDays(cursor, step)
1111
+ ) {
1112
+ if (keys.has(format(cursor, "yyyy-MM-dd"))) return cursor;
1113
+ }
1114
+ return null;
1115
+ };
1116
+ const onKeyDown = (e: DomKeyboardEvent<HTMLDivElement>) => {
1117
+ if (multiWeek()) {
1118
+ if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"].includes(e.key)) {
1119
+ return;
1120
+ }
1121
+ e.preventDefault();
1122
+ const target = nextMultiWeekFocus(e.key);
1123
+ if (!target) return;
1124
+ setFocusedDate(target);
1125
+ const targetKey = format(target, "yyyy-MM-dd");
1126
+ gridRef.current?.querySelector<HTMLElement>(`[data-day="${targetKey}"]`)?.focus();
1127
+ return;
1128
+ }
1129
+ const focused = focusedDate();
1130
+ if (!focused) return;
1131
+ let next: Date | null = null;
1132
+ if (e.key === "ArrowLeft") next = addDays(focused, -1);
1133
+ else if (e.key === "ArrowRight") next = addDays(focused, 1);
1134
+ else if (e.key === "ArrowUp") next = addDays(focused, -7);
1135
+ else if (e.key === "ArrowDown") next = addDays(focused, 7);
1136
+ else if (e.key === "Home") next = startOfMonth(props.source.date);
1137
+ else if (e.key === "End") next = endOfMonth(props.source.date);
1138
+ else return;
1139
+ e.preventDefault();
1140
+ if (!isSameMonth(next, props.source.date)) return;
1141
+ setFocusedDate(next);
1142
+ const key = format(next, "yyyy-MM-dd");
1143
+ gridRef.current?.querySelector<HTMLElement>(`[data-day="${key}"]`)?.focus();
1144
+ };
1145
+ return (
1146
+ <div
1147
+ class={props.className}
1148
+ style={css({
1149
+ fontFamily: theme().fontFamily,
1150
+ color: theme().text,
1151
+ // Multi-week rows keep their full height; when the view is given less
1152
+ // room, the grid scrolls under the title and weekday header.
1153
+ ...(multiWeek() ? { display: "flex", flexDirection: "column", minHeight: 0 } : null),
1154
+ ...props.style,
1155
+ })}
1156
+ >
1157
+ {props.showTitle ? (
1158
+ <div
1159
+ {...slot("title", {
1160
+ themed: {
1161
+ fontSize: 17,
1162
+ fontWeight: 700,
1163
+ padding: "10px 14px 6px",
1164
+ },
1165
+ })}
1166
+ >
1167
+ {_grid().title}
1168
+ </div>
1169
+ ) : null}
1170
+ {props.showWeekdays ? (
1171
+ <div
1172
+ {...slot("weekdays", {
1173
+ base: {
1174
+ display: "grid",
1175
+ gridTemplateColumns: `repeat(${_grid().weekdays.length}, minmax(0, 1fr))`,
1176
+ },
1177
+ themed: {
1178
+ borderBottom: `1px solid ${theme().gridLine}`,
1179
+ padding: "6px 0",
1180
+ },
1181
+ })}
1182
+ >
1183
+ {
1184
+ <For each={_grid().weekdays} keyed={false}>
1185
+ {(wd) => (
1186
+ <span
1187
+ {...slot("weekday", {
1188
+ themed: {
1189
+ textAlign: "center",
1190
+ fontSize: 12,
1191
+ fontWeight: 600,
1192
+ color: theme().textMuted,
1193
+ },
1194
+ })}
1195
+ >
1196
+ {wd().label}
1197
+ </span>
1198
+ )}
1199
+ </For>
1200
+ }
1201
+ </div>
1202
+ ) : null}
1203
+ <div
1204
+ ref={(el) => (gridRef.current = el)}
1205
+ role="grid"
1206
+ tabindex={multiWeek() ? -1 : undefined}
1207
+ aria-label={_grid().title}
1208
+ // Arrow-key roving applies whenever the day cells are a tab stop: the
1209
+ // picker always, events mode only when keyboardDayNavigation is set.
1210
+ onKeyDown={dayRoving() ? onKeyDown : undefined}
1211
+ {...slot(
1212
+ "grid",
1213
+ multiWeek() ? { base: { flex: "1 1 auto", minHeight: 0, overflowY: "auto" } } : undefined,
1214
+ )}
1215
+ >
1216
+ {
1217
+ <For each={_grid().weeks} keyed={false}>
1218
+ {(week, weekIndex) => {
1219
+ // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
1220
+ // event is one bar across its columns, stacked into lanes; each bar renders
1221
+ // inside its start-column cell (valid grid content that reads with that day)
1222
+ // and overflows right across the days it spans. The cells reserve the lane
1223
+ // rows so "+more" sits below the bars.
1224
+ const rowLayout = createMemo(() => weekLayouts()[weekIndex] ?? EMPTY_LAYOUT);
1225
+ // When lanes overflow, keep the last row for "+more" but always show at
1226
+ // least one bar, so a day never collapses to only the overflow row.
1227
+ const overflowing = createMemo(
1228
+ () => rowLayout().laneCount > props.maxVisibleEventCount,
1229
+ );
1230
+ const visibleLanes = createMemo(() =>
1231
+ overflowing() ? Math.max(props.maxVisibleEventCount - 1, 1) : rowLayout().laneCount,
1232
+ );
1233
+ // With adjacent months hidden, clamp bars to the current-month columns so
1234
+ // none draw over the blank leading/trailing cells.
1235
+ const cols = createMemo(() => week().days.length);
1236
+ const columns = createMemo(() => {
1237
+ let first = 0;
1238
+ let last = cols() - 1;
1239
+ if (eventsMode() && !showAdjacentMonths()) {
1240
+ const start = week().days.findIndex((d) => !isOutsidePeriod(d));
1241
+ const end = [...week().days].reverse().findIndex((d) => !isOutsidePeriod(d));
1242
+ if (start !== -1) {
1243
+ first = start;
1244
+ last = cols() - 1 - end;
1245
+ }
1246
+ }
1247
+ return {
1248
+ first,
1249
+ last,
1250
+ };
1251
+ });
1252
+ return (
1253
+ <>
1254
+ {(() => {
1255
+ const barSegs = createMemo(() =>
1256
+ rowLayout()
1257
+ .segments.filter((s) => s.lane < visibleLanes())
1258
+ .map((s) => {
1259
+ const startCol = Math.max(s.startCol, columns().first);
1260
+ const endCol = Math.min(s.endCol, columns().last);
1261
+ return {
1262
+ seg: s,
1263
+ startCol,
1264
+ endCol,
1265
+ continuesBefore: s.continuesBefore || startCol > s.startCol,
1266
+ continuesAfter: s.continuesAfter || endCol < s.endCol,
1267
+ };
1268
+ })
1269
+ .filter((b) => b.startCol <= b.endCol),
1270
+ );
1271
+ const barChipButton = createMemo(() => slot("chipButton", chipButtonDefault));
1272
+ const barChip = createMemo(() =>
1273
+ slot("chip", chipDefault(theme(), props.chipHeight)),
1274
+ );
1275
+ return (
1276
+ <div
1277
+ role="row"
1278
+ {...slot("week", {
1279
+ base: {
1280
+ display: "grid",
1281
+ gridTemplateColumns: `repeat(${cols()}, minmax(0, 1fr))`,
1282
+ },
1283
+ })}
1284
+ >
1285
+ {
1286
+ <For each={week().days} keyed={false}>
1287
+ {(day, dayCol) => {
1288
+ const hidden = createMemo(
1289
+ () => !showAdjacentMonths() && isOutsidePeriod(day()),
1290
+ );
1291
+ const cellHeight = createMemo(() =>
1292
+ eventsMode() ? eventRowHeight() : theme().cellHeight,
1293
+ );
1294
+ return (
1295
+ <>
1296
+ {(() => {
1297
+ if (hidden()) {
1298
+ return (
1299
+ <div
1300
+ role="gridcell"
1301
+ aria-hidden="true"
1302
+ style={css({
1303
+ height: cellHeight(),
1304
+ })}
1305
+ />
1306
+ );
1307
+ }
1308
+ const band = createMemo(() =>
1309
+ rangeBandDefault(
1310
+ day(),
1311
+ theme(),
1312
+ props.fillCellOnSelection,
1313
+ eventsMode(),
1314
+ ),
1315
+ );
1316
+ const dateLabel = createMemo(() =>
1317
+ format(
1318
+ day().date,
1319
+ "EEEE, d MMMM yyyy",
1320
+ props.locale
1321
+ ? {
1322
+ locale: props.locale,
1323
+ }
1324
+ : undefined,
1325
+ ),
1326
+ );
1327
+ const label = createMemo(() =>
1328
+ dayAccessibilityLabel({
1329
+ dateLabel: dateLabel(),
1330
+ isToday: day().isToday,
1331
+ labels: labels(),
1332
+ }),
1333
+ );
1334
+ const dayTime = createMemo(() =>
1335
+ startOfDay(day().date).getTime(),
1336
+ );
1337
+ const inCreate = createMemo(() => {
1338
+ const currentDrag = drag();
1339
+ return (
1340
+ currentDrag?.kind === "create" &&
1341
+ dayTime() >=
1342
+ Math.min(currentDrag.anchor, currentDrag.hover) &&
1343
+ dayTime() <= Math.max(currentDrag.anchor, currentDrag.hover)
1344
+ );
1345
+ });
1346
+ // The day an event is about to land on (not the one it came from).
1347
+ const isDropTarget = createMemo(() => {
1348
+ const currentDrag = drag();
1349
+ return (
1350
+ currentDrag?.kind === "move" &&
1351
+ dayTime() === currentDrag.to &&
1352
+ currentDrag.to !== currentDrag.from
1353
+ );
1354
+ });
1355
+ // Present/absent data-* attributes so consumers can style day state
1356
+ // with CSS/Tailwind variants (e.g. `data-[today]:bg-blue-500`).
1357
+ const dayData = createMemo(() =>
1358
+ dataState({
1359
+ "data-today": day().isToday,
1360
+ "data-selected": day().isSelected,
1361
+ "data-range": day().isInRange,
1362
+ "data-weekend": day().isWeekend,
1363
+ "data-outside": isOutsidePeriod(day()),
1364
+ "data-disabled": day().isDisabled,
1365
+ "data-creating": inCreate(),
1366
+ "data-drop": isDropTarget(),
1367
+ }),
1368
+ );
1369
+ if (eventsMode()) {
1370
+ const dayEvents = createMemo(
1371
+ () =>
1372
+ eventsByDay().get(startOfDay(day().date).toISOString()) ??
1373
+ [],
1374
+ );
1375
+ // Events past the visible lanes (this day's segments in a lane the
1376
+ // row doesn't show) collapse into "+N more"; the popover lists the
1377
+ // whole day.
1378
+ const hiddenEvents = createMemo(() =>
1379
+ rowLayout()
1380
+ .segments.filter(
1381
+ (s) =>
1382
+ s.startCol <= dayCol &&
1383
+ s.endCol >= dayCol &&
1384
+ s.lane >= visibleLanes(),
1385
+ )
1386
+ .map((s) => s.event),
1387
+ );
1388
+ const dayLabel = createMemo(() =>
1389
+ format(
1390
+ day().date,
1391
+ "d MMMM",
1392
+ props.locale
1393
+ ? {
1394
+ locale: props.locale,
1395
+ }
1396
+ : undefined,
1397
+ ),
1398
+ );
1399
+ const dayCellProps = createMemo(() =>
1400
+ slot(
1401
+ "day",
1402
+ eventCellDefault(
1403
+ day(),
1404
+ theme(),
1405
+ cellHeight(),
1406
+ props.highlightWeekends,
1407
+ inCreate() || isDropTarget(),
1408
+ props.chipGap,
1409
+ ),
1410
+ ),
1411
+ );
1412
+ return (
1413
+ // Events mode: by default the cell is not a tab stop, so keyboard
1414
+ // focus moves through the event chips (real buttons) only, not
1415
+ // every empty day. With keyboardDayNavigation the cell joins the
1416
+ // roving tab order (arrow keys + Enter to open the day). A pointer
1417
+ // click always drills into the day.
1418
+ <div
1419
+ role="gridcell"
1420
+ data-day={day().id}
1421
+ onFocusIn={(event) => {
1422
+ if (event.target === event.currentTarget) {
1423
+ lastDayFocus.current = event.currentTarget;
1424
+ setFocusedDate(day().date);
1425
+ }
1426
+ }}
1427
+ onFocusOut={(event) => {
1428
+ if (event.target !== event.currentTarget) return;
1429
+ const previous = event.currentTarget;
1430
+ if (event.relatedTarget) lastDayFocus.current = null;
1431
+ else {
1432
+ // Removal blurs before detaching the node. Distinguish
1433
+ // it from a manual blur after the DOM update finishes.
1434
+ queueMicrotask(() => {
1435
+ if (
1436
+ lastDayFocus.current === previous &&
1437
+ previous.isConnected
1438
+ )
1439
+ lastDayFocus.current = null;
1440
+ });
1441
+ }
1442
+ }}
1443
+ {...dayData()}
1444
+ tabindex={
1445
+ props.keyboardDayNavigation
1446
+ ? day().id === focusKey()
1447
+ ? 0
1448
+ : -1
1449
+ : undefined
1450
+ }
1451
+ aria-disabled={
1452
+ (day().isDisabled || undefined) == null
1453
+ ? undefined
1454
+ : day().isDisabled || undefined
1455
+ ? "true"
1456
+ : "false"
1457
+ }
1458
+ aria-label={dayAccessibilityLabel({
1459
+ dateLabel: dateLabel(),
1460
+ isToday: day().isToday,
1461
+ isSelected: day().isSelected,
1462
+ eventCount: dayEvents().length,
1463
+ labels: labels(),
1464
+ })}
1465
+ {...dayCellProps()}
1466
+ // Dragging disables touch scroll on the cell so a swipe
1467
+ // sketches a span (or carries an event) instead of scrolling
1468
+ // the grid, and stops the sweep from text-selecting the day
1469
+ // numbers and chip titles it passes over.
1470
+ style={css(
1471
+ dragWired()
1472
+ ? {
1473
+ ...dayCellProps().style,
1474
+ touchAction: multiWeek() ? "pan-y" : "none",
1475
+ userSelect: "none",
1476
+ }
1477
+ : dayCellProps().style,
1478
+ )}
1479
+ onPointerDown={
1480
+ dragWired() && !day().isDisabled
1481
+ ? (e) => {
1482
+ const date = day().date;
1483
+ pressRow(e, date);
1484
+ }
1485
+ : undefined
1486
+ }
1487
+ // A disabled day is out of every selection, drag included, so
1488
+ // a sweep never extends onto it and no drop lands there.
1489
+ onPointerEnter={
1490
+ dragWired() && !day().isDisabled
1491
+ ? (e) => extendDrag(day().date, e.pointerId)
1492
+ : undefined
1493
+ }
1494
+ onClick={
1495
+ day().isDisabled
1496
+ ? undefined
1497
+ : () => {
1498
+ if (consumeSuppressedClick()) return;
1499
+ props.onPressDay?.(day().date);
1500
+ props.onPressCell?.(startOfDay(day().date));
1501
+ }
1502
+ }
1503
+ onKeyDown={
1504
+ props.keyboardDayNavigation && !day().isDisabled
1505
+ ? (e) => {
1506
+ // Let Enter/Space on a focused chip activate the chip.
1507
+ if (e.target !== e.currentTarget) return;
1508
+ if (e.key === "Enter" || e.key === " ") {
1509
+ e.preventDefault();
1510
+ props.onPressDay?.(day().date);
1511
+ props.onPressCell?.(startOfDay(day().date));
1512
+ }
1513
+ }
1514
+ : undefined
1515
+ }
1516
+ >
1517
+ {
1518
+ <Show when={band()}>
1519
+ {(band) => (
1520
+ <span
1521
+ data-band
1522
+ aria-hidden="true"
1523
+ {...slot("rangeBand", band())}
1524
+ />
1525
+ )}
1526
+ </Show>
1527
+ }
1528
+ <span
1529
+ {...dayData()}
1530
+ {...slot(
1531
+ "dayBadge",
1532
+ compactBadgeDefault(day(), theme()),
1533
+ )}
1534
+ >
1535
+ {day().label}
1536
+ </span>
1537
+ {/* Spanning bars that start in this column: absolutely placed,
1538
+ overflowing right across the days they span. Rendered here
1539
+ (not a row overlay) so each bar is valid content of its
1540
+ start day's gridcell and reads with that day. Made
1541
+ non-interactive mid drag so a sweep (or a move) reaches the
1542
+ cells beneath. */}
1543
+ {
1544
+ <For
1545
+ each={barSegs().filter((b) => b.startCol === dayCol)}
1546
+ keyed={false}
1547
+ >
1548
+ {(b) => {
1549
+ const span = createMemo(
1550
+ () => b().endCol - b().startCol + 1,
1551
+ );
1552
+ const isDragged = createMemo(() => {
1553
+ const currentDrag = drag();
1554
+ return (
1555
+ currentDrag?.kind === "move" &&
1556
+ currentDrag.event === b().seg.event
1557
+ );
1558
+ });
1559
+ return (
1560
+ <button
1561
+ type="button"
1562
+ onPointerDown={
1563
+ canMove(b().seg.event)
1564
+ ? (e) => {
1565
+ e.stopPropagation();
1566
+ const event = b().seg.event;
1567
+ const date = day().date;
1568
+ pressRow(e, date, event);
1569
+ }
1570
+ : undefined
1571
+ }
1572
+ onClick={(e) => {
1573
+ e.stopPropagation();
1574
+ if (consumeSuppressedClick()) return;
1575
+ props.onPressEvent?.(b().seg.event);
1576
+ }}
1577
+ {...barChipButton()}
1578
+ title={b().seg.event.title}
1579
+ aria-label={
1580
+ props.eventAccessibilityLabel
1581
+ ? props.eventAccessibilityLabel(
1582
+ b().seg.event,
1583
+ {
1584
+ mode: viewMode(),
1585
+ isAllDay: isAllDayEvent(
1586
+ b().seg.event,
1587
+ ),
1588
+ ampm: false,
1589
+ },
1590
+ )
1591
+ : `${b().seg.event.title}, ${dayLabel()}`
1592
+ }
1593
+ style={css({
1594
+ ...barChipButton().style,
1595
+ position: "absolute",
1596
+ left: 2,
1597
+ width: `calc(${span() * 100}% - 4px)`,
1598
+ top:
1599
+ CELL_PAD +
1600
+ DATE_ROW +
1601
+ props.chipGap +
1602
+ b().seg.lane *
1603
+ (props.chipHeight + props.chipGap),
1604
+ height: props.chipHeight,
1605
+ pointerEvents: isDragging() ? "none" : "auto",
1606
+ // Fade the bar being carried, so the tinted drop
1607
+ // target reads as where it is going.
1608
+ opacity: isDragged()
1609
+ ? DRAGGED_CHIP_OPACITY
1610
+ : undefined,
1611
+ cursor: canMove(b().seg.event)
1612
+ ? "grab"
1613
+ : undefined,
1614
+ touchAction: dragWired()
1615
+ ? multiWeek()
1616
+ ? "pan-y"
1617
+ : "none"
1618
+ : undefined,
1619
+ zIndex: 2,
1620
+ })}
1621
+ >
1622
+ {Chip() ? (
1623
+ <Dynamic
1624
+ component={Chip()}
1625
+ mode={viewMode()}
1626
+ event={b().seg.event}
1627
+ onPress={() =>
1628
+ props.onPressEvent?.(b().seg.event)
1629
+ }
1630
+ />
1631
+ ) : (
1632
+ <span
1633
+ {...barChip()}
1634
+ style={css({
1635
+ ...barChip().style,
1636
+ ...(b().continuesBefore
1637
+ ? {
1638
+ borderTopLeftRadius: 0,
1639
+ borderBottomLeftRadius: 0,
1640
+ }
1641
+ : null),
1642
+ ...(b().continuesAfter
1643
+ ? {
1644
+ borderTopRightRadius: 0,
1645
+ borderBottomRightRadius: 0,
1646
+ }
1647
+ : null),
1648
+ })}
1649
+ >
1650
+ {b().seg.event.title}
1651
+ </span>
1652
+ )}
1653
+ </button>
1654
+ );
1655
+ }}
1656
+ </For>
1657
+ }
1658
+ <div
1659
+ {...slot("events", {
1660
+ base: {
1661
+ display: "flex",
1662
+ flexDirection: "column",
1663
+ gap: props.chipGap,
1664
+ },
1665
+ })}
1666
+ >
1667
+ {/* Reserve one row per visible lane so the absolute bars have
1668
+ space and "+more" sits below them. */}
1669
+ {Array.from(
1670
+ {
1671
+ length: visibleLanes(),
1672
+ },
1673
+ () => (
1674
+ <div
1675
+ aria-hidden="true"
1676
+ style={css({
1677
+ height: props.chipHeight,
1678
+ })}
1679
+ />
1680
+ ),
1681
+ )}
1682
+ {hiddenEvents().length > 0 ? (
1683
+ <button
1684
+ type="button"
1685
+ // In built-in-popover mode, keep the document
1686
+ // pointerdown dismiss from firing before this click's
1687
+ // toggle, so pressing the button again closes it.
1688
+ onPointerDown={
1689
+ props.onPressMore
1690
+ ? undefined
1691
+ : (e) => e.stopPropagation()
1692
+ }
1693
+ onClick={(e) => {
1694
+ e.stopPropagation();
1695
+ if (props.onPressMore)
1696
+ props.onPressMore(hiddenEvents(), day().date);
1697
+ else {
1698
+ moreTriggerRef.current = e.currentTarget;
1699
+ setMoreOpenFor((open) =>
1700
+ open === day().id ? null : day().id,
1701
+ );
1702
+ }
1703
+ }}
1704
+ {...slot(
1705
+ "more",
1706
+ moreButtonDefault(
1707
+ theme(),
1708
+ props.chipHeight,
1709
+ multiWeek(),
1710
+ ),
1711
+ )}
1712
+ aria-label={`${labels().moreEvents(hiddenEvents().length)}, ${dayLabel()}`}
1713
+ aria-expanded={
1714
+ (props.onPressMore
1715
+ ? undefined
1716
+ : moreOpenFor() === day().id) == null
1717
+ ? undefined
1718
+ : (
1719
+ props.onPressMore
1720
+ ? undefined
1721
+ : moreOpenFor() === day().id
1722
+ )
1723
+ ? "true"
1724
+ : "false"
1725
+ }
1726
+ >
1727
+ {props.moreLabel.replace(
1728
+ "{moreCount}",
1729
+ String(hiddenEvents().length),
1730
+ )}
1731
+ </button>
1732
+ ) : null}
1733
+ {moreOpenFor() === day().id ? (
1734
+ <div
1735
+ ref={(el) => (morePopoverRef.current = el)}
1736
+ // A non-modal dialog: Tab stays inside and Escape closes,
1737
+ // but the page behind is not inert (outside clicks work),
1738
+ // so no aria-modal claim.
1739
+ role="dialog"
1740
+ aria-label={dayLabel()}
1741
+ onPointerDown={(e) => e.stopPropagation()}
1742
+ // Contain Tab inside the dialog; Escape (handled on the
1743
+ // document) closes it and restores focus to the trigger.
1744
+ onKeyDown={(e) => {
1745
+ if (e.key !== "Tab") return;
1746
+ const buttons =
1747
+ morePopoverRef.current?.querySelectorAll<HTMLElement>(
1748
+ "button",
1749
+ );
1750
+ if (!buttons?.length) return;
1751
+ const first = buttons[0];
1752
+ const last = buttons[buttons.length - 1];
1753
+ if (
1754
+ e.shiftKey &&
1755
+ document.activeElement === first
1756
+ ) {
1757
+ e.preventDefault();
1758
+ last.focus();
1759
+ } else if (
1760
+ !e.shiftKey &&
1761
+ document.activeElement === last
1762
+ ) {
1763
+ e.preventDefault();
1764
+ first.focus();
1765
+ }
1766
+ }}
1767
+ {...slot("morePopover", {
1768
+ base: {
1769
+ position: "absolute",
1770
+ top: 2,
1771
+ left: 2,
1772
+ right: 2,
1773
+ zIndex: 10,
1774
+ display: "flex",
1775
+ flexDirection: "column",
1776
+ gap: 2,
1777
+ maxHeight: 240,
1778
+ overflowY: "auto",
1779
+ },
1780
+ themed: {
1781
+ background: theme().surface,
1782
+ border: `1px solid ${theme().gridLine}`,
1783
+ borderRadius: 8,
1784
+ padding: 6,
1785
+ boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
1786
+ },
1787
+ })}
1788
+ >
1789
+ <div
1790
+ style={css({
1791
+ fontSize: 11,
1792
+ fontWeight: 600,
1793
+ color: theme().textMuted,
1794
+ })}
1795
+ >
1796
+ {dayLabel()}
1797
+ </div>
1798
+ {
1799
+ <For each={dayEvents()} keyed={false}>
1800
+ {(event) => {
1801
+ return (
1802
+ <button
1803
+ type="button"
1804
+ onClick={() => {
1805
+ setMoreOpenFor(null);
1806
+ props.onPressEvent?.(event());
1807
+ }}
1808
+ style={css({
1809
+ display: "block",
1810
+ width: "100%",
1811
+ border: "none",
1812
+ background: "transparent",
1813
+ padding: 0,
1814
+ font: "inherit",
1815
+ textAlign: "left",
1816
+ cursor: "pointer",
1817
+ })}
1818
+ >
1819
+ {Chip() ? (
1820
+ <Dynamic
1821
+ component={Chip()}
1822
+ mode={viewMode()}
1823
+ event={event()}
1824
+ onPress={() =>
1825
+ props.onPressEvent?.(event())
1826
+ }
1827
+ />
1828
+ ) : (
1829
+ <span
1830
+ {...slot(
1831
+ "chip",
1832
+ chipDefault(
1833
+ theme(),
1834
+ props.chipHeight,
1835
+ ),
1836
+ )}
1837
+ >
1838
+ {event().title}
1839
+ </span>
1840
+ )}
1841
+ </button>
1842
+ );
1843
+ }}
1844
+ </For>
1845
+ }
1846
+ </div>
1847
+ ) : null}
1848
+ </div>
1849
+ </div>
1850
+ );
1851
+ }
1852
+ return (
1853
+ <button
1854
+ type="button"
1855
+ role="gridcell"
1856
+ data-day={day().id}
1857
+ onFocusIn={(event) => {
1858
+ if (event.target === event.currentTarget) {
1859
+ lastDayFocus.current = event.currentTarget;
1860
+ setFocusedDate(day().date);
1861
+ }
1862
+ }}
1863
+ {...dayData()}
1864
+ tabindex={day().id === focusKey() ? 0 : -1}
1865
+ aria-disabled={
1866
+ (day().isDisabled || undefined) == null
1867
+ ? undefined
1868
+ : day().isDisabled || undefined
1869
+ ? "true"
1870
+ : "false"
1871
+ }
1872
+ aria-label={label()}
1873
+ aria-selected={
1874
+ day().isSelected || day().isInRange ? "true" : "false"
1875
+ }
1876
+ {...slot(
1877
+ "day",
1878
+ dayCellDefault(day(), theme(), props.highlightWeekends),
1879
+ )}
1880
+ onClick={
1881
+ day().isDisabled
1882
+ ? undefined
1883
+ : () => {
1884
+ props.onPressDay?.(day().date);
1885
+ props.onPressCell?.(startOfDay(day().date));
1886
+ }
1887
+ }
1888
+ onMouseEnter={
1889
+ day().isDisabled
1890
+ ? undefined
1891
+ : () => setHoveredKey(day().id)
1892
+ }
1893
+ onMouseLeave={() =>
1894
+ setHoveredKey((k) => (k === day().id ? null : k))
1895
+ }
1896
+ >
1897
+ {
1898
+ <Show when={band()}>
1899
+ {(band) => (
1900
+ <span
1901
+ data-band
1902
+ aria-hidden="true"
1903
+ {...slot("rangeBand", band())}
1904
+ />
1905
+ )}
1906
+ </Show>
1907
+ }
1908
+ <span
1909
+ {...dayData()}
1910
+ {...slot(
1911
+ "dayBadge",
1912
+ badgeDefault(day(), theme(), hoveredKey() === day().id),
1913
+ )}
1914
+ >
1915
+ {day().label}
1916
+ </span>
1917
+ </button>
1918
+ );
1919
+ })()}
1920
+ </>
1921
+ );
1922
+ }}
1923
+ </For>
1924
+ }
1925
+ </div>
1926
+ );
1927
+ })()}
1928
+ </>
1929
+ );
1930
+ }}
1931
+ </For>
1932
+ }
1933
+ </div>
1934
+ </div>
1935
+ );
1936
+ }