@super-calendar/dom 2.7.0 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/MonthView.tsx CHANGED
@@ -29,8 +29,9 @@ import {
29
29
  groupEventsByDay,
30
30
  isBackgroundEvent,
31
31
  isAllDayEvent,
32
+ layoutMonthWeek,
32
33
  type MonthGridDay,
33
- monthVisibleCount,
34
+ type MonthGridWeek,
34
35
  rangeBandKind,
35
36
  type WeekdayFormat,
36
37
  type WeekStartsOn,
@@ -57,6 +58,9 @@ export type MonthViewSlot =
57
58
  | "more"
58
59
  | "morePopover";
59
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;
63
+
60
64
  // Chip metrics for the events layout (when `events` is provided).
61
65
  const DATE_ROW = 24;
62
66
  const CHIP_HEIGHT = 18;
@@ -99,7 +103,12 @@ export interface MonthViewProps<T = unknown>
99
103
  * announce. Defaults to the event title and day (e.g. "Standup, 15 July").
100
104
  */
101
105
  eventAccessibilityLabel?: EventAccessibilityLabeler<T>;
102
- /** Max chips shown per day before a "+N more" row (default 3). */
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
+ */
103
112
  maxVisibleEventCount?: number;
104
113
  /** Template for the overflow row; `{moreCount}` is replaced (default "{moreCount} More"). */
105
114
  moreLabel?: string;
@@ -113,6 +122,8 @@ export interface MonthViewProps<T = unknown>
113
122
  selectedDates?: Date[];
114
123
  /** Render days from the neighbouring months in the leading/trailing cells (default true). */
115
124
  showAdjacentMonths?: boolean;
125
+ /** Tint weekend day cells with the theme's weekend background (default true). */
126
+ highlightWeekends?: boolean;
116
127
  /**
117
128
  * Fill the whole cell with the range background instead of the default
118
129
  * centered rounded "pill" strip. Default false.
@@ -152,7 +163,11 @@ export interface MonthViewProps<T = unknown>
152
163
  // Each helper returns the slot's built-in styling split into `base` (structural,
153
164
  // always applied) and `themed` (colour/type/spacing, dropped when a class is set).
154
165
 
155
- function dayCellDefault(day: MonthGridDay, theme: DomCalendarTheme): SlotDefault {
166
+ function dayCellDefault(
167
+ day: MonthGridDay,
168
+ theme: DomCalendarTheme,
169
+ highlightWeekends: boolean,
170
+ ): SlotDefault {
156
171
  return {
157
172
  base: {
158
173
  position: "relative",
@@ -168,7 +183,10 @@ function dayCellDefault(day: MonthGridDay, theme: DomCalendarTheme): SlotDefault
168
183
  },
169
184
  themed: {
170
185
  // The range band is a separate layer; the cell only carries the weekend tint.
171
- background: day.isWeekend && !day.isInRange ? theme.weekendBackground : "transparent",
186
+ background:
187
+ highlightWeekends && day.isWeekend && !day.isInRange
188
+ ? theme.weekendBackground
189
+ : "transparent",
172
190
  fontSize: 15,
173
191
  color: day.isDisabled ? theme.textDisabled : theme.text,
174
192
  },
@@ -245,7 +263,12 @@ function badgeDefault(day: MonthGridDay, theme: DomCalendarTheme, hovered: boole
245
263
 
246
264
  // --- Calendar (events) layout styles -------------------------------------
247
265
 
248
- function eventCellDefault(day: MonthGridDay, theme: DomCalendarTheme, height: number): SlotDefault {
266
+ function eventCellDefault(
267
+ day: MonthGridDay,
268
+ theme: DomCalendarTheme,
269
+ height: number,
270
+ highlightWeekends: boolean,
271
+ ): SlotDefault {
249
272
  return {
250
273
  base: {
251
274
  position: "relative",
@@ -263,7 +286,10 @@ function eventCellDefault(day: MonthGridDay, theme: DomCalendarTheme, height: nu
263
286
  },
264
287
  themed: {
265
288
  borderTop: `1px solid ${theme.gridLine}`,
266
- background: day.isWeekend && !day.isInRange ? theme.weekendBackground : "transparent",
289
+ background:
290
+ highlightWeekends && day.isWeekend && !day.isInRange
291
+ ? theme.weekendBackground
292
+ : "transparent",
267
293
  color: day.isDisabled ? theme.textDisabled : theme.text,
268
294
  },
269
295
  };
@@ -360,6 +386,28 @@ interface MonthViewInternalProps<T = unknown> extends MonthViewProps<T> {
360
386
  eventsByDay?: ReadonlyMap<string, CalendarEvent<T>[]>;
361
387
  }
362
388
 
389
+ // The distinct events touching a week row, in the per-day index's sorted order.
390
+ // A multi-day event lives in each covered day's bucket, so dedupe by reference;
391
+ // this scans only the row's days, not every event in the month.
392
+ function collectRowEvents<T>(
393
+ week: MonthGridWeek,
394
+ eventsByDay: ReadonlyMap<string, CalendarEvent<T>[]>,
395
+ ): CalendarEvent<T>[] {
396
+ const seen = new Set<CalendarEvent<T>>();
397
+ const out: CalendarEvent<T>[] = [];
398
+ for (const day of week.days) {
399
+ const list = eventsByDay.get(startOfDay(day.date).toISOString());
400
+ if (!list) continue;
401
+ for (const event of list) {
402
+ if (!seen.has(event)) {
403
+ seen.add(event);
404
+ out.push(event);
405
+ }
406
+ }
407
+ }
408
+ return out;
409
+ }
410
+
363
411
  /**
364
412
  * A single static month grid, rendered with plain DOM elements.
365
413
  *
@@ -384,6 +432,7 @@ export function MonthView<T = unknown>({
384
432
  selectedRange,
385
433
  selectedDates,
386
434
  showAdjacentMonths = true,
435
+ highlightWeekends = true,
387
436
  fillCellOnSelection = false,
388
437
  showTitle = true,
389
438
  showWeekdays = true,
@@ -488,6 +537,21 @@ export function MonthView<T = unknown>({
488
537
  ],
489
538
  );
490
539
 
540
+ // Lay out each week row's spanning bars once per data change, not per render, so
541
+ // hover / popover / drag-create state changes don't relay out every row.
542
+ const weekLayouts = useMemo(
543
+ () =>
544
+ eventsMode
545
+ ? weeks.map((week) =>
546
+ layoutMonthWeek(
547
+ week.days.map((d) => d.date),
548
+ collectRowEvents(week, eventsByDay),
549
+ ),
550
+ )
551
+ : [],
552
+ [eventsMode, weeks, eventsByDay],
553
+ );
554
+
491
555
  // Roving tabindex: only one day is in the tab order; arrow keys move focus
492
556
  // within the month, so the grid is a single, sensible tab stop.
493
557
  const initialFocus = useMemo(() => {
@@ -610,281 +674,373 @@ export function MonthView<T = unknown>({
610
674
  onKeyDown={dayRoving ? onKeyDown : undefined}
611
675
  {...slot("grid")}
612
676
  >
613
- {weeks.map((week) => (
614
- <div
615
- key={week.id}
616
- role="row"
617
- {...slot("week", {
618
- base: { display: "grid", gridTemplateColumns: "repeat(7, minmax(0, 1fr))" },
619
- })}
620
- >
621
- {week.days.map((day) => {
622
- const hidden = !showAdjacentMonths && !day.isCurrentMonth;
623
- const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
624
- if (hidden) {
625
- return (
626
- <div key={day.id} role="gridcell" aria-hidden style={{ height: cellHeight }} />
677
+ {weeks.map((week, weekIndex) => {
678
+ // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
679
+ // event is one bar across its columns, stacked into lanes; each bar renders
680
+ // inside its start-column cell (valid grid content that reads with that day)
681
+ // and overflows right across the days it spans. The cells reserve the lane
682
+ // rows so "+more" sits below the bars.
683
+ const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
684
+ // When lanes overflow, keep the last row for "+more" but always show at
685
+ // least one bar, so a day never collapses to only the overflow row.
686
+ const overflowing = rowLayout.laneCount > maxVisibleEventCount;
687
+ const visibleLanes = overflowing
688
+ ? Math.max(maxVisibleEventCount - 1, 1)
689
+ : rowLayout.laneCount;
690
+ // With adjacent months hidden, clamp bars to the current-month columns so
691
+ // none draw over the blank leading/trailing cells.
692
+ const cols = week.days.length;
693
+ let firstVisCol = 0;
694
+ let lastVisCol = cols - 1;
695
+ if (eventsMode && !showAdjacentMonths) {
696
+ const first = week.days.findIndex((d) => d.isCurrentMonth);
697
+ const lastFromEnd = [...week.days].reverse().findIndex((d) => d.isCurrentMonth);
698
+ if (first !== -1) {
699
+ firstVisCol = first;
700
+ lastVisCol = cols - 1 - lastFromEnd;
701
+ }
702
+ }
703
+ const barSegs = rowLayout.segments
704
+ .filter((s) => s.lane < visibleLanes)
705
+ .map((s) => {
706
+ const startCol = Math.max(s.startCol, firstVisCol);
707
+ const endCol = Math.min(s.endCol, lastVisCol);
708
+ return {
709
+ seg: s,
710
+ startCol,
711
+ endCol,
712
+ continuesBefore: s.continuesBefore || startCol > s.startCol,
713
+ continuesAfter: s.continuesAfter || endCol < s.endCol,
714
+ };
715
+ })
716
+ .filter((b) => b.startCol <= b.endCol);
717
+ const barChipButton = slot("chipButton", chipButtonDefault);
718
+ const barChip = slot("chip", chipDefault(theme));
719
+ return (
720
+ <div
721
+ key={week.id}
722
+ role="row"
723
+ {...slot("week", {
724
+ base: { display: "grid", gridTemplateColumns: "repeat(7, minmax(0, 1fr))" },
725
+ })}
726
+ >
727
+ {week.days.map((day, dayCol) => {
728
+ const hidden = !showAdjacentMonths && !day.isCurrentMonth;
729
+ const cellHeight = eventsMode ? eventRowHeight : theme.cellHeight;
730
+ if (hidden) {
731
+ return (
732
+ <div key={day.id} role="gridcell" aria-hidden style={{ height: cellHeight }} />
733
+ );
734
+ }
735
+ const band = rangeBandDefault(day, theme, fillCellOnSelection);
736
+ const label = format(
737
+ day.date,
738
+ "EEEE, d MMMM yyyy",
739
+ locale ? { locale } : undefined,
627
740
  );
628
- }
629
- const band = rangeBandDefault(day, theme, fillCellOnSelection);
630
- const label = format(day.date, "EEEE, d MMMM yyyy", locale ? { locale } : undefined);
631
- const dayTime = startOfDay(day.date).getTime();
632
- const inCreate =
633
- creating != null &&
634
- dayTime >= Math.min(creating.anchor, creating.hover) &&
635
- dayTime <= Math.max(creating.anchor, creating.hover);
636
- // Present/absent data-* attributes so consumers can style day state
637
- // with CSS/Tailwind variants (e.g. `data-[today]:bg-blue-500`).
638
- const dayData = dataState({
639
- "data-today": day.isToday,
640
- "data-selected": day.isSelected,
641
- "data-range": day.isInRange,
642
- "data-weekend": day.isWeekend,
643
- "data-outside": !day.isCurrentMonth,
644
- "data-disabled": day.isDisabled,
645
- "data-creating": inCreate,
646
- });
647
-
648
- if (eventsMode) {
649
- const dayEvents = eventsByDay.get(startOfDay(day.date).toISOString()) ?? [];
650
- // Core decides how many fit; withMore keeps >=1 chip so an
651
- // overflowing day never shows only the "+N more" row.
652
- const visible = monthVisibleCount(dayEvents.length, {
653
- full: maxVisibleEventCount,
654
- withMore: Math.max(maxVisibleEventCount - 1, 1),
741
+ const dayTime = startOfDay(day.date).getTime();
742
+ const inCreate =
743
+ creating != null &&
744
+ dayTime >= Math.min(creating.anchor, creating.hover) &&
745
+ dayTime <= Math.max(creating.anchor, creating.hover);
746
+ // Present/absent data-* attributes so consumers can style day state
747
+ // with CSS/Tailwind variants (e.g. `data-[today]:bg-blue-500`).
748
+ const dayData = dataState({
749
+ "data-today": day.isToday,
750
+ "data-selected": day.isSelected,
751
+ "data-range": day.isInRange,
752
+ "data-weekend": day.isWeekend,
753
+ "data-outside": !day.isCurrentMonth,
754
+ "data-disabled": day.isDisabled,
755
+ "data-creating": inCreate,
655
756
  });
656
- const shown = dayEvents.slice(0, visible);
657
- const rest = dayEvents.slice(visible);
658
- const overflow = rest.length > 0;
659
- const dayLabel = format(day.date, "d MMMM", locale ? { locale } : undefined);
660
- const dayCellProps = slot("day", eventCellDefault(day, theme, cellHeight));
661
- return (
662
- // Events mode: by default the cell is not a tab stop, so keyboard
663
- // focus moves through the event chips (real buttons) only, not
664
- // every empty day. With keyboardDayNavigation the cell joins the
665
- // roving tab order (arrow keys + Enter to open the day). A pointer
666
- // click always drills into the day.
667
- <div
668
- key={day.id}
669
- role="gridcell"
670
- data-day={day.id}
671
- {...dayData}
672
- tabIndex={keyboardDayNavigation ? (day.id === focusKey ? 0 : -1) : undefined}
673
- aria-disabled={day.isDisabled || undefined}
674
- aria-label={label}
675
- {...dayCellProps}
676
- // Drag-to-create disables touch scroll on the cell so a swipe
677
- // sketches a span instead of scrolling the grid.
678
- style={
679
- onCreateEvent
680
- ? { ...dayCellProps.style, touchAction: "none" }
681
- : dayCellProps.style
682
- }
683
- onPointerDown={
684
- onCreateEvent && !day.isDisabled
685
- ? (e) => {
686
- if (e.button === 0) beginCreate(day.date);
687
- }
688
- : undefined
689
- }
690
- onPointerEnter={onCreateEvent ? () => extendCreate(day.date) : undefined}
691
- onClick={
692
- day.isDisabled
693
- ? undefined
694
- : () => {
695
- if (suppressClickRef.current) {
696
- suppressClickRef.current = false;
697
- return;
698
- }
699
- onPressDay?.(day.date);
700
- }
701
- }
702
- onKeyDown={
703
- keyboardDayNavigation && !day.isDisabled
704
- ? (e) => {
705
- // Let Enter/Space on a focused chip activate the chip.
706
- if (e.target !== e.currentTarget) return;
707
- if (e.key === "Enter" || e.key === " ") {
708
- e.preventDefault();
709
- onPressDay?.(day.date);
710
- }
711
- }
712
- : undefined
713
- }
714
- >
715
- {band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
716
- <span {...dayData} {...slot("dayBadge", compactBadgeDefault(day, theme))}>
717
- {day.label}
718
- </span>
757
+
758
+ if (eventsMode) {
759
+ const dayEvents = eventsByDay.get(startOfDay(day.date).toISOString()) ?? [];
760
+ // Events past the visible lanes (this day's segments in a lane the
761
+ // row doesn't show) collapse into "+N more"; the popover lists the
762
+ // whole day.
763
+ const hiddenEvents = rowLayout.segments
764
+ .filter(
765
+ (s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes,
766
+ )
767
+ .map((s) => s.event);
768
+ const dayLabel = format(day.date, "d MMMM", locale ? { locale } : undefined);
769
+ const dayCellProps = slot(
770
+ "day",
771
+ eventCellDefault(day, theme, cellHeight, highlightWeekends),
772
+ );
773
+ return (
774
+ // Events mode: by default the cell is not a tab stop, so keyboard
775
+ // focus moves through the event chips (real buttons) only, not
776
+ // every empty day. With keyboardDayNavigation the cell joins the
777
+ // roving tab order (arrow keys + Enter to open the day). A pointer
778
+ // click always drills into the day.
719
779
  <div
720
- {...slot("events", {
721
- base: { display: "flex", flexDirection: "column", gap: CHIP_GAP },
722
- })}
723
- >
724
- {shown.map((event) => {
725
- const onPress = () => onPressEvent?.(event);
726
- return (
727
- <button
728
- key={`${event.start.toISOString()}:${event.title}`}
729
- type="button"
730
- onClick={(e) => {
731
- e.stopPropagation();
732
- onPress();
733
- }}
734
- {...slot("chipButton", chipButtonDefault)}
735
- title={event.title}
736
- aria-label={
737
- eventAccessibilityLabel
738
- ? eventAccessibilityLabel(event, {
739
- mode: "month",
740
- isAllDay: isAllDayEvent(event),
741
- ampm: false,
742
- })
743
- : `${event.title}, ${dayLabel}`
780
+ key={day.id}
781
+ role="gridcell"
782
+ data-day={day.id}
783
+ {...dayData}
784
+ tabIndex={keyboardDayNavigation ? (day.id === focusKey ? 0 : -1) : undefined}
785
+ aria-disabled={day.isDisabled || undefined}
786
+ aria-label={label}
787
+ {...dayCellProps}
788
+ // Drag-to-create disables touch scroll on the cell so a swipe
789
+ // sketches a span instead of scrolling the grid.
790
+ style={
791
+ onCreateEvent
792
+ ? { ...dayCellProps.style, touchAction: "none" }
793
+ : dayCellProps.style
794
+ }
795
+ onPointerDown={
796
+ onCreateEvent && !day.isDisabled
797
+ ? (e) => {
798
+ if (e.button === 0) beginCreate(day.date);
744
799
  }
745
- >
746
- {Chip ? (
747
- <Chip event={event} onPress={onPress} />
748
- ) : (
749
- <span {...slot("chip", chipDefault(theme))}>{event.title}</span>
750
- )}
751
- </button>
752
- );
753
- })}
754
- {overflow ? (
755
- <button
756
- type="button"
757
- // In built-in-popover mode, keep the document
758
- // pointerdown dismiss from firing before this click's
759
- // toggle, so pressing the button again closes it.
760
- onPointerDown={onPressMore ? undefined : (e) => e.stopPropagation()}
761
- onClick={(e) => {
762
- e.stopPropagation();
763
- if (onPressMore) onPressMore(rest, day.date);
764
- else {
765
- moreTriggerRef.current = e.currentTarget;
766
- setMoreOpenFor((open) => (open === day.id ? null : day.id));
800
+ : undefined
801
+ }
802
+ onPointerEnter={onCreateEvent ? () => extendCreate(day.date) : undefined}
803
+ onClick={
804
+ day.isDisabled
805
+ ? undefined
806
+ : () => {
807
+ if (suppressClickRef.current) {
808
+ suppressClickRef.current = false;
809
+ return;
810
+ }
811
+ onPressDay?.(day.date);
767
812
  }
768
- }}
769
- {...slot("more", moreButtonDefault(theme))}
770
- aria-label={`${rest.length} more events, ${dayLabel}`}
771
- aria-expanded={onPressMore ? undefined : moreOpenFor === day.id}
772
- >
773
- {moreLabel.replace("{moreCount}", String(rest.length))}
774
- </button>
775
- ) : null}
776
- {moreOpenFor === day.id ? (
777
- <div
778
- ref={morePopoverRef}
779
- // A non-modal dialog: Tab stays inside and Escape closes,
780
- // but the page behind is not inert (outside clicks work),
781
- // so no aria-modal claim.
782
- role="dialog"
783
- aria-label={dayLabel}
784
- onPointerDown={(e) => e.stopPropagation()}
785
- // Contain Tab inside the dialog; Escape (handled on the
786
- // document) closes it and restores focus to the trigger.
787
- onKeyDown={(e) => {
788
- if (e.key !== "Tab") return;
789
- const buttons =
790
- morePopoverRef.current?.querySelectorAll<HTMLElement>("button");
791
- if (!buttons?.length) return;
792
- const first = buttons[0];
793
- const last = buttons[buttons.length - 1];
794
- if (e.shiftKey && document.activeElement === first) {
795
- e.preventDefault();
796
- last.focus();
797
- } else if (!e.shiftKey && document.activeElement === last) {
798
- e.preventDefault();
799
- first.focus();
813
+ }
814
+ onKeyDown={
815
+ keyboardDayNavigation && !day.isDisabled
816
+ ? (e) => {
817
+ // Let Enter/Space on a focused chip activate the chip.
818
+ if (e.target !== e.currentTarget) return;
819
+ if (e.key === "Enter" || e.key === " ") {
820
+ e.preventDefault();
821
+ onPressDay?.(day.date);
822
+ }
800
823
  }
801
- }}
802
- {...slot("morePopover", {
803
- base: {
804
- position: "absolute",
805
- top: 2,
806
- left: 2,
807
- right: 2,
808
- zIndex: 10,
809
- display: "flex",
810
- flexDirection: "column",
811
- gap: 2,
812
- maxHeight: 240,
813
- overflowY: "auto",
814
- },
815
- themed: {
816
- background: theme.surface,
817
- border: `1px solid ${theme.gridLine}`,
818
- borderRadius: 8,
819
- padding: 6,
820
- boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
821
- },
822
- })}
823
- >
824
- <div style={{ fontSize: 11, fontWeight: 600, color: theme.textMuted }}>
825
- {dayLabel}
826
- </div>
827
- {dayEvents.map((event, i) => (
824
+ : undefined
825
+ }
826
+ >
827
+ {band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
828
+ <span {...dayData} {...slot("dayBadge", compactBadgeDefault(day, theme))}>
829
+ {day.label}
830
+ </span>
831
+ {/* Spanning bars that start in this column: absolutely placed,
832
+ overflowing right across the days they span. Rendered here
833
+ (not a row overlay) so each bar is valid content of its
834
+ start day's gridcell and reads with that day. Made
835
+ non-interactive mid drag-create so a sweep reaches the
836
+ cells beneath. */}
837
+ {barSegs
838
+ .filter((b) => b.startCol === dayCol)
839
+ .map((b) => {
840
+ const span = b.endCol - b.startCol + 1;
841
+ return (
828
842
  <button
829
- key={i}
843
+ key={`bar-${b.seg.event.start.toISOString()}:${b.seg.event.title}:${b.seg.lane}`}
830
844
  type="button"
831
- onClick={() => {
832
- setMoreOpenFor(null);
833
- onPressEvent?.(event);
845
+ onClick={(e) => {
846
+ e.stopPropagation();
847
+ onPressEvent?.(b.seg.event);
834
848
  }}
849
+ {...barChipButton}
850
+ title={b.seg.event.title}
851
+ aria-label={
852
+ eventAccessibilityLabel
853
+ ? eventAccessibilityLabel(b.seg.event, {
854
+ mode: "month",
855
+ isAllDay: isAllDayEvent(b.seg.event),
856
+ ampm: false,
857
+ })
858
+ : `${b.seg.event.title}, ${dayLabel}`
859
+ }
835
860
  style={{
836
- display: "block",
837
- width: "100%",
838
- border: "none",
839
- background: "transparent",
840
- padding: 0,
841
- font: "inherit",
842
- textAlign: "left",
843
- cursor: "pointer",
861
+ ...barChipButton.style,
862
+ position: "absolute",
863
+ left: 2,
864
+ width: `calc(${span * 100}% - 4px)`,
865
+ top:
866
+ CELL_PAD +
867
+ DATE_ROW +
868
+ CHIP_GAP +
869
+ b.seg.lane * (CHIP_HEIGHT + CHIP_GAP),
870
+ height: CHIP_HEIGHT,
871
+ pointerEvents: isCreating ? "none" : "auto",
872
+ zIndex: 2,
844
873
  }}
845
874
  >
846
875
  {Chip ? (
847
- <Chip event={event} onPress={() => onPressEvent?.(event)} />
876
+ <Chip
877
+ event={b.seg.event}
878
+ onPress={() => onPressEvent?.(b.seg.event)}
879
+ />
848
880
  ) : (
849
- <span {...slot("chip", chipDefault(theme))}>{event.title}</span>
881
+ <span
882
+ {...barChip}
883
+ style={{
884
+ ...barChip.style,
885
+ ...(b.continuesBefore
886
+ ? { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }
887
+ : null),
888
+ ...(b.continuesAfter
889
+ ? { borderTopRightRadius: 0, borderBottomRightRadius: 0 }
890
+ : null),
891
+ }}
892
+ >
893
+ {b.seg.event.title}
894
+ </span>
850
895
  )}
851
896
  </button>
852
- ))}
853
- </div>
854
- ) : null}
897
+ );
898
+ })}
899
+ <div
900
+ {...slot("events", {
901
+ base: { display: "flex", flexDirection: "column", gap: CHIP_GAP },
902
+ })}
903
+ >
904
+ {/* Reserve one row per visible lane so the absolute bars have
905
+ space and "+more" sits below them. */}
906
+ {Array.from({ length: visibleLanes }, (_, i) => (
907
+ <div key={`lane-${i}`} aria-hidden style={{ height: CHIP_HEIGHT }} />
908
+ ))}
909
+ {hiddenEvents.length > 0 ? (
910
+ <button
911
+ type="button"
912
+ // In built-in-popover mode, keep the document
913
+ // pointerdown dismiss from firing before this click's
914
+ // toggle, so pressing the button again closes it.
915
+ onPointerDown={onPressMore ? undefined : (e) => e.stopPropagation()}
916
+ onClick={(e) => {
917
+ e.stopPropagation();
918
+ if (onPressMore) onPressMore(hiddenEvents, day.date);
919
+ else {
920
+ moreTriggerRef.current = e.currentTarget;
921
+ setMoreOpenFor((open) => (open === day.id ? null : day.id));
922
+ }
923
+ }}
924
+ {...slot("more", moreButtonDefault(theme))}
925
+ aria-label={`${hiddenEvents.length} more events, ${dayLabel}`}
926
+ aria-expanded={onPressMore ? undefined : moreOpenFor === day.id}
927
+ >
928
+ {moreLabel.replace("{moreCount}", String(hiddenEvents.length))}
929
+ </button>
930
+ ) : null}
931
+ {moreOpenFor === day.id ? (
932
+ <div
933
+ ref={morePopoverRef}
934
+ // A non-modal dialog: Tab stays inside and Escape closes,
935
+ // but the page behind is not inert (outside clicks work),
936
+ // so no aria-modal claim.
937
+ role="dialog"
938
+ aria-label={dayLabel}
939
+ onPointerDown={(e) => e.stopPropagation()}
940
+ // Contain Tab inside the dialog; Escape (handled on the
941
+ // document) closes it and restores focus to the trigger.
942
+ onKeyDown={(e) => {
943
+ if (e.key !== "Tab") return;
944
+ const buttons =
945
+ morePopoverRef.current?.querySelectorAll<HTMLElement>("button");
946
+ if (!buttons?.length) return;
947
+ const first = buttons[0];
948
+ const last = buttons[buttons.length - 1];
949
+ if (e.shiftKey && document.activeElement === first) {
950
+ e.preventDefault();
951
+ last.focus();
952
+ } else if (!e.shiftKey && document.activeElement === last) {
953
+ e.preventDefault();
954
+ first.focus();
955
+ }
956
+ }}
957
+ {...slot("morePopover", {
958
+ base: {
959
+ position: "absolute",
960
+ top: 2,
961
+ left: 2,
962
+ right: 2,
963
+ zIndex: 10,
964
+ display: "flex",
965
+ flexDirection: "column",
966
+ gap: 2,
967
+ maxHeight: 240,
968
+ overflowY: "auto",
969
+ },
970
+ themed: {
971
+ background: theme.surface,
972
+ border: `1px solid ${theme.gridLine}`,
973
+ borderRadius: 8,
974
+ padding: 6,
975
+ boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
976
+ },
977
+ })}
978
+ >
979
+ <div style={{ fontSize: 11, fontWeight: 600, color: theme.textMuted }}>
980
+ {dayLabel}
981
+ </div>
982
+ {dayEvents.map((event, i) => (
983
+ <button
984
+ key={i}
985
+ type="button"
986
+ onClick={() => {
987
+ setMoreOpenFor(null);
988
+ onPressEvent?.(event);
989
+ }}
990
+ style={{
991
+ display: "block",
992
+ width: "100%",
993
+ border: "none",
994
+ background: "transparent",
995
+ padding: 0,
996
+ font: "inherit",
997
+ textAlign: "left",
998
+ cursor: "pointer",
999
+ }}
1000
+ >
1001
+ {Chip ? (
1002
+ <Chip event={event} onPress={() => onPressEvent?.(event)} />
1003
+ ) : (
1004
+ <span {...slot("chip", chipDefault(theme))}>{event.title}</span>
1005
+ )}
1006
+ </button>
1007
+ ))}
1008
+ </div>
1009
+ ) : null}
1010
+ </div>
855
1011
  </div>
