@super-calendar/dom 2.6.0 → 2.8.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.
- package/dist/index.d.mts +111 -16
- package/dist/index.d.ts +111 -16
- package/dist/index.js +811 -250
- package/dist/index.mjs +783 -252
- package/package.json +2 -2
- package/src/Agenda.tsx +5 -2
- package/src/Calendar.tsx +42 -0
- package/src/MonthList.tsx +3 -1
- package/src/MonthView.tsx +441 -174
- package/src/ResourceTimeline.tsx +286 -24
- package/src/TimeGrid.tsx +427 -87
- package/src/YearView.tsx +14 -4
- package/src/index.ts +8 -0
package/src/MonthView.tsx
CHANGED
|
@@ -27,9 +27,11 @@ import {
|
|
|
27
27
|
type DateSelectionConstraints,
|
|
28
28
|
type EventAccessibilityLabeler,
|
|
29
29
|
groupEventsByDay,
|
|
30
|
+
isBackgroundEvent,
|
|
30
31
|
isAllDayEvent,
|
|
32
|
+
layoutMonthWeek,
|
|
31
33
|
type MonthGridDay,
|
|
32
|
-
|
|
34
|
+
type MonthGridWeek,
|
|
33
35
|
rangeBandKind,
|
|
34
36
|
type WeekdayFormat,
|
|
35
37
|
type WeekStartsOn,
|
|
@@ -53,7 +55,11 @@ export type MonthViewSlot =
|
|
|
53
55
|
| "events"
|
|
54
56
|
| "chipButton"
|
|
55
57
|
| "chip"
|
|
56
|
-
| "more"
|
|
58
|
+
| "more"
|
|
59
|
+
| "morePopover";
|
|
60
|
+
|
|
61
|
+
// Stable empty layout for rows with no events (avoids a fresh object per render).
|
|
62
|
+
const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
|
|
57
63
|
|
|
58
64
|
// Chip metrics for the events layout (when `events` is provided).
|
|
59
65
|
const DATE_ROW = 24;
|
|
@@ -79,6 +85,8 @@ export interface MonthViewProps<T = unknown>
|
|
|
79
85
|
date: Date;
|
|
80
86
|
/** First day of the week. Sunday = 0 (default) … Saturday = 6. */
|
|
81
87
|
weekStartsOn?: WeekStartsOn;
|
|
88
|
+
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
89
|
+
hiddenDays?: number[];
|
|
82
90
|
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
83
91
|
weekdayFormat?: WeekdayFormat;
|
|
84
92
|
/**
|
|
@@ -95,7 +103,12 @@ export interface MonthViewProps<T = unknown>
|
|
|
95
103
|
* announce. Defaults to the event title and day (e.g. "Standup, 15 July").
|
|
96
104
|
*/
|
|
97
105
|
eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
|
|
98
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Max event lanes (stacked rows) shown per week before the rest of a day's
|
|
108
|
+
* events collapse into a "+N more" row (default 3). Because multi-day events draw
|
|
109
|
+
* as one bar spanning a lane across the week, this caps lanes per row, not chips
|
|
110
|
+
* per day, so a long bar can push a lightly-booked day's own events into "+N more".
|
|
111
|
+
*/
|
|
99
112
|
maxVisibleEventCount?: number;
|
|
100
113
|
/** Template for the overflow row; `{moreCount}` is replaced (default "{moreCount} More"). */
|
|
101
114
|
moreLabel?: string;
|
|
@@ -356,6 +369,28 @@ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
|
356
369
|
eventsByDay?: ReadonlyMap<string, CalendarEvent<T>[]>;
|
|
357
370
|
}
|
|
358
371
|
|
|
372
|
+
// The distinct events touching a week row, in the per-day index's sorted order.
|
|
373
|
+
// A multi-day event lives in each covered day's bucket, so dedupe by reference;
|
|
374
|
+
// this scans only the row's days, not every event in the month.
|
|
375
|
+
function collectRowEvents<T>(
|
|
376
|
+
week: MonthGridWeek,
|
|
377
|
+
eventsByDay: ReadonlyMap<string, CalendarEvent<T>[]>,
|
|
378
|
+
): CalendarEvent<T>[] {
|
|
379
|
+
const seen = new Set<CalendarEvent<T>>();
|
|
380
|
+
const out: CalendarEvent<T>[] = [];
|
|
381
|
+
for (const day of week.days) {
|
|
382
|
+
const list = eventsByDay.get(startOfDay(day.date).toISOString());
|
|
383
|
+
if (!list) continue;
|
|
384
|
+
for (const event of list) {
|
|
385
|
+
if (!seen.has(event)) {
|
|
386
|
+
seen.add(event);
|
|
387
|
+
out.push(event);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
|
|
359
394
|
/**
|
|
360
395
|
* A single static month grid, rendered with plain DOM elements.
|
|
361
396
|
*
|
|
@@ -367,6 +402,7 @@ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
|
|
|
367
402
|
export function MonthView<T = unknown>({
|
|
368
403
|
date,
|
|
369
404
|
weekStartsOn = 0,
|
|
405
|
+
hiddenDays,
|
|
370
406
|
weekdayFormat = "short",
|
|
371
407
|
events,
|
|
372
408
|
eventsByDay: eventsByDayProp,
|
|
@@ -411,11 +447,49 @@ export function MonthView<T = unknown>({
|
|
|
411
447
|
// The list (MonthList) sorts before passing its index in; only sort here when
|
|
412
448
|
// building our own, so each day reads all-day events first, then by start.
|
|
413
449
|
if (eventsByDayProp) return eventsByDayProp;
|
|
414
|
-
|
|
450
|
+
// Background events shade the time grid; the month grid ignores them.
|
|
451
|
+
const map = groupEventsByDay((events ?? []).filter((event) => !isBackgroundEvent(event)));
|
|
415
452
|
for (const list of map.values()) list.sort(compareDayEvents);
|
|
416
453
|
return map;
|
|
417
454
|
}, [eventsByDayProp, events]);
|
|
418
455
|
const Chip = renderEvent;
|
|
456
|
+
// Built-in "+N more" popover: opens when the consumer doesn't handle
|
|
457
|
+
// `onPressMore` themselves. Keyed by the day id; closes on outside click,
|
|
458
|
+
// Escape, or picking an event.
|
|
459
|
+
const [moreOpenFor, setMoreOpenFor] = useState<string | null>(null);
|
|
460
|
+
const morePopoverRef = useRef<HTMLDivElement | null>(null);
|
|
461
|
+
// The "+N more" button that opened the popover, so focus can return to it.
|
|
462
|
+
const moreTriggerRef = useRef<HTMLButtonElement | null>(null);
|
|
463
|
+
useEffect(() => {
|
|
464
|
+
if (moreOpenFor) {
|
|
465
|
+
// Move focus into the dialog so keyboard users land on the first event.
|
|
466
|
+
morePopoverRef.current?.querySelector<HTMLElement>("button")?.focus();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
// Return focus to the trigger when the popover closes.
|
|
470
|
+
moreTriggerRef.current?.focus();
|
|
471
|
+
moreTriggerRef.current = null;
|
|
472
|
+
}, [moreOpenFor]);
|
|
473
|
+
useEffect(() => {
|
|
474
|
+
if (!moreOpenFor) return;
|
|
475
|
+
const onDocPointerDown = (e: PointerEvent) => {
|
|
476
|
+
if (!morePopoverRef.current?.contains(e.target as Node)) {
|
|
477
|
+
// A pointer dismissal moves focus to whatever was clicked; don't yank
|
|
478
|
+
// it back to the trigger (that's for Escape and event selection).
|
|
479
|
+
moreTriggerRef.current = null;
|
|
480
|
+
setMoreOpenFor(null);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
const onKey = (e: KeyboardEvent) => {
|
|
484
|
+
if (e.key === "Escape") setMoreOpenFor(null);
|
|
485
|
+
};
|
|
486
|
+
document.addEventListener("pointerdown", onDocPointerDown);
|
|
487
|
+
document.addEventListener("keydown", onKey);
|
|
488
|
+
return () => {
|
|
489
|
+
document.removeEventListener("pointerdown", onDocPointerDown);
|
|
490
|
+
document.removeEventListener("keydown", onKey);
|
|
491
|
+
};
|
|
492
|
+
}, [moreOpenFor]);
|
|
419
493
|
// Reserve `maxVisibleEventCount` rows below the date so every cell is uniform;
|
|
420
494
|
// when a day overflows, the last row becomes the "+N more" affordance.
|
|
421
495
|
const eventRowHeight = CELL_PAD * 2 + DATE_ROW + maxVisibleEventCount * (CHIP_HEIGHT + CHIP_GAP);
|
|
@@ -423,6 +497,7 @@ export function MonthView<T = unknown>({
|
|
|
423
497
|
() =>
|
|
424
498
|
buildMonthGrid(date, {
|
|
425
499
|
weekStartsOn,
|
|
500
|
+
hiddenDays,
|
|
426
501
|
weekdayFormat,
|
|
427
502
|
selectedRange,
|
|
428
503
|
selectedDates,
|
|
@@ -444,6 +519,21 @@ export function MonthView<T = unknown>({
|
|
|
444
519
|
],
|
|
445
520
|
);
|
|
446
521
|
|
|
522
|
+
// Lay out each week row's spanning bars once per data change, not per render, so
|
|
523
|
+
// hover / popover / drag-create state changes don't relay out every row.
|
|
524
|
+
const weekLayouts = useMemo(
|
|
525
|
+
() =>
|
|
526
|
+
eventsMode
|
|
527
|
+
? weeks.map((week) =>
|
|
528
|
+
layoutMonthWeek(
|
|
529
|
+
week.days.map((d) => d.date),
|
|
530
|
+
collectRowEvents(week, eventsByDay),
|
|
531
|
+
),
|
|
532
|
+
)
|
|
533
|
+
: [],
|
|
534
|
+
[eventsMode, weeks, eventsByDay],
|
|
535
|
+
);
|
|
536
|
+
|
|
447
537
|
// Roving tabindex: only one day is in the tab order; arrow keys move focus
|
|
448
538
|
// within the month, so the grid is a single, sensible tab stop.
|
|
449
539
|
const initialFocus = useMemo(() => {
|
|
@@ -566,193 +656,370 @@ export function MonthView<T = unknown>({
|
|
|
566
656
|
onKeyDown={dayRoving ? onKeyDown : undefined}
|
|
567
657
|
{...slot("grid")}
|
|
568
658
|
>
|
|
569
|
-
{weeks.map((week) =>
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
659
|
+
{weeks.map((week, weekIndex) => {
|
|
660
|
+
// Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
|
|
661
|
+
// event is one bar across its columns, stacked into lanes; each bar renders
|
|
662
|
+
// inside its start-column cell (valid grid content that reads with that day)
|
|
663
|
+
// and overflows right across the days it spans. The cells reserve the lane
|
|
664
|
+
// rows so "+more" sits below the bars.
|
|
665
|
+
const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
666
|
+
// When lanes overflow, keep the last row for "+more" but always show at
|
|
667
|
+
// least one bar, so a day never collapses to only the overflow row.
|
|
668
|
+
const overflowing = rowLayout.laneCount > maxVisibleEventCount;
|
|
669
|
+
const visibleLanes = overflowing
|
|
670
|
+
? Math.max(maxVisibleEventCount - 1, 1)
|
|
671
|
+
: rowLayout.laneCount;
|
|
672
|
+
// With adjacent months hidden, clamp bars to the current-month columns so
|
|
673
|
+
// none draw over the blank leading/trailing cells.
|
|
674
|
+
const cols = week.days.length;
|
|
675
|
+
let firstVisCol = 0;
|
|
676
|
+
let lastVisCol = cols - 1;
|
|
677
|
+
if (eventsMode && !showAdjacentMonths) {
|
|
678
|
+
const first = week.days.findIndex((d) => d.isCurrentMonth);
|
|
679
|
+
const lastFromEnd = [...week.days].reverse().findIndex((d) => d.isCurrentMonth);
|
|
680
|
+
if (first !== -1) {
|
|
681
|
+
firstVisCol = first;
|
|
682
|
+
lastVisCol = cols - 1 - lastFromEnd;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const barSegs = rowLayout.segments
|
|
686
|
+
.filter((s) => s.lane < visibleLanes)
|
|
687
|
+
.map((s) => {
|
|
688
|
+
const startCol = Math.max(s.startCol, firstVisCol);
|
|
689
|
+
const endCol = Math.min(s.endCol, lastVisCol);
|
|
690
|
+
return {
|
|
691
|
+
seg: s,
|
|
692
|
+
startCol,
|
|
693
|
+
endCol,
|
|
694
|
+
continuesBefore: s.continuesBefore || startCol > s.startCol,
|
|
695
|
+
continuesAfter: s.continuesAfter || endCol < s.endCol,
|
|
696
|
+
};
|
|
697
|
+
})
|
|
698
|
+
.filter((b) => b.startCol <= b.endCol);
|
|
699
|
+
const barChipButton = slot("chipButton", chipButtonDefault);
|
|
700
|
+
const barChip = slot("chip", chipDefault(theme));
|
|
701
|
+
return (
|
|
702
|
+
<div
|
|
703
|
+
key={week.id}
|
|
704
|
+
role="row"
|
|
705
|
+
{...slot("week", {
|
|
706
|
+
base: { display: "grid", gridTemplateColumns: "repeat(7, minmax(0, 1fr))" },
|
|
707
|
+
})}
|
|
708
|
+
>
|
|
709
|
+
{week.days.map((day, dayCol) => {
|
|
710
|
+
const hidden = !showAdjacentMonths && !day.isCurrentMonth;
|
|
711
|
+
const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
|
|
712
|
+
if (hidden) {
|
|
713
|
+
return (
|
|
714
|
+
<div key={day.id} role="gridcell" aria-hidden style={{ height: cellHeight }} />
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
const band = rangeBandDefault(day, theme, fillCellOnSelection);
|
|
718
|
+
const label = format(
|
|
719
|
+
day.date,
|
|
720
|
+
"EEEE, d MMMM yyyy",
|
|
721
|
+
locale ? { locale } : undefined,
|
|
583
722
|
);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
"data-outside": !day.isCurrentMonth,
|
|
600
|
-
"data-disabled": day.isDisabled,
|
|
601
|
-
"data-creating": inCreate,
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
if (eventsMode) {
|
|
605
|
-
const dayEvents = eventsByDay.get(startOfDay(day.date).toISOString()) ?? [];
|
|
606
|
-
// Core decides how many fit; withMore keeps >=1 chip so an
|
|
607
|
-
// overflowing day never shows only the "+N more" row.
|
|
608
|
-
const visible = monthVisibleCount(dayEvents.length, {
|
|
609
|
-
full: maxVisibleEventCount,
|
|
610
|
-
withMore: Math.max(maxVisibleEventCount - 1, 1),
|
|
723
|
+
const dayTime = startOfDay(day.date).getTime();
|
|
724
|
+
const inCreate =
|
|
725
|
+
creating != null &&
|
|
726
|
+
dayTime >= Math.min(creating.anchor, creating.hover) &&
|
|
727
|
+
dayTime <= Math.max(creating.anchor, creating.hover);
|
|
728
|
+
// Present/absent data-* attributes so consumers can style day state
|
|
729
|
+
// with CSS/Tailwind variants (e.g. `data-[today]:bg-blue-500`).
|
|
730
|
+
const dayData = dataState({
|
|
731
|
+
"data-today": day.isToday,
|
|
732
|
+
"data-selected": day.isSelected,
|
|
733
|
+
"data-range": day.isInRange,
|
|
734
|
+
"data-weekend": day.isWeekend,
|
|
735
|
+
"data-outside": !day.isCurrentMonth,
|
|
736
|
+
"data-disabled": day.isDisabled,
|
|
737
|
+
"data-creating": inCreate,
|
|
611
738
|
});
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (suppressClickRef.current) {
|
|
652
|
-
suppressClickRef.current = false;
|
|
653
|
-
return;
|
|
739
|
+
|
|
740
|
+
if (eventsMode) {
|
|
741
|
+
const dayEvents = eventsByDay.get(startOfDay(day.date).toISOString()) ?? [];
|
|
742
|
+
// Events past the visible lanes (this day's segments in a lane the
|
|
743
|
+
// row doesn't show) collapse into "+N more"; the popover lists the
|
|
744
|
+
// whole day.
|
|
745
|
+
const hiddenEvents = rowLayout.segments
|
|
746
|
+
.filter(
|
|
747
|
+
(s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes,
|
|
748
|
+
)
|
|
749
|
+
.map((s) => s.event);
|
|
750
|
+
const dayLabel = format(day.date, "d MMMM", locale ? { locale } : undefined);
|
|
751
|
+
const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight));
|
|
752
|
+
return (
|
|
753
|
+
// Events mode: by default the cell is not a tab stop, so keyboard
|
|
754
|
+
// focus moves through the event chips (real buttons) only, not
|
|
755
|
+
// every empty day. With keyboardDayNavigation the cell joins the
|
|
756
|
+
// roving tab order (arrow keys + Enter to open the day). A pointer
|
|
757
|
+
// click always drills into the day.
|
|
758
|
+
<div
|
|
759
|
+
key={day.id}
|
|
760
|
+
role="gridcell"
|
|
761
|
+
data-day={day.id}
|
|
762
|
+
{...dayData}
|
|
763
|
+
tabIndex={keyboardDayNavigation ? (day.id === focusKey ? 0 : -1) : undefined}
|
|
764
|
+
aria-disabled={day.isDisabled || undefined}
|
|
765
|
+
aria-label={label}
|
|
766
|
+
{...dayCellProps}
|
|
767
|
+
// Drag-to-create disables touch scroll on the cell so a swipe
|
|
768
|
+
// sketches a span instead of scrolling the grid.
|
|
769
|
+
style={
|
|
770
|
+
onCreateEvent
|
|
771
|
+
? { ...dayCellProps.style, touchAction: "none" }
|
|
772
|
+
: dayCellProps.style
|
|
773
|
+
}
|
|
774
|
+
onPointerDown={
|
|
775
|
+
onCreateEvent && !day.isDisabled
|
|
776
|
+
? (e) => {
|
|
777
|
+
if (e.button === 0) beginCreate(day.date);
|
|
654
778
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
779
|
+
: undefined
|
|
780
|
+
}
|
|
781
|
+
onPointerEnter={onCreateEvent ? () => extendCreate(day.date) : undefined}
|
|
782
|
+
onClick={
|
|
783
|
+
day.isDisabled
|
|
784
|
+
? undefined
|
|
785
|
+
: () => {
|
|
786
|
+
if (suppressClickRef.current) {
|
|
787
|
+
suppressClickRef.current = false;
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
665
790
|
onPressDay?.(day.date);
|
|
666
791
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
792
|
+
}
|
|
793
|
+
onKeyDown={
|
|
794
|
+
keyboardDayNavigation && !day.isDisabled
|
|
795
|
+
? (e) => {
|
|
796
|
+
// Let Enter/Space on a focused chip activate the chip.
|
|
797
|
+
if (e.target !== e.currentTarget) return;
|
|
798
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
799
|
+
e.preventDefault();
|
|
800
|
+
onPressDay?.(day.date);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
: undefined
|
|
804
|
+
}
|
|
679
805
|
>
|
|
680
|
-
{
|
|
681
|
-
|
|
682
|
-
|
|
806
|
+
{band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
|
|
807
|
+
<span {...dayData} {...slot("dayBadge", compactBadgeDefault(day, theme))}>
|
|
808
|
+
{day.label}
|
|
809
|
+
</span>
|
|
810
|
+
{/* Spanning bars that start in this column: absolutely placed,
|
|
811
|
+
overflowing right across the days they span. Rendered here
|
|
812
|
+
(not a row overlay) so each bar is valid content of its
|
|
813
|
+
start day's gridcell and reads with that day. Made
|
|
814
|
+
non-interactive mid drag-create so a sweep reaches the
|
|
815
|
+
cells beneath. */}
|
|
816
|
+
{barSegs
|
|
817
|
+
.filter((b) => b.startCol === dayCol)
|
|
818
|
+
.map((b) => {
|
|
819
|
+
const span = b.endCol - b.startCol + 1;
|
|
820
|
+
return (
|
|
821
|
+
<button
|
|
822
|
+
key={`bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`}
|
|
823
|
+
type="button"
|
|
824
|
+
onClick={(e) => {
|
|
825
|
+
e.stopPropagation();
|
|
826
|
+
onPressEvent?.(b.seg.event);
|
|
827
|
+
}}
|
|
828
|
+
{...barChipButton}
|
|
829
|
+
title={b.seg.event.title}
|
|
830
|
+
aria-label={
|
|
831
|
+
eventAccessibilityLabel
|
|
832
|
+
? eventAccessibilityLabel(b.seg.event, {
|
|
833
|
+
mode: "month",
|
|
834
|
+
isAllDay: isAllDayEvent(b.seg.event),
|
|
835
|
+
ampm: false,
|
|
836
|
+
})
|
|
837
|
+
: `${b.seg.event.title}, ${dayLabel}`
|
|
838
|
+
}
|
|
839
|
+
style={{
|
|
840
|
+
...barChipButton.style,
|
|
841
|
+
position: "absolute",
|
|
842
|
+
left: 2,
|
|
843
|
+
width: `calc(${span * 100}% - 4px)`,
|
|
844
|
+
top:
|
|
845
|
+
CELL_PAD +
|
|
846
|
+
DATE_ROW +
|
|
847
|
+
CHIP_GAP +
|
|
848
|
+
b.seg.lane * (CHIP_HEIGHT + CHIP_GAP),
|
|
849
|
+
height: CHIP_HEIGHT,
|
|
850
|
+
pointerEvents: isCreating ? "none" : "auto",
|
|
851
|
+
zIndex: 2,
|
|
852
|
+
}}
|
|
853
|
+
>
|
|
854
|
+
{Chip ? (
|
|
855
|
+
<Chip
|
|
856
|
+
event={b.seg.event}
|
|
857
|
+
onPress={() => onPressEvent?.(b.seg.event)}
|
|
858
|
+
/>
|
|
859
|
+
) : (
|
|
860
|
+
<span
|
|
861
|
+
{...barChip}
|
|
862
|
+
style={{
|
|
863
|
+
...barChip.style,
|
|
864
|
+
...(b.continuesBefore
|
|
865
|
+
? { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }
|
|
866
|
+
: null),
|
|
867
|
+
...(b.continuesAfter
|
|
868
|
+
? { borderTopRightRadius: 0, borderBottomRightRadius: 0 }
|
|
869
|
+
: null),
|
|
870
|
+
}}
|
|
871
|
+
>
|
|
872
|
+
{b.seg.event.title}
|
|
873
|
+
</span>
|
|
874
|
+
)}
|
|
875
|
+
</button>
|
|
876
|
+
);
|
|
877
|
+
})}
|
|
878
|
+
<div
|
|
879
|
+
{...slot("events", {
|
|
880
|
+
base: { display: "flex", flexDirection: "column", gap: CHIP_GAP },
|
|
881
|
+
})}
|
|
882
|
+
>
|
|
883
|
+
{/* Reserve one row per visible lane so the absolute bars have
|
|
884
|
+
space and "+more" sits below them. */}
|
|
885
|
+
{Array.from({ length: visibleLanes }, (_, i) => (
|
|
886
|
+
<div key={`lane-${i}`} aria-hidden style={{ height: CHIP_HEIGHT }} />
|
|
887
|
+
))}
|
|
888
|
+
{hiddenEvents.length > 0 ? (
|
|
683
889
|
<button
|
|
684
|
-
key={`${event.start.toISOString()}:${event.title}`}
|
|
685
890
|
type="button"
|
|
891
|
+
// In built-in-popover mode, keep the document
|
|
892
|
+
// pointerdown dismiss from firing before this click's
|
|
893
|
+
// toggle, so pressing the button again closes it.
|
|
894
|
+
onPointerDown={onPressMore ? undefined : (e) => e.stopPropagation()}
|
|
686
895
|
onClick={(e) => {
|
|
687
896
|
e.stopPropagation();
|
|
688
|
-
|
|
897
|
+
if (onPressMore) onPressMore(hiddenEvents, day.date);
|
|
898
|
+
else {
|
|
899
|
+
moreTriggerRef.current = e.currentTarget;
|
|
900
|
+
setMoreOpenFor((open) => (open === day.id ? null : day.id));
|
|
901
|
+
}
|
|
689
902
|
}}
|
|
690
|
-
{...slot("
|
|
691
|
-
|
|
692
|
-
aria-
|
|
693
|
-
eventAccessibilityLabel
|
|
694
|
-
? eventAccessibilityLabel(event, {
|
|
695
|
-
mode: "month",
|
|
696
|
-
isAllDay: isAllDayEvent(event),
|
|
697
|
-
ampm: false,
|
|
698
|
-
})
|
|
699
|
-
: `${event.title}, ${dayLabel}`
|
|
700
|
-
}
|
|
903
|
+
{...slot("more", moreButtonDefault(theme))}
|
|
904
|
+
aria-label={`${hiddenEvents.length} more events, ${dayLabel}`}
|
|
905
|
+
aria-expanded={onPressMore ? undefined : moreOpenFor === day.id}
|
|
701
906
|
>
|
|
702
|
-
{
|
|
703
|
-
<Chip event={event} onPress={onPress} />
|
|
704
|
-
) : (
|
|
705
|
-
<span {...slot("chip", chipDefault(theme))}>{event.title}</span>
|
|
706
|
-
)}
|
|
907
|
+
{moreLabel.replace("{moreCount}", String(hiddenEvents.length))}
|
|
707
908
|
</button>
|
|
708
|
-
)
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
909
|
+
) : null}
|
|
910
|
+
{moreOpenFor === day.id ? (
|
|
911
|
+
<div
|
|
912
|
+
ref={morePopoverRef}
|
|
913
|
+
// A non-modal dialog: Tab stays inside and Escape closes,
|
|
914
|
+
// but the page behind is not inert (outside clicks work),
|
|
915
|
+
// so no aria-modal claim.
|
|
916
|
+
role="dialog"
|
|
917
|
+
aria-label={dayLabel}
|
|
918
|
+
onPointerDown={(e) => e.stopPropagation()}
|
|
919
|
+
// Contain Tab inside the dialog; Escape (handled on the
|
|
920
|
+
// document) closes it and restores focus to the trigger.
|
|
921
|
+
onKeyDown={(e) => {
|
|
922
|
+
if (e.key !== "Tab") return;
|
|
923
|
+
const buttons =
|
|
924
|
+
morePopoverRef.current?.querySelectorAll<HTMLElement>("button");
|
|
925
|
+
if (!buttons?.length) return;
|
|
926
|
+
const first = buttons[0];
|
|
927
|
+
const last = buttons[buttons.length - 1];
|
|
928
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
929
|
+
e.preventDefault();
|
|
930
|
+
last.focus();
|
|
931
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
932
|
+
e.preventDefault();
|
|
933
|
+
first.focus();
|
|
934
|
+
}
|
|
935
|
+
}}
|
|
936
|
+
{...slot("morePopover", {
|
|
937
|
+
base: {
|
|
938
|
+
position: "absolute",
|
|
939
|
+
top: 2,
|
|
940
|
+
left: 2,
|
|
941
|
+
right: 2,
|
|
942
|
+
zIndex: 10,
|
|
943
|
+
display: "flex",
|
|
944
|
+
flexDirection: "column",
|
|
945
|
+
gap: 2,
|
|
946
|
+
maxHeight: 240,
|
|
947
|
+
overflowY: "auto",
|
|
948
|
+
},
|
|
949
|
+
themed: {
|
|
950
|
+
background: theme.surface,
|
|
951
|
+
border: `1px solid ${theme.gridLine}`,
|
|
952
|
+
borderRadius: 8,
|
|
953
|
+
padding: 6,
|
|
954
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
|
|
955
|
+
},
|
|
956
|
+
})}
|
|
957
|
+
>
|
|
958
|
+
<div style={{ fontSize: 11, fontWeight: 600, color: theme.textMuted }}>
|
|
959
|
+
{dayLabel}
|
|
960
|
+
</div>
|
|
961
|
+
{dayEvents.map((event, i) => (
|
|
962
|
+
<button
|
|
963
|
+
key={i}
|
|
964
|
+
type="button"
|
|
965
|
+
onClick={() => {
|
|
966
|
+
setMoreOpenFor(null);
|
|
967
|
+
onPressEvent?.(event);
|
|
968
|
+
}}
|
|
969
|
+
style={{
|
|
970
|
+
display: "block",
|
|
971
|
+
width: "100%",
|
|
972
|
+
border: "none",
|
|
973
|
+
background: "transparent",
|
|
974
|
+
padding: 0,
|
|
975
|
+
font: "inherit",
|
|
976
|
+
textAlign: "left",
|
|
977
|
+
cursor: "pointer",
|
|
978
|
+
}}
|
|
979
|
+
>
|
|
980
|
+
{Chip ? (
|
|
981
|
+
<Chip event={event} onPress={() => onPressEvent?.(event)} />
|
|
982
|
+
) : (
|
|
983
|
+
<span {...slot("chip", chipDefault(theme))}>{event.title}</span>
|
|
984
|
+
)}
|
|
985
|
+
</button>
|
|
986
|
+
))}
|
|
987
|
+
</div>
|
|
988
|
+
) : null}
|
|
989
|
+
</div>
|
|
723
990
|
</div>
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
991
|
+
);
|
|
992
|
+
}
|
|
727
993
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
{...dayData}
|
|
735
|
-
tabIndex={day.id === focusKey ? 0 : -1}
|
|
736
|
-
aria-disabled={day.isDisabled || undefined}
|
|
737
|
-
aria-label={label}
|
|
738
|
-
aria-pressed={day.isSelected || day.isInRange}
|
|
739
|
-
{...slot("day", dayCellDefault(day, theme))}
|
|
740
|
-
onClick={day.isDisabled ? undefined : () => onPressDay?.(day.date)}
|
|
741
|
-
onMouseEnter={day.isDisabled ? undefined : () => setHoveredKey(day.id)}
|
|
742
|
-
onMouseLeave={() => setHoveredKey((k) => (k === day.id ? null : k))}
|
|
743
|
-
>
|
|
744
|
-
{band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
|
|
745
|
-
<span
|
|
994
|
+
return (
|
|
995
|
+
<button
|
|
996
|
+
key={day.id}
|
|
997
|
+
type="button"
|
|
998
|
+
role="gridcell"
|
|
999
|
+
data-day={day.id}
|
|
746
1000
|
{...dayData}
|
|
747
|
-
{
|
|
1001
|
+
tabIndex={day.id === focusKey ? 0 : -1}
|
|
1002
|
+
aria-disabled={day.isDisabled || undefined}
|
|
1003
|
+
aria-label={label}
|
|
1004
|
+
aria-pressed={day.isSelected || day.isInRange}
|
|
1005
|
+
{...slot("day", dayCellDefault(day, theme))}
|
|
1006
|
+
onClick={day.isDisabled ? undefined : () => onPressDay?.(day.date)}
|
|
1007
|
+
onMouseEnter={day.isDisabled ? undefined : () => setHoveredKey(day.id)}
|
|
1008
|
+
onMouseLeave={() => setHoveredKey((k) => (k === day.id ? null : k))}
|
|
748
1009
|
>
|
|
749
|
-
{
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1010
|
+
{band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
|
|
1011
|
+
<span
|
|
1012
|
+
{...dayData}
|
|
1013
|
+
{...slot("dayBadge", badgeDefault(day, theme, hoveredKey === day.id))}
|
|
1014
|
+
>
|
|
1015
|
+
{day.label}
|
|
1016
|
+
</span>
|
|
1017
|
+
</button>
|
|
1018
|
+
);
|
|
1019
|
+
})}
|
|
1020
|
+
</div>
|
|
1021
|
+
);
|
|
1022
|
+
})}
|
|
756
1023
|
</div>
|
|
757
1024
|
</div>
|
|
758
1025
|
);
|