@super-calendar/native 2.12.1 → 2.14.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.
@@ -12,7 +12,16 @@ import {
12
12
  startOfWeek,
13
13
  startOfYear,
14
14
  } from "date-fns";
15
- import { type ReactElement, useCallback, useMemo } from "react";
15
+ import {
16
+ type ForwardedRef,
17
+ forwardRef,
18
+ type ReactElement,
19
+ type RefAttributes,
20
+ useCallback,
21
+ useImperativeHandle,
22
+ useMemo,
23
+ useRef,
24
+ } from "react";
16
25
  import type { ScrollViewProps, StyleProp, ViewStyle } from "react-native";
17
26
  import { useSharedValue } from "react-native-reanimated";
18
27
  import { CalendarThemeProvider, mergeTheme, type PartialCalendarTheme } from "../theme";
@@ -34,7 +43,11 @@ import {
34
43
  type WeekdayFormat,
35
44
  getViewDays,
36
45
  } from "@super-calendar/core";
37
- import { type CalendarLabels, resolveCalendarLabels } from "@super-calendar/core";
46
+ import {
47
+ type CalendarHandle,
48
+ type CalendarLabels,
49
+ resolveCalendarLabels,
50
+ } from "@super-calendar/core";
38
51
  import { CalendarLabelsContext } from "../utils/labels";
39
52
  import { type SlotStyleProps } from "../utils/slots";
40
53
  import { YearView, type YearViewSlot } from "./YearView";
@@ -156,6 +169,10 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
156
169
  * fixed cap. Pass an explicit value when using a custom `renderEvent`.
157
170
  */
158
171
  maxVisibleEventCount?: number;
172
+ /** Month chip height in pixels; omit to keep the renderer default. */
173
+ chipHeight?: number;
174
+ /** Gap between month chip rows in pixels (default 2). */
175
+ chipGap?: number;
159
176
  /** Sort each month day's events by start. Default true. */
160
177
  sortedMonthView?: boolean;
161
178
  /** Month overflow label template; `{moreCount}` is replaced. Default "{moreCount} More". */
@@ -311,7 +328,7 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
311
328
  ellipsizeTitle?: boolean;
312
329
  /** Label the built-in renderer shows for an all-day event in the schedule (and its screen-reader text). Default "All day". */
313
330
  allDayLabel?: string;
314
- /** Initial vertical scroll, in minutes from midnight (week/day). */
331
+ /** Vertical scroll, in minutes from midnight (week/day). Applied on mount and whenever it changes. */
315
332
  scrollOffsetMinutes?: number;
316
333
  /** Show the current-time line on the week/day grid. Default true. */
317
334
  showNowIndicator?: boolean;
@@ -442,103 +459,120 @@ function expansionRange(
442
459
  * }
