@super-calendar/native 2.17.0 → 2.18.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.
@@ -1,9 +1,15 @@
1
+ import { useMemo } from "react";
1
2
  import { addDays, startOfDay } from "date-fns";
2
3
  import { type LayoutChangeEvent, StyleSheet, View } from "react-native";
3
4
  import { useCalendarTheme } from "../theme";
4
5
  import type { CalendarEvent, CalendarMode, EventKeyExtractor, RenderEvent } from "../types";
5
6
  import { useSlots } from "../utils/slots";
6
- import { isAllDayEvent, isBackgroundEvent } from "@super-calendar/core";
7
+ import {
8
+ isAllDayEvent,
9
+ isBackgroundEvent,
10
+ layoutMonthWeek,
11
+ type MonthEventSegment,
12
+ } from "@super-calendar/core";
7
13
 
8
14
  // The lane's slots are a subset of the TimeGrid slot union; typed locally so
9
15
  // this file doesn't import the full TimeGrid type.
@@ -25,7 +31,7 @@ type AllDayLaneProps<T> = {
25
31
  /**
26
32
  * The all-day lane of one page, pinned above the scrolling hours. All-day
27
33
  * events are excluded from the timed columns (see `layoutDayEvents`) and shown
28
- * here, stacked under their day(s). Always rendered so every page reports a
34
+ * here as continuous spans, stacked only when their dates overlap. Always rendered so every page reports a
29
35
  * height, zero when the week has none, which the band above the grid follows
30
36
  * live as you swipe; the "all-day" label lives in the hour column.
31
37
  */
@@ -44,60 +50,81 @@ export function AllDayLane<T>({
44
50
  const slot = useSlots<AllDayLaneSlot>();
45
51
  const RenderEventComponent = renderEvent;
46
52
 
47
- // Background events shade the timed columns instead of taking a lane chip.
48
- const allDay = events.filter((event) => isAllDayEvent(event) && !isBackgroundEvent(event));
49
- const perDay = days.map((day) => {
50
- const start = startOfDay(day);
51
- const next = addDays(start, 1);
52
- return allDay.filter((event) => event.start < next && event.end > start);
53
- });
53
+ const spans = useMemo(() => {
54
+ const allDay = events.filter(
55
+ (event) =>
56
+ isAllDayEvent(event) &&
57
+ !isBackgroundEvent(event) &&
58
+ days.some(
59
+ (day) => event.start < addDays(startOfDay(day), 1) && event.end > startOfDay(day),
60
+ ),
61
+ );
62
+ const { segments, laneCount } = layoutMonthWeek(days, allDay);
63
+ const lanes: MonthEventSegment<T>[][] = Array.from({ length: laneCount }, () => []);
64
+ for (const segment of segments) lanes[segment.lane].push(segment);
65
+ return lanes.flat();
66
+ }, [days, events]);
54
67
 
55
68
  return (
56
69
  <View
57
70
  {...slot("allDayLane", {
58
- base: styles.lane,
71
+ base: [styles.lane, spans.length > 0 && { paddingVertical: 2 }],
59
72
  themed: theme.containers.allDayLane,
60
73
  })}
61
74
  onLayout={onLayout}
62
75
  >
63
- {perDay.every((list) => list.length === 0)
64
- ? null
65
- : days.map((day, dayIndex) => (
66
- <View
67
- key={day.toISOString()}
68
- {...slot("allDayColumn", {
69
- base: [styles.column, { width: dayWidth }],
70
- themed: theme.containers.allDayColumn,
71
- })}
72
- >
73
- {perDay[dayIndex].map((event, index) => (
74
- <View
75
- key={keyExtractor(event, index)}
76
- {...slot("allDayEvent", { base: styles.chip })}
77
- >
78
- <RenderEventComponent
79
- event={event}
80
- mode={mode}
81
- isAllDay
82
- onPress={() => onPressEvent(event)}
83
- onLongPress={onLongPressEvent ? () => onLongPressEvent(event) : undefined}
84
- />
85
- </View>
86
- ))}
76
+ {spans.map((segment, index) => {
77
+ const { event, startCol, endCol, lane, continuesBefore, continuesAfter } = segment;
78
+ const previous = spans[index - 1];
79
+ const previousEnd = previous?.lane === lane ? previous.endCol : -1;
80
+ const lastInLane = spans[index + 1]?.lane !== lane;
81
+ const remaining = lastInLane ? days.length - endCol - 1 : 0;
82
+ // Yoga wraps before pixel rounding. Leave subpixel slack at the row end
83
+ // so float32 accumulation cannot push a bar onto the following line.
84
+ const wrapSlack = lastInLane ? Math.min(0.5, dayWidth / 4) : 0;
85
+ return (
86
+ <View
87
+ key={keyExtractor(event, index)}
88
+ {...slot("allDayColumn", {
89
+ base: [
90
+ styles.column,
91
+ {
92
+ width: dayWidth * (endCol - startCol + 1),
93
+ marginLeft: dayWidth * (startCol - previousEnd - 1),
94
+ marginRight: dayWidth * remaining - wrapSlack,
95
+ },
96
+ ],
97
+ themed: theme.containers.allDayColumn,
98
+ })}
99
+ >
100
+ <View {...slot("allDayEvent", { base: styles.chip })}>
101
+ <RenderEventComponent
102
+ event={event}
103
+ mode={mode}
104
+ isAllDay
105
+ continuesBefore={continuesBefore}
106
+ continuesAfter={continuesAfter}
107
+ onPress={() => onPressEvent(event)}
108
+ onLongPress={onLongPressEvent ? () => onLongPressEvent(event) : undefined}
109
+ />
87
110
  </View>
88
- ))}
111
+ </View>
112
+ );
113
+ })}
89
114
  </View>
90
115
  );
91
116
  }
92
117
 
93
118
  const styles = StyleSheet.create({
94
119
  lane: {
120
+ // Keep keyed events as siblings so changing lanes preserves renderer state.
95
121
  flexDirection: "row",
122
+ flexWrap: "wrap",
123
+ alignItems: "flex-start",
124
+ rowGap: 2,
96
125
  },
97
126
  column: {
98
- paddingVertical: 2,
99
127
  paddingHorizontal: 1,
100
- gap: 2,
101
128
  },
102
129
  chip: {
103
130
  minHeight: 18,
@@ -42,6 +42,10 @@ import {
42
42
  type DateRange,
43
43
  type EventAccessibilityLabeler,
44
44
  eventsInTimeZone,
45
+ fromZonedRange,
46
+ fromZonedTime,
47
+ zonedDragBounds,
48
+ zonedEventSource,
45
49
  expandRecurringEvents,
46
50
  type WeekdayFormat,
47
51
  getViewDays,
@@ -143,8 +147,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
143
147
  */
144
148
  onCreateEvent?: (start: Date, end: Date) => void;
145
149
  /**
146
- * A component that draws content inside the time-grid drag-to-create preview;
147
- * see `TimeGrid`'s prop of the same name. Applies to the week/day grid only.
150
+ * Content inside the drag-to-create preview in time grids, month, and multiweek.
151
+ * Month grids receive an all-day range with an exclusive end, repeated for
152
+ * each row the span covers. Requires `onCreateEvent`.
148
153
  */
149
154
  renderCreateGhost?: ComponentType<CreateGhostArgs>;
150
155
  /**
@@ -196,9 +201,10 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
196
201
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
197
202
  hiddenDays?: number[];
198
203
  /**
199
- * Fixed "now" instant for the current-time indicator (doesn't tick), e.g. a
200
- * server-synced clock. Defaults to the device clock, shifted into `timeZone`
201
- * when one is set so the line matches the displayed events.
204
+ * Fixed "now" instant for the current-time indicator (doesn't tick) and for
205
+ * the day highlighted as today in every mode, e.g. a server-synced clock.
206
+ * Defaults to the device clock, shifted into `timeZone` when one is set so
207
+ * both match the displayed events.
202
208
  */
203
209
  now?: Date;
204
210
  /** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
@@ -347,7 +353,9 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
347
353
  /**
348
354
  * Display events in this IANA time zone (e.g. `"America/New_York"`), DST-correct
349
355
  * and independent of the device zone. Display-only: it shifts the wall-clock the
350
- * grid lays out from, it doesn't change your `Date`s. Uses `eventsInTimeZone`.
356
+ * grid lays out from, it doesn't change your `Date`s, and callbacks report your
357
+ * own events and real instants. All-day events stay on their days. Uses
358
+ * `eventsInTimeZone`.
351
359
  */
352
360
  timeZone?: string;
353
361
  /** Highlight this date (header/cell/agenda) instead of the real "today". */
@@ -609,7 +617,7 @@ function CalendarInner<T>(
609
617
  const displayEvents = useMemo(() => {
610
618
  let out = events;
611
619
  if (out.some((e) => e.recurrence)) {
612
- let [start, end] = expansionRange(
620
+ const [start, end] = expansionRange(
613
621
  mode,
614
622
  date,
615
623
  weekStartsOn,
@@ -617,13 +625,13 @@ function CalendarInner<T>(
617
625
  weekEndsOn,
618
626
  numberOfWeeks,
619
627
  );
620
- // A display zone shifts each occurrence's wall-clock by up to ~a day, which
621
- // can move an edge occurrence into a visible column; widen so it's generated.
622
- if (timeZone) {
623
- start = addDays(start, -1);
624
- end = addDays(end, 1);
625
- }
626
- out = expandRecurringEvents(out, start, end);
628
+ // The range is the days on screen, which under a display zone are that
629
+ // zone's days: expand on its clock, over the instants those days cover.
630
+ out = timeZone
631
+ ? expandRecurringEvents(out, fromZonedTime(start, timeZone), fromZonedTime(end, timeZone), {
632
+ timeZone,
633
+ })
634
+ : expandRecurringEvents(out, start, end);
627
635
  }
628
636
  if (timeZone) out = eventsInTimeZone(out, timeZone);
629
637
  return out;
@@ -640,22 +648,81 @@ function CalendarInner<T>(
640
648
  ]);
641
649
 
642
650
  // Swallow presses on disabled events once, so every view inherits the guard.
651
+ // With a display zone the views hold wall-clock copies of the events, so hand
652
+ // back the consumer's own event. Without one, events pass through untouched,
653
+ // including copies the consumer zoned themselves.
643
654
  const handlePressEvent = useCallback(
644
655
  (event: CalendarEvent<T>) => {
645
- if (!event.disabled) onPressEvent(event);
656
+ if (!event.disabled) onPressEvent(timeZone ? zonedEventSource(event) : event);
646
657
  },
647
- [onPressEvent],
658
+ [onPressEvent, timeZone],
648
659
  );
649
660
  const handleLongPressEvent = useMemo(
650
661
  () =>
651
662
  onLongPressEvent
652
663
  ? (event: CalendarEvent<T>) => {
653
- if (!event.disabled) onLongPressEvent(event);
664
+ if (!event.disabled) onLongPressEvent(timeZone ? zonedEventSource(event) : event);
654
665
  }
655
666
  : undefined,
656
- [onLongPressEvent],
667
+ [onLongPressEvent, timeZone],
657
668
  );
658
669
 
670
+ // The views also report wall-clock dates under a display zone. Convert them to
671
+ // real instants. Whole days (`onPressDay`, a month sweep, ...) stay
672
+ // device-local dates, as `date` is, so only the time grid's cell callbacks
673
+ // convert.
674
+ // A time-grid move keeps the event's elapsed duration; a month drop keeps the
675
+ // clock time of both edges.
676
+ const timeGridMode = mode !== "month" && mode !== "multiweek";
677
+ const zoned = useMemo(() => {
678
+ if (!timeZone) {
679
+ return {
680
+ onDragStart,
681
+ onDragEvent,
682
+ onPressMore,
683
+ onPressTime: onPressCell,
684
+ onLongPressTime: onLongPressCell,
685
+ onCreateTimed: onCreateEvent,
686
+ };
687
+ }
688
+ const instant = (wallClock: Date) => fromZonedTime(wallClock, timeZone);
689
+ return {
690
+ onDragStart:
691
+ onDragStart && ((event: CalendarEvent<T>) => onDragStart(zonedEventSource(event))),
692
+ onDragEvent:
693
+ onDragEvent &&
694
+ ((event: CalendarEvent<T>, start: Date, end: Date) => {
695
+ const bounds = zonedDragBounds(event, start, end, { keepDuration: timeGridMode });
696
+ // An edge dropped into an hour the zone's clock skips can leave no
697
+ // usable span; reject the drop, so the event snaps back.
698
+ if (!bounds) return false;
699
+ return onDragEvent(zonedEventSource(event), bounds.start, bounds.end);
700
+ }),
701
+ onPressMore:
702
+ onPressMore &&
703
+ ((dayEvents: CalendarEvent<T>[], day: Date) =>
704
+ onPressMore(dayEvents.map(zonedEventSource), day)),
705
+ onPressTime: onPressCell && ((time: Date) => onPressCell(instant(time))),
706
+ onLongPressTime: onLongPressCell && ((time: Date) => onLongPressCell(instant(time))),
707
+ onCreateTimed:
708
+ onCreateEvent &&
709
+ ((start: Date, end: Date) => {
710
+ // A sweep that collapses inside a skipped hour creates nothing.
711
+ const range = fromZonedRange(start, end, timeZone);
712
+ if (range) onCreateEvent(range.start, range.end);
713
+ }),
714
+ };
715
+ }, [
716
+ timeZone,
717
+ timeGridMode,
718
+ onDragStart,
719
+ onDragEvent,
720
+ onPressMore,
721
+ onPressCell,
722
+ onLongPressCell,
723
+ onCreateEvent,
724
+ ]);
725
+
659
726
  // Echo every date change and, when asked, the full visible range derived from it.
660
727
  const handleChangeDate = useCallback(
661
728
  (next: Date) => {
@@ -760,6 +827,8 @@ function CalendarInner<T>(
760
827
  hiddenDays={hiddenDays}
761
828
  weekdayFormat={weekdayFormat}
762
829
  locale={locale}
830
+ now={now}
831
+ timeZone={timeZone}
763
832
  labels={labels}
764
833
  sortedMonthView={sortedMonthView}
765
834
  moreLabel={moreLabel}
@@ -778,11 +847,12 @@ function CalendarInner<T>(
778
847
  onPressCell={onPressCell}
779
848
  onPressEvent={handlePressEvent}
780
849
  onLongPressEvent={handleLongPressEvent}
781
- onPressMore={onPressMore}
850
+ onPressMore={zoned.onPressMore}
782
851
  onCreateEvent={onCreateEvent}
852
+ renderCreateGhost={renderCreateGhost}
783
853
  onSelectDrag={onSelectDrag}
784
- onDragEvent={onDragEvent}
785
- onDragStart={onDragStart}
854
+ onDragEvent={zoned.onDragEvent}
855
+ onDragStart={zoned.onDragStart}
786
856
  eventStartEditable={eventStartEditable}
787
857
  eventOverlap={eventOverlap}
788
858
  selectedDates={selectedDates}
@@ -805,6 +875,8 @@ function CalendarInner<T>(
805
875
  weekStartsOn={weekStartsOn}
806
876
  hiddenDays={hiddenDays}
807
877
  locale={locale}
878
+ now={now}
879
+ timeZone={timeZone}
808
880
  labels={labels}
809
881
  activeDate={activeDate}
810
882
  selectedDates={selectedDates}
@@ -823,6 +895,8 @@ function CalendarInner<T>(
823
895
  <Agenda
824
896
  events={displayEvents}
825
897
  locale={locale}
898
+ now={now}
899
+ timeZone={timeZone}
826
900
  renderEvent={resolvedRenderEvent}
827
901
  keyExtractor={keyExtractor}
828
902
  onPressEvent={handlePressEvent}
@@ -888,14 +962,14 @@ function CalendarInner<T>(
888
962
  swipeEnabled={swipeEnabled}
889
963
  onPressEvent={handlePressEvent}
890
964
  onLongPressEvent={handleLongPressEvent}
891
- onDragEvent={onDragEvent}
965
+ onDragEvent={zoned.onDragEvent}
892
966
  showDragHandle={showDragHandle}
893
- onDragStart={onDragStart}
967
+ onDragStart={zoned.onDragStart}
894
968
  dragStepMinutes={dragStepMinutes}
895
- onPressCell={onPressCell}
969
+ onPressCell={zoned.onPressTime}
896
970
  resetPageOnPressCell={resetPageOnPressCell}
897
- onLongPressCell={onLongPressCell}
898
- onCreateEvent={onCreateEvent}
971
+ onLongPressCell={zoned.onLongPressTime}
972
+ onCreateEvent={zoned.onCreateTimed}
899
973
  renderCreateGhost={renderCreateGhost}
900
974
  onPressDateHeader={onPressDateHeader}
901
975
  onChangeDate={handleChangeDate}
@@ -17,6 +17,7 @@ import {
17
17
  } from "date-fns";
18
18
  import {
19
19
  type ComponentRef,
20
+ type ComponentType,
20
21
  memo,
21
22
  type ReactElement,
22
23
  useCallback,
@@ -46,6 +47,7 @@ import type {
46
47
  } from "../types";
47
48
  import {
48
49
  type CalendarSelection,
50
+ type CreateGhostArgs,
49
51
  CalendarSelectionProvider,
50
52
  buildMultiWeekGrid,
51
53
  type DateRange,
@@ -86,6 +88,8 @@ export type MonthPagerProps<T> = {
86
88
  hiddenDays?: number[];
87
89
  weekdayFormat?: WeekdayFormat;
88
90
  locale?: Locale;
91
+ now?: Date;
92
+ timeZone?: string;
89
93
  sortedMonthView?: boolean;
90
94
  moreLabel?: string;
91
95
  /** Translations for the screen-reader words and gutter text; omitted keys use English. */
@@ -106,6 +110,8 @@ export type MonthPagerProps<T> = {
106
110
  onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
107
111
  /** Drag across empty day cells to sweep out an all-day span for a new event. */
108
112
  onCreateEvent?: (start: Date, end: Date) => void;
113
+ /** Content for each row of the live creation preview; requires `onCreateEvent`. */
114
+ renderCreateGhost?: ComponentType<CreateGhostArgs>;
109
115
  /** Drag-to-select: reports the swept `[start, end]` days live. */
110
116
  onSelectDrag?: (start: Date, end: Date) => void;
111
117
  /** Days drawn as selected (a filled badge). */
@@ -185,6 +191,8 @@ function DateRowsPagerInner<T>({
185
191
  hiddenDays,
186
192
  weekdayFormat = "short",
187
193
  locale,
194
+ now,
195
+ timeZone,
188
196
  sortedMonthView,
189
197
  moreLabel,
190
198
  labels,
@@ -201,6 +209,7 @@ function DateRowsPagerInner<T>({
201
209
  onLongPressEvent,
202
210
  onPressMore,
203
211
  onCreateEvent,
212
+ renderCreateGhost,
204
213
  onSelectDrag,
205
214
  selectedDates,
206
215
  selectedRange,
@@ -370,16 +379,37 @@ function DateRowsPagerInner<T>({
370
379
  // `fillCellOnSelection` and `onSelectDrag` ride along because they reach the
371
380
  // grids as renderItem props, not through the selection context below: toggling
372
381
  // a "pick dates" mode on must reach the pages already rendered.
382
+ // `now` and `timeZone` move the today highlight on the pages already rendered.
383
+ const nowTime = now?.getTime();
373
384
  const monthExtraData = useMemo(
374
385
  () => ({
375
386
  events,
376
387
  activeDate,
388
+ nowTime,
389
+ timeZone,
377
390
  fillCellOnSelection,
378
391
  dragSelect: onSelectDrag != null,
379
392
  chipHeight,
380
393
  chipGap,
394
+ renderCreateGhost,
395
+ onCreateEvent,
396
+ createGhostClassName: classNames?.createGhost,
397
+ createGhostStyle: styleOverrides?.createGhost,
381
398
  }),
382
- [events, activeDate, fillCellOnSelection, onSelectDrag, chipHeight, chipGap],
399
+ [
400
+ events,
401
+ activeDate,
402
+ nowTime,
403
+ timeZone,
404
+ fillCellOnSelection,
405
+ onSelectDrag,
406
+ chipHeight,
407
+ chipGap,
408
+ renderCreateGhost,
409
+ onCreateEvent,
410
+ classNames?.createGhost,
411
+ styleOverrides?.createGhost,
412
+ ],
383
413
  );
384
414
 
385
415
  // Selection reaches the grids through context, not `renderItem`, so a change
@@ -423,6 +453,8 @@ function DateRowsPagerInner<T>({
423
453
  weekStartsOn={weekStartsOn}
424
454
  hiddenDays={hiddenDays}
425
455
  locale={locale}
456
+ now={now}
457
+ timeZone={timeZone}
426
458
  sortedMonthView={sortedMonthView}
427
459
  moreLabel={moreLabel}
428
460
  labels={labels}
@@ -440,6 +472,7 @@ function DateRowsPagerInner<T>({
440
472
  onLongPressEvent={onLongPressEvent}
441
473
  onPressMore={onPressMore}
442
474
  onCreateEvent={onCreateEvent}
475
+ renderCreateGhost={renderCreateGhost}
443
476
  onSelectDrag={onSelectDrag}
444
477
  fillCellOnSelection={fillCellOnSelection}
445
478
  onDragEvent={onDragEvent}
@@ -462,6 +495,8 @@ function DateRowsPagerInner<T>({
462
495
  weekStartsOn,
463
496
  hiddenDays,
464
497
  locale,
498
+ now,
499
+ timeZone,
465
500
  sortedMonthView,
466
501
  moreLabel,
467
502
  labels,
@@ -480,6 +515,7 @@ function DateRowsPagerInner<T>({
480
515
  onLongPressEvent,
481
516
  onPressMore,
482
517
  onCreateEvent,
518
+ renderCreateGhost,
483
519
  onSelectDrag,
484
520
  fillCellOnSelection,
485
521
  onDragEvent,
@@ -1,6 +1,7 @@
1
1
  import { addDays, format, type Locale, isSameMonth, startOfDay } from "date-fns";
2
2
  import {
3
3
  type ComponentRef,
4
+ type ComponentType,
4
5
  memo,
5
6
  type ReactElement,
6
7
  useCallback,
@@ -30,6 +31,8 @@ import { Gesture, GestureDetector } from "react-native-gesture-handler";
30
31
  // Web drag-to-select relays cell pointer events up to MonthList; native drag is
31
32
  // driven by a list-level pan there instead.
32
33
  const isWeb = Platform.OS === "web";
34
+ // React 18 forwards the canonical string; React 19 treats it as a boolean attribute.
35
+ const webPreviewProps = isWeb ? { "aria-hidden": true, inert: "inert" } : {};
33
36
  import { useCalendarTheme } from "../theme";
34
37
  import type {
35
38
  CalendarEvent,
@@ -45,6 +48,7 @@ import { holdWebDateDrag } from "../utils/holdWebDateDrag";
45
48
  import { CalendarLabelsContext } from "../utils/labels";
46
49
  import {
47
50
  type CalendarLabels,
51
+ type CreateGhostArgs,
48
52
  type DateRange,
49
53
  type EventAccessibilityLabeler,
50
54
  dayAccessibilityLabel,
@@ -60,6 +64,7 @@ import {
60
64
  buildMonthWeeks,
61
65
  buildMultiWeekGrid,
62
66
  getIsToday,
67
+ nowInTimeZone,
63
68
  filterHiddenDays,
64
69
  getWeekDays,
65
70
  isSameCalendarDay,
@@ -153,6 +158,7 @@ export type MonthViewSlot =
153
158
  | "dayBadge"
154
159
  | "dayBadgeText"
155
160
  | "rangeBand"
161
+ | "createGhost"
156
162
  | "more"
157
163
  | "morePopover";
158
164
 
@@ -180,6 +186,13 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
180
186
  /** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
181
187
  weekdayFormat?: WeekdayFormat;
182
188
  locale?: Locale;
189
+ /**
190
+ * The instant whose calendar day is highlighted as today. Defaults to the
191
+ * device clock, and is read in `timeZone` when one is set.
192
+ */
193
+ now?: Date;
194
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
195
+ timeZone?: string;
183
196
  /** Sort each day's events by start time before slicing. Default true. */
184
197
  sortedMonthView?: boolean;
185
198
  /** Template for the overflow label; `{moreCount}` is replaced. Default "{moreCount} More". */
@@ -249,6 +262,14 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
249
262
  * plain tap fires `onPressDay`/`onPressCell` instead.
250
263
  */
251
264
  onCreateEvent?: (start: Date, end: Date) => void;
265
+ /**
266
+ * Content inside the drag-to-create preview. Receives the full all-day range,
267
+ * with an exclusive end, that `onCreateEvent` would receive on release. A span
268
+ * crossing rows renders the component once per row with the same range.
269
+ * Requires `onCreateEvent`; content is clipped, noninteractive, and hidden
270
+ * from screen readers. Omit to keep the day highlight without preview content.
271
+ */
272
+ renderCreateGhost?: ComponentType<CreateGhostArgs>;
252
273
  /**
253
274
  * Reports the day span of a create sweep **as it happens**, as the ordered
254
275
  * inclusive `[start, end]` days (both at midnight), so a selection highlight can
@@ -324,6 +345,8 @@ function DateRowsInner<T>({
324
345
  hiddenDays,
325
346
  weekdayFormat = "short",
326
347
  locale,
348
+ now,
349
+ timeZone,
327
350
  sortedMonthView = true,
328
351
  moreLabel = "{moreCount} More",
329
352
  labels: labelsProp,
@@ -350,6 +373,7 @@ function DateRowsInner<T>({
350
373
  onLongPressEvent,
351
374
  onPressMore,
352
375
  onCreateEvent,
376
+ renderCreateGhost: RenderCreateGhost,
353
377
  onSelectDrag,
354
378
  onDragEvent,
355
379
  onDragStart,
@@ -400,6 +424,7 @@ function DateRowsInner<T>({
400
424
  events: CalendarEvent<T>[];
401
425
  } | null>(null);
402
426
 
427
+ const today = nowInTimeZone(now, timeZone);
403
428
  const multiWeekGrid = useMemo(
404
429
  () =>
405
430
  numberOfWeeks === undefined
@@ -471,9 +496,10 @@ function DateRowsInner<T>({
471
496
  return map;
472
497
  }, [events, sortedMonthView]);
473
498
 
474
- // Draw the day-cell grid only for an events calendar; the events-free date
475
- // picker reads cleaner without it (matching the dom renderer).
476
- const showGrid = multiWeek || events.length > 0;
499
+ // Custom drafts need event lanes before the first event exists. Keep the
500
+ // events-free picker layout when no creation content is requested.
501
+ const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
502
+ const showGrid = multiWeek || events.length > 0 || createContentEnabled;
477
503
 
478
504
  // Lay out each week row's spanning bars once per data change, not per render.
479
505
  const weekLayouts = useMemo(
@@ -493,6 +519,13 @@ function DateRowsInner<T>({
493
519
  // pointer listeners read, so neither has to be rebuilt as the hover day moves
494
520
  // (rebuilding the gesture mid-drag would cancel it).
495
521
  const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
522
+ const createRange = useMemo(
523
+ () =>
524
+ createContentEnabled && drag?.kind === "create"
525
+ ? monthCreateRange(drag.anchor, drag.hover)
526
+ : null,
527
+ [createContentEnabled, drag],
528
+ );
496
529
  const dragRef = useRef<MonthDrag<T> | null>(null);
497
530
  const interactionWindow = useRef(windowKey);
498
531
  interactionWindow.current = windowKey;
@@ -827,7 +860,7 @@ function DateRowsInner<T>({
827
860
  }
828
861
 
829
862
  const dayEvents = eventsByDay.get(startOfDay(day).toISOString()) ?? [];
830
- const isToday = getIsToday(day);
863
+ const isToday = getIsToday(day, today);
831
864
  // Highlight the chosen `activeDate` when supplied, else the real today.
832
865
  const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
833
866
  // Selection band wins over the weekend tint; the today badge shows unless the
@@ -1204,6 +1237,24 @@ function DateRowsInner<T>({
1204
1237
  cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
1205
1238
  }
1206
1239
  }
1240
+ const draftColumns = createRange
1241
+ ? week.flatMap((day, index) =>
1242
+ (showAdjacentMonths || isSameMonth(day, date)) &&
1243
+ day >= createRange.start &&
1244
+ day < createRange.end
1245
+ ? [index]
1246
+ : [],
1247
+ )
1248
+ : [];
1249
+ const draftStart = draftColumns[0];
1250
+ const draftEnd = draftColumns.at(-1);
1251
+ // Overlay a free lane when possible, without moving cells under the drag.
1252
+ const draftLane = Math.min(visibleLanes, Math.max(0, capacity.full - 1));
1253
+ const draftTop = badgeArea + draftLane * chipMetrics.chipRowHeight;
1254
+ const draftHeight = Math.min(
1255
+ chipMetrics.chipHeight,
1256
+ Math.max(0, gridHeight / weeks.length - draftTop),
1257
+ );
1207
1258
  return (
1208
1259
  <View
1209
1260
  {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
@@ -1270,6 +1321,40 @@ function DateRowsInner<T>({
1270
1321
  </View>
1271
1322
  );
1272
1323
  })}
1324
+ {RenderCreateGhost &&
1325
+ createRange &&
1326
+ draftStart !== undefined &&
1327
+ draftEnd !== undefined &&
1328
+ draftHeight > 0 ? (
1329
+ <View
1330
+ testID="month-create-ghost"
1331
+ {...slot("createGhost", {
1332
+ base: {
1333
+ position: "absolute",
1334
+ left: pct((draftStart / cols) * 100),
1335
+ right: pct(((cols - 1 - draftEnd) / cols) * 100),
1336
+ top: draftTop,
1337
+ height: draftHeight,
1338
+ marginHorizontal: CHIP_INSET_H,
1339
+ overflow: "hidden",
1340
+ zIndex: 1,
1341
+ },
1342
+ themed: {
1343
+ backgroundColor: theme.colors.rangeBackground,
1344
+ borderColor: theme.colors.selectedBackground,
1345
+ borderWidth: 1,
1346
+ borderRadius: 4,
1347
+ },
1348
+ })}
1349
+ {...webPreviewProps}
1350
+ pointerEvents="none"
1351
+ accessible={false}
1352
+ accessibilityElementsHidden
1353
+ importantForAccessibility="no-hide-descendants"
1354
+ >
1355
+ <RenderCreateGhost start={createRange.start} end={createRange.end} />
1356
+ </View>
1357
+ ) : null}
1273
1358
  </View>
1274
1359
  ) : null}
1275
1360
  </View>