856
- </div>
857
- );
858
- }
1012
+ );
1013
+ }
859
1014
 
860
- return (
861
- <button
862
- key={day.id}
863
- type="button"
864
- role="gridcell"
865
- data-day={day.id}
866
- {...dayData}
867
- tabIndex={day.id === focusKey ? 0 : -1}
868
- aria-disabled={day.isDisabled || undefined}
869
- aria-label={label}
870
- aria-pressed={day.isSelected || day.isInRange}
871
- {...slot("day", dayCellDefault(day, theme))}
872
- onClick={day.isDisabled ? undefined : () => onPressDay?.(day.date)}
873
- onMouseEnter={day.isDisabled ? undefined : () => setHoveredKey(day.id)}
874
- onMouseLeave={() => setHoveredKey((k) => (k === day.id ? null : k))}
875
- >
876
- {band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
877
- <span
1015
+ return (
1016
+ <button
1017
+ key={day.id}
1018
+ type="button"
1019
+ role="gridcell"
1020
+ data-day={day.id}
878
1021
  {...dayData}
879
- {...slot("dayBadge", badgeDefault(day, theme, hoveredKey === day.id))}
1022
+ tabIndex={day.id === focusKey ? 0 : -1}
1023
+ aria-disabled={day.isDisabled || undefined}
1024
+ aria-label={label}
1025
+ aria-pressed={day.isSelected || day.isInRange}
1026
+ {...slot("day", dayCellDefault(day, theme, highlightWeekends))}
1027
+ onClick={day.isDisabled ? undefined : () => onPressDay?.(day.date)}
1028
+ onMouseEnter={day.isDisabled ? undefined : () => setHoveredKey(day.id)}
1029
+ onMouseLeave={() => setHoveredKey((k) => (k === day.id ? null : k))}
880
1030
  >
881
- {day.label}
882
- </span>
883
- </button>
884
- );
885
- })}
886
- </div>
887
- ))}
1031
+ {band ? <span data-band aria-hidden {...slot("rangeBand", band)} /> : null}
1032
+ <span
1033
+ {...dayData}
1034
+ {...slot("dayBadge", badgeDefault(day, theme, hoveredKey === day.id))}
1035
+ >
1036
+ {day.label}
1037
+ </span>
1038
+ </button>
1039
+ );
1040
+ })}
1041
+ </div>
1042
+ );
1043
+ })}
888
1044
  </div>
889
1045
  </div>
890
1046
  );