443
460
  * ```
444
461
  */
445
- export function Calendar<T>({
446
- events,
447
- mode,
448
- date,
449
- onChangeDate,
450
- onChangeDateRange,
451
- onPressEvent,
452
- onLongPressEvent,
453
- onDragEvent,
454
- onDragStart,
455
- dragStepMinutes,
456
- showDragHandle,
457
- onPressDay,
458
- onPressMonth,
459
- onLongPressDay,
460
- onPressMore,
461
- onPressCell,
462
- resetPageOnPressCell,
463
- onLongPressCell,
464
- onCreateEvent,
465
- onSelectDrag,
466
- selectedDates,
467
- selectedRange,
468
- fillCellOnSelection,
469
- minDate,
470
- maxDate,
471
- isDateDisabled,
472
- onPressDateHeader,
473
- maxVisibleEventCount,
474
- sortedMonthView,
475
- moreLabel,
476
- labels,
477
- showAdjacentMonths,
478
- disableMonthEventCellPress,
479
- weekStartsOn = 0,
480
- hiddenDays,
481
- now,
482
- weekdayFormat,
483
- numberOfDays,
484
- weekEndsOn,
485
- renderEvent = DefaultEvent,
486
- eventAccessibilityLabel,
487
- eventCellStyle,
488
- calendarCellStyle,
489
- businessHours,
490
- renderBusinessHours,
491
- renderBackgroundEvent,
492
- keyExtractor = defaultKeyExtractor as EventKeyExtractor<T>,
493
- theme,
494
- cellHeight: cellHeightProp,
495
- hourHeight = DEFAULT_HOUR_HEIGHT,
496
- minHourHeight,
497
- maxHourHeight,
498
- minEventHeight,
499
- eventGap,
500
- hourColumnWidth,
501
- hideHours,
502
- timeslots,
503
- showAllDayEventCell,
504
- showAllDayLabel,
505
- refreshControl,
506
- highlightWeekends,
507
- eventStartEditable,
508
- eventDurationEditable,
509
- eventOverlap,
510
- showWeekNumber,
511
- weekNumberPrefix,
512
- hourComponent,
513
- showSixWeeks,
514
- showTitle,
515
- swipeEnabled,
516
- showVerticalScrollIndicator,
517
- verticalScrollEnabled,
518
- headerComponent,
519
- minHour,
520
- maxHour,
521
- ampm,
522
- showTime,
523
- ellipsizeTitle,
524
- allDayLabel,
525
- scrollOffsetMinutes,
526
- showNowIndicator,
527
- locale,
528
- timeZone,
529
- activeDate,
530
- isRTL,
531
- freeSwipe,
532
- renderTimeGridHeader,
533
- renderHeaderForMonthView,
534
- renderCustomDateForMonth,
535
- itemSeparatorComponent,
536
- classNames,
537
- styles: styleOverrides,
538
- }: CalendarProps<T>): ReactElement {
462
+ export const Calendar = forwardRef(CalendarInner) as <T>(
463
+ props: CalendarProps<T> & RefAttributes<CalendarHandle>,
464
+ ) => ReactElement;
465
+
466
+ function CalendarInner<T>(
467
+ {
468
+ events,
469
+ mode,
470
+ date,
471
+ onChangeDate,
472
+ onChangeDateRange,
473
+ onPressEvent,
474
+ onLongPressEvent,
475
+ onDragEvent,
476
+ onDragStart,
477
+ dragStepMinutes,
478
+ showDragHandle,
479
+ onPressDay,
480
+ onPressMonth,
481
+ onLongPressDay,
482
+ onPressMore,
483
+ onPressCell,
484
+ resetPageOnPressCell,
485
+ onLongPressCell,
486
+ onCreateEvent,
487
+ onSelectDrag,
488
+ selectedDates,
489
+ selectedRange,
490
+ fillCellOnSelection,
491
+ minDate,
492
+ maxDate,
493
+ isDateDisabled,
494
+ onPressDateHeader,
495
+ maxVisibleEventCount,
496
+ chipHeight,
497
+ chipGap,
498
+ sortedMonthView,
499
+ moreLabel,
500
+ labels,
501
+ showAdjacentMonths,
502
+ disableMonthEventCellPress,
503
+ weekStartsOn = 0,
504
+ hiddenDays,
505
+ now,
506
+ weekdayFormat,
507
+ numberOfDays,
508
+ weekEndsOn,
509
+ renderEvent = DefaultEvent,
510
+ eventAccessibilityLabel,
511
+ eventCellStyle,
512
+ calendarCellStyle,
513
+ businessHours,
514
+ renderBusinessHours,
515
+ renderBackgroundEvent,
516
+ keyExtractor = defaultKeyExtractor as EventKeyExtractor<T>,
517
+ theme,
518
+ cellHeight: cellHeightProp,
519
+ hourHeight = DEFAULT_HOUR_HEIGHT,
520
+ minHourHeight,
521
+ maxHourHeight,
522
+ minEventHeight,
523
+ eventGap,
524
+ hourColumnWidth,
525
+ hideHours,
526
+ timeslots,
527
+ showAllDayEventCell,
528
+ showAllDayLabel,
529
+ refreshControl,
530
+ highlightWeekends,
531
+ eventStartEditable,
532
+ eventDurationEditable,
533
+ eventOverlap,
534
+ showWeekNumber,
535
+ weekNumberPrefix,
536
+ hourComponent,
537
+ showSixWeeks,
538
+ showTitle,
539
+ swipeEnabled,
540
+ showVerticalScrollIndicator,
541
+ verticalScrollEnabled,
542
+ headerComponent,
543
+ minHour,
544
+ maxHour,
545
+ ampm,
546
+ showTime,
547
+ ellipsizeTitle,
548
+ allDayLabel,
549
+ scrollOffsetMinutes,
550
+ showNowIndicator,
551
+ locale,
552
+ timeZone,
553
+ activeDate,
554
+ isRTL,
555
+ freeSwipe,
556
+ renderTimeGridHeader,
557
+ renderHeaderForMonthView,
558
+ renderCustomDateForMonth,
559
+ itemSeparatorComponent,
560
+ classNames,
561
+ styles: styleOverrides,
562
+ }: CalendarProps<T>,
563
+ ref: ForwardedRef<CalendarHandle>,
564
+ ): ReactElement {
539
565
  const mergedTheme = useMemo(() => mergeTheme(theme), [theme]);
540
566
  const internalCellHeight = useSharedValue(hourHeight);
541
567
  const cellHeight = cellHeightProp ?? internalCellHeight;
568
+ const timeGridRef = useRef<CalendarHandle>(null);
569
+ useImperativeHandle(
570
+ ref,
571
+ () => ({
572
+ scrollToTime: (minutes, options) => timeGridRef.current?.scrollToTime(minutes, options),
573
+ }),
574
+ [],
575
+ );
542
576
 
543
577
  // Materialise recurring events over the range this mode renders (plus a one-page
544
578
  // buffer so occurrences survive the pager's pre-rendered neighbours), then apply
@@ -645,6 +679,8 @@ export function Calendar<T>({
645
679
  date={date}
646
680
  events={displayEvents}
647
681
  maxVisibleEventCount={maxVisibleEventCount}
682
+ chipHeight={chipHeight}
683
+ chipGap={chipGap}
648
684
  weekStartsOn={weekStartsOn}
649
685
  hiddenDays={hiddenDays}
650
686
  weekdayFormat={weekdayFormat}
@@ -727,6 +763,7 @@ export function Calendar<T>({
727
763
  />
728
764
  ) : (
729
765
  <TimeGrid
766
+ ref={timeGridRef}
730
767
  mode={mode}
731
768
  numberOfDays={numberOfDays}
732
769
  weekEndsOn={weekEndsOn}
@@ -98,6 +98,10 @@ export type MonthListProps<T> = {
98
98
  */
99
99
  monthHeaderHeight?: number;
100
100
  maxVisibleEventCount?: number;
101
+ /** Month chip height in pixels; omit to keep the renderer default. */
102
+ chipHeight?: number;
103
+ /** Gap between month chip rows in pixels (default 2). */
104
+ chipGap?: number;
101
105
  locale?: Locale;
102
106
  sortedMonthView?: boolean;
103
107
  moreLabel?: string;
@@ -153,6 +157,8 @@ function MonthListInner<T>({
153
157
  weekRowHeight: weekRowHeightProp,
154
158
  monthHeaderHeight = DEFAULT_MONTH_HEADER_HEIGHT,
155
159
  maxVisibleEventCount,
160
+ chipHeight,
161
+ chipGap,
156
162
  locale,
157
163
  sortedMonthView,
158
164
  moreLabel,
@@ -209,8 +215,8 @@ function MonthListInner<T>({
209
215
  // `firstViewableIndex` (the web `inert` cutoff must stay current). Selection
210
216
  // needs no entry: it reaches MonthView through context.
211
217
  const listExtraData = useMemo(
212
- () => ({ events, activeDate, firstViewableIndex }),
213
- [events, activeDate, firstViewableIndex],
218
+ () => ({ events, activeDate, firstViewableIndex, chipHeight, chipGap }),
219
+ [events, activeDate, firstViewableIndex, chipHeight, chipGap],
214
220
  );
215
221
 
216
222
  // A fixed window of months anchored once, aligned to the month start.
@@ -466,6 +472,8 @@ function MonthListInner<T>({
466
472
  showTitle={false}
467
473
  showWeekdays={false}
468
474
  maxVisibleEventCount={maxVisibleEventCount}
475
+ chipHeight={chipHeight}
476
+ chipGap={chipGap}
469
477
  weekStartsOn={weekStartsOn}
470
478
  locale={locale}
471
479
  sortedMonthView={sortedMonthView}
@@ -503,6 +511,8 @@ function MonthListInner<T>({
503
511
  locale,
504
512
  events,
505
513
  maxVisibleEventCount,
514
+ chipHeight,
515
+ chipGap,
506
516
  weekStartsOn,
507
517
  sortedMonthView,
508
518
  moreLabel,
@@ -57,6 +57,10 @@ export type MonthPagerProps<T> = {
57
57
  date: Date;
58
58
  events: CalendarEvent<T>[];
59
59
  maxVisibleEventCount?: number;
60
+ /** Month chip height in pixels; omit to keep the theme default. */
61
+ chipHeight?: number;
62
+ /** Gap between month chip rows in pixels (default 2). */
63
+ chipGap?: number;
60
64
  weekStartsOn: WeekStartsOn;
61
65
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
62
66
  hiddenDays?: number[];
@@ -121,6 +125,8 @@ function MonthPagerInner<T>({
121
125
  date,
122
126
  events,
123
127
  maxVisibleEventCount,
128
+ chipHeight,
129
+ chipGap,
124
130
  weekStartsOn,
125
131
  hiddenDays,
126
132
  weekdayFormat = "short",
@@ -291,8 +297,15 @@ function MonthPagerInner<T>({
291
297
  // grids as renderItem props, not through the selection context below: toggling
292
298
  // a "pick dates" mode on must reach the pages already rendered.
293
299
  const listExtraData = useMemo(
294
- () => ({ events, activeDate, fillCellOnSelection, dragSelect: onSelectDrag != null }),
295
- [events, activeDate, fillCellOnSelection, onSelectDrag],
300
+ () => ({
301
+ events,
302
+ activeDate,
303
+ fillCellOnSelection,
304
+ dragSelect: onSelectDrag != null,
305
+ chipHeight,
306
+ chipGap,
307
+ }),
308
+ [events, activeDate, fillCellOnSelection, onSelectDrag, chipHeight, chipGap],
296
309
  );
297
310
 
298
311
  // Selection reaches the grids through context, not `renderItem`, so a change
@@ -317,6 +330,8 @@ function MonthPagerInner<T>({
317
330
  showTitle={false}
318
331
  showWeekdays={false}
319
332
  maxVisibleEventCount={maxVisibleEventCount}
333
+ chipHeight={chipHeight}
334
+ chipGap={chipGap}
320
335
  weekStartsOn={weekStartsOn}
321
336
  hiddenDays={hiddenDays}
322
337
  locale={locale}
@@ -356,6 +371,8 @@ function MonthPagerInner<T>({
356
371
  pageHeight,
357
372
  events,
358
373
  maxVisibleEventCount,
374
+ chipHeight,
375
+ chipGap,
359
376
  weekStartsOn,
360
377
  hiddenDays,
361
378
  locale,
@@ -72,8 +72,6 @@ const DATE_BADGE_HEIGHT = 24;
72
72
  const BAND_CENTER_Y = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT / 2;
73
73
  const CELL_ROW_GAP = 2;
74
74
  const CHIP_PADDING_V = 2;
75
- // Where the first event row sits below the date badge (padding + badge + gap).
76
- const BADGE_AREA = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT + CELL_ROW_GAP;
77
75
  // Stable empty layout for the events-free picker (avoids a fresh object per render).
78
76
  const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
79
77
  // Horizontal inset of a chip within its cell (mirrors `styles.monthEvent`).
@@ -161,6 +159,10 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
161
159
  * explicit value when using a custom `renderEvent`.
162
160
  */
163
161
  maxVisibleEventCount?: number;
162
+ /** Chip and overflow height in pixels; defaults to the theme title height plus padding. */
163
+ chipHeight?: number;
164
+ /** Vertical gap between chip rows in pixels (default 2). */
165
+ chipGap?: number;
164
166
  weekStartsOn: WeekStartsOn;
165
167
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
166
168
  hiddenDays?: number[];
@@ -272,6 +274,8 @@ function MonthViewInner<T>({
272
274
  date,
273
275
  events,
274
276
  maxVisibleEventCount,
277
+ chipHeight,
278
+ chipGap = CELL_ROW_GAP,
275
279
  weekStartsOn,
276
280
  hiddenDays,
277
281
  weekdayFormat = "short",
@@ -316,6 +320,7 @@ function MonthViewInner<T>({
316
320
  styles: styleOverrides,
317
321
  }: MonthViewProps<T>): ReactElement {
318
322
  const theme = useCalendarTheme();
323
+ const badgeArea = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT + chipGap;
319
324
  const slot = createSlots<MonthViewSlot>({ classNames, styles: styleOverrides });
320
325
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
321
326
  // Selection comes from context (so cached pages still repaint), but explicit
@@ -366,9 +371,9 @@ function MonthViewInner<T>({
366
371
  const chipMetrics = useMemo(() => {
367
372
  const fontSize = numericStyle(theme.text.eventTitle.fontSize, 12);
368
373
  const lineHeight = numericStyle(theme.text.eventTitle.lineHeight, Math.ceil(fontSize * 1.3));
369
- const chipHeight = lineHeight + CHIP_PADDING_V * 2;
370
- return { chipHeight, chipRowHeight: chipHeight + CELL_ROW_GAP };
371
- }, [theme]);
374
+ const height = chipHeight ?? lineHeight + CHIP_PADDING_V * 2;
375
+ return { chipHeight: height, chipRowHeight: height + chipGap };
376
+ }, [theme, chipHeight, chipGap]);
372
377
 
373
378
  // How many chips fit per cell: a fixed cap when `maxVisibleEventCount` is set,
374
379
  // else derived from the measured cell height and the (default) chip metrics.
@@ -381,10 +386,10 @@ function MonthViewInner<T>({
381
386
  }
382
387
  const rowHeight = gridHeight / weeks.length;
383
388
  const moreFontSize = numericStyle(theme.text.more.fontSize, 11);
384
- const moreRowHeight = Math.ceil(moreFontSize * 1.3) + CELL_ROW_GAP;
389
+ const moreRowHeight = (chipHeight ?? Math.ceil(moreFontSize * 1.3)) + chipGap;
385
390
  const available = rowHeight - DAY_CELL_PADDING_TOP - DATE_BADGE_HEIGHT;
386
391
  return monthEventCapacity(available, chipMetrics.chipRowHeight, moreRowHeight);
387
- }, [maxVisibleEventCount, gridHeight, weeks.length, theme, chipMetrics]);
392
+ }, [maxVisibleEventCount, gridHeight, weeks.length, theme, chipMetrics, chipHeight, chipGap]);
388
393
 
389
394
  // Group events by calendar day once per `events` change (shared with the dom
390
395
  // renderer via core's `groupEventsByDay`), rather than scanning the whole list
@@ -466,7 +471,7 @@ function MonthViewInner<T>({
466
471
  if (!isDateSelectable(day, { minDate, maxDate, isDateDisabled })) return null;
467
472
  // Which lane row the point lands on, mirroring the bar overlay's geometry.
468
473
  const rowLayout = weekLayouts[row] ?? EMPTY_LAYOUT;
469
- const lane = Math.floor((y - row * rowHeight - BADGE_AREA) / chipMetrics.chipRowHeight);
474
+ const lane = Math.floor((y - row * rowHeight - badgeArea) / chipMetrics.chipRowHeight);
470
475
  const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
471
476
  const segment =
472
477
  lane >= 0 && lane < visibleLanes
@@ -480,6 +485,7 @@ function MonthViewInner<T>({
480
485
  weekLayouts,
481
486
  capacity,
482
487
  chipMetrics,
488
+ badgeArea,
483
489
  showAdjacentMonths,
484
490
  date,
485
491
  minDate,
@@ -623,7 +629,7 @@ function MonthViewInner<T>({
623
629
  <View
624
630
  key={day.toISOString()}
625
631
  {...slot("day", {
626
- base: styles.dayCell,
632
+ base: [styles.dayCell, { gap: chipGap }],
627
633
  themed: [
628
634
  showGrid && {
629
635
  borderTopWidth: StyleSheet.hairlineWidth,
@@ -715,7 +721,7 @@ function MonthViewInner<T>({
715
721
  // Events mode mirrors the dom renderer: left-aligned cell content with
716
722
  // the date badge in the top-right. The picker (no grid) stays centered
717
723
  // so the selection range band lines up with the centered badge.
718
- base: [styles.dayCell, showGrid && styles.dayCellEvents],
724
+ base: [styles.dayCell, { gap: chipGap }, showGrid && styles.dayCellEvents],
719
725
  themed: [
720
726
  showGrid && {
721
727
  borderTopWidth: StyleSheet.hairlineWidth,
@@ -862,7 +868,7 @@ function MonthViewInner<T>({
862
868
  {hiddenCount > 0 ? (
863
869
  <Text
864
870
  {...slot<TextStyle>("more", {
865
- base: styles.moreLabel,
871
+ base: [styles.moreLabel, chipHeight != null && { height: chipHeight }],
866
872
  themed: [theme.text.more, { color: theme.colors.textMuted }],
867
873
  })}
868
874
  onPress={
@@ -1036,7 +1042,7 @@ function MonthViewInner<T>({
1036
1042
  position: "absolute",
1037
1043
  left: pct((startCol / cols) * 100),
1038
1044
  width: pct(((endCol - startCol + 1) / cols) * 100),
1039
- top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
1045
+ top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
1040
1046
  height: chipMetrics.chipHeight,
1041
1047
  paddingHorizontal: CHIP_INSET_H,
1042
1048
  // Let a sweep in progress reach the cells underneath.