@super-calendar/native 2.9.1 → 2.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/native",
3
- "version": "2.9.1",
3
+ "version": "2.11.0",
4
4
  "description": "Gesture-driven, virtualized month / week / day calendar and date picker for React Native (and web via react-native-web).",
5
5
  "keywords": [
6
6
  "agenda",
@@ -64,7 +64,7 @@
64
64
  "access": "public"
65
65
  },
66
66
  "dependencies": {
67
- "@super-calendar/core": "2.9.1"
67
+ "@super-calendar/core": "2.11.0"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@legendapp/list": ">=3",
@@ -1,7 +1,7 @@
1
1
  import { LegendList, type LegendListRenderItemProps } from "@legendapp/list/react-native";
2
2
  import { format, isSameDay, type Locale, startOfDay } from "date-fns";
3
3
  import { type ComponentType, type ReactElement, useCallback, useMemo } from "react";
4
- import { StyleSheet, Text, type TextStyle, View } from "react-native";
4
+ import { StyleSheet, Text, type TextStyle, View, type ScrollViewProps } from "react-native";
5
5
  import { useCalendarTheme } from "../theme";
6
6
  import type { CalendarEvent, EventKeyExtractor, RenderEvent } from "../types";
7
7
  import { createSlots, type SlotStyleProps } from "../utils/slots";
@@ -27,6 +27,8 @@ export type AgendaProps<T> = SlotStyleProps<AgendaSlot> & {
27
27
  activeDate?: Date;
28
28
  /** Drawn between rows of the agenda list. */
29
29
  itemSeparatorComponent?: ComponentType<unknown> | null;
30
+ /** Pull-to-refresh control, mounted on the list's scroll view. */
31
+ refreshControl?: ScrollViewProps["refreshControl"];
30
32
  };
31
33
 
32
34
  type Row<T> =
@@ -48,6 +50,7 @@ export function Agenda<T>({
48
50
  onPressDay,
49
51
  activeDate,
50
52
  itemSeparatorComponent,
53
+ refreshControl,
51
54
  classNames,
52
55
  styles: styleOverrides,
53
56
  }: AgendaProps<T>): ReactElement {
@@ -145,6 +148,7 @@ export function Agenda<T>({
145
148
  (itemSeparatorComponent ?? undefined) as ComponentType<{ leadingItem: Row<T> }> | undefined
146
149
  }
147
150
  recycleItems={false}
151
+ refreshControl={refreshControl}
148
152
  />
149
153
  );
150
154
  }
@@ -1,5 +1,5 @@
1
1
  import { addDays, startOfDay } from "date-fns";
2
- import { StyleSheet, Text, type TextStyle, View } from "react-native";
2
+ import { type LayoutChangeEvent, StyleSheet, View } from "react-native";
3
3
  import { useCalendarTheme } from "../theme";
4
4
  import type { CalendarEvent, CalendarMode, EventKeyExtractor, RenderEvent } from "../types";
5
5
  import { useSlots } from "../utils/slots";
@@ -7,36 +7,38 @@ import { isAllDayEvent, isBackgroundEvent } from "@super-calendar/core";
7
7
 
8
8
  // The lane's slots are a subset of the TimeGrid slot union; typed locally so
9
9
  // this file doesn't import the full TimeGrid type.
10
- type AllDayLaneSlot = "allDayLane" | "allDayLabel" | "allDayColumn" | "allDayEvent";
10
+ type AllDayLaneSlot = "allDayLane" | "allDayColumn" | "allDayEvent";
11
11
 
12
12
  type AllDayLaneProps<T> = {
13
13
  days: Date[];
14
14
  events: CalendarEvent<T>[];
15
15
  mode: CalendarMode;
16
- hourColumnWidth: number;
17
16
  dayWidth: number;
18
17
  renderEvent: RenderEvent<T>;
19
18
  keyExtractor: EventKeyExtractor<T>;
20
19
  onPressEvent: (event: CalendarEvent<T>) => void;
21
20
  onLongPressEvent?: (event: CalendarEvent<T>) => void;
21
+ /** Reports the lane's natural height, which the grid's all-day band follows. */
22
+ onLayout?: (event: LayoutChangeEvent) => void;
22
23
  };
23
24
 
24
25
  /**
25
- * The all-day lane that sits above the scrolling time grid. All-day events are
26
- * excluded from the timed columns (see `layoutDayEvents`) and shown here,
27
- * stacked under their day(s). Renders nothing when no day has an all-day event,
28
- * so timed-only calendars are unaffected.
26
+ * The all-day lane of one page, pinned above the scrolling hours. All-day
27
+ * 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
29
+ * height, zero when the week has none, which the band above the grid follows
30
+ * live as you swipe; the "all-day" label lives in the hour column.
29
31
  */
30
32
  export function AllDayLane<T>({
31
33
  days,
32
34
  events,
33
35
  mode,
34
- hourColumnWidth,
35
36
  dayWidth,
36
37
  renderEvent,
37
38
  keyExtractor,
38
39
  onPressEvent,
39
40
  onLongPressEvent,
41
+ onLayout,
40
42
  }: AllDayLaneProps<T>) {
41
43
  const theme = useCalendarTheme();
42
44
  const slot = useSlots<AllDayLaneSlot>();
@@ -50,50 +52,40 @@ export function AllDayLane<T>({
50
52
  return allDay.filter((event) => event.start < next && event.end > start);
51
53
  });
52
54
 
53
- if (perDay.every((list) => list.length === 0)) return null;
54
-
55
55
  return (
56
56
  <View
57
57
  {...slot("allDayLane", {
58
58
  base: styles.lane,
59
- themed: [{ borderBottomColor: theme.colors.gridLine }, theme.containers.allDayLane],
59
+ themed: theme.containers.allDayLane,
60
60
  })}
61
+ onLayout={onLayout}
61
62
  >
62
- <View style={[styles.gutter, { width: hourColumnWidth }]}>
63
- {/* The "all-day" gutter label, mirroring the dom renderer: small, muted,
64
- and right-aligned against the timed columns. Centered vertically so it
65
- lines up with the chips whether the lane holds one event or several. */}
66
- <Text
67
- {...slot<TextStyle>("allDayLabel", {
68
- base: styles.label,
69
- themed: { color: theme.colors.textMuted },
70
- })}
71
- allowFontScaling={false}
72
- >
73
- all-day
74
- </Text>
75
- </View>
76
- {days.map((day, dayIndex) => (
77
- <View
78
- key={day.toISOString()}
79
- {...slot("allDayColumn", {
80
- base: [styles.column, { width: dayWidth }],
81
- themed: theme.containers.allDayColumn,
82
- })}
83
- >
84
- {perDay[dayIndex].map((event, index) => (
85
- <View key={keyExtractor(event, index)} {...slot("allDayEvent", { base: styles.chip })}>
86
- <RenderEventComponent
87
- event={event}
88
- mode={mode}
89
- isAllDay
90
- onPress={() => onPressEvent(event)}
91
- onLongPress={onLongPressEvent ? () => onLongPressEvent(event) : undefined}
92
- />
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
+ ))}
93
87
  </View>
94
88
  ))}
95
- </View>
96
- ))}
97
89
  </View>
98
90
  );
99
91
  }
@@ -101,15 +93,6 @@ export function AllDayLane<T>({
101
93
  const styles = StyleSheet.create({
102
94
  lane: {
103
95
  flexDirection: "row",
104
- borderBottomWidth: StyleSheet.hairlineWidth,
105
- },
106
- gutter: {
107
- justifyContent: "center",
108
- },
109
- label: {
110
- fontSize: 10,
111
- textAlign: "right",
112
- paddingRight: 6,
113
96
  },
114
97
  column: {
115
98
  paddingVertical: 2,
@@ -13,7 +13,7 @@ import {
13
13
  startOfYear,
14
14
  } from "date-fns";
15
15
  import { type ReactElement, useCallback, useMemo } from "react";
16
- import type { StyleProp, ViewStyle } from "react-native";
16
+ import type { ScrollViewProps, StyleProp, ViewStyle } from "react-native";
17
17
  import { useSharedValue } from "react-native-reanimated";
18
18
  import { CalendarThemeProvider, mergeTheme, type PartialCalendarTheme } from "../theme";
19
19
  import type {
@@ -207,6 +207,18 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
207
207
  * band stays non-interactive and hidden from assistive tech.
208
208
  */
209
209
  renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
210
+ /**
211
+ * Week/day grid only: a component that draws a `display: "background"` event's
212
+ * band in place of the themed shade. Rendered as a real component, like
213
+ * `renderEvent`, so it may use hooks. It receives `event`, `mode`, a live
214
+ * `boxHeight`, `continuesBefore` / `continuesAfter` for a multi-day event, and
215
+ * `onPress` / `onLongPress`, which fire `onPressEvent` / `onLongPressEvent`.
216
+ * The band lets touches through to what you render and stops hiding itself
217
+ * from assistive tech, so a pressable there works; cell presses and
218
+ * drag-to-create are unreachable underneath it. Without this prop the band
219
+ * stays a shaded, non-interactive range. The resource timeline keeps the shade.
220
+ */
221
+ renderBackgroundEvent?: RenderEvent<T>;
210
222
  /** Stable key per event. Defaults to start-time + index. */
211
223
  keyExtractor?: EventKeyExtractor<T>;
212
224
  /** Partial theme merged over the defaults. */
@@ -217,17 +229,43 @@ export type CalendarProps<T> = SlotStyleProps<CalendarSlot> & {
217
229
  hourHeight?: number;
218
230
  minHourHeight?: number;
219
231
  maxHourHeight?: number;
232
+ /**
233
+ * Minimum pixel height of a timed event box on the week/day grid, so short
234
+ * events stay legible and tappable. Also the floor of the `boxHeight` handed to
235
+ * `renderEvent`. Default 32; pass 0 to size every box strictly by its duration.
236
+ */
237
+ minEventHeight?: number;
238
+ /**
239
+ * Inset in pixels between a timed event box and its slot on the week/day grid
240
+ * (each side). Default 2; pass 0 to let events fill their slot.
241
+ */
242
+ eventGap?: number;
220
243
  hourColumnWidth?: number;
221
244
  /** Hide the left hour-axis column on the week/day grid. Default false. */
222
245
  hideHours?: boolean;
223
246
  /** Sub-hour divider lines per hour on the week/day grid (e.g. 2 = half-hours). Default 1. */
224
247
  timeslots?: number;
225
248
  /**
226
- * Show the all-day lane above the week/day grid. Default true. When false the
227
- * lane is never rendered, so all-day events (see `ICalendarEvent.allDay` and
228
- * whole-day spans) are not shown on the time grid.
249
+ * Show the all-day lane above the week/day grid. Default true: the lane is
250
+ * sized to the week's all-day events, collapsing to nothing when there are
251
+ * none, and its height follows the week as you swipe. When false the lane is
252
+ * never rendered, so
253
+ * all-day events (see `ICalendarEvent.allDay` and whole-day spans) are not
254
+ * shown on the time grid.
229
255
  */
230
256
  showAllDayEventCell?: boolean;
257
+ /**
258
+ * Show the "all-day" text label in the week/day hour column. Default false: a
259
+ * week with no all-day events then shows no lane at all, rather than a label
260
+ * beside an empty row; with the label on, it slides away with the lane.
261
+ */
262
+ showAllDayLabel?: boolean;
263
+ /**
264
+ * Pull-to-refresh for the modes that scroll vertically: pass a `RefreshControl`
265
+ * element and it wraps the schedule list, the week/day grid's scroll view or
266
+ * the year view. Month pages scroll sideways, so it has no effect there.
267
+ */
268
+ refreshControl?: ScrollViewProps["refreshControl"];
231
269
  /** Tint weekend columns (default true). Set false to treat weekends normally. */
232
270
  highlightWeekends?: boolean;
233
271
  /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
@@ -445,16 +483,21 @@ export function Calendar<T>({
445
483
  calendarCellStyle,
446
484
  businessHours,
447
485
  renderBusinessHours,
486
+ renderBackgroundEvent,
448
487
  keyExtractor = defaultKeyExtractor as EventKeyExtractor<T>,
449
488
  theme,
450
489
  cellHeight: cellHeightProp,
451
490
  hourHeight = DEFAULT_HOUR_HEIGHT,
452
491
  minHourHeight,
453
492
  maxHourHeight,
493
+ minEventHeight,
494
+ eventGap,
454
495
  hourColumnWidth,
455
496
  hideHours,
456
497
  timeslots,
457
498
  showAllDayEventCell,
499
+ showAllDayLabel,
500
+ refreshControl,
458
501
  highlightWeekends,
459
502
  eventStartEditable,
460
503
  eventDurationEditable,
@@ -640,6 +683,7 @@ export function Calendar<T>({
640
683
  <YearView
641
684
  date={date}
642
685
  events={displayEvents}
686
+ refreshControl={refreshControl}
643
687
  weekStartsOn={weekStartsOn}
644
688
  hiddenDays={hiddenDays}
645
689
  locale={locale}
@@ -667,6 +711,7 @@ export function Calendar<T>({
667
711
  onPressDay={onPressDay}
668
712
  activeDate={activeDate}
669
713
  itemSeparatorComponent={itemSeparatorComponent}
714
+ refreshControl={refreshControl}
670
715
  classNames={classNames}
671
716
  styles={styleOverrides}
672
717
  />
@@ -691,6 +736,8 @@ export function Calendar<T>({
691
736
  hideHours={hideHours}
692
737
  timeslots={timeslots}
693
738
  showAllDayEventCell={showAllDayEventCell}
739
+ showAllDayLabel={showAllDayLabel}
740
+ refreshControl={refreshControl}
694
741
  highlightWeekends={highlightWeekends}
695
742
  eventStartEditable={eventStartEditable}
696
743
  eventDurationEditable={eventDurationEditable}
@@ -698,6 +745,7 @@ export function Calendar<T>({
698
745
  calendarCellStyle={calendarCellStyle}
699
746
  businessHours={businessHours}
700
747
  renderBusinessHours={renderBusinessHours}
748
+ renderBackgroundEvent={renderBackgroundEvent}
701
749
  showWeekNumber={showWeekNumber}
702
750
  weekNumberPrefix={weekNumberPrefix}
703
751
  hourComponent={hourComponent}
@@ -709,6 +757,8 @@ export function Calendar<T>({
709
757
  ampm={ampm}
710
758
  minHourHeight={minHourHeight}
711
759
  maxHourHeight={maxHourHeight}
760
+ minEventHeight={minEventHeight}
761
+ eventGap={eventGap}
712
762
  showNowIndicator={showNowIndicator}
713
763
  locale={locale}
714
764
  activeDate={activeDate}
@@ -28,14 +28,14 @@ type PreviewProps<T> = {
28
28
  days: Date[];
29
29
  cellHeight: SharedValue<number>;
30
30
  dayWidth: number;
31
- hourColumnWidth: number;
32
31
  minHour: number;
33
32
  mode: CalendarMode;
34
33
  renderEvent: RenderEvent<T>;
34
+ minEventHeight: number;
35
+ eventGap: number;
35
36
  };
36
37
 
37
38
  const noop = () => {};
38
- const MIN_EVENT_HEIGHT = 32;
39
39
 
40
40
  // Mount once on grab. Only numbers and shared values cross to the UI thread;
41
41
  // moving the pointer does not rerender the page or rebuild its gestures.
@@ -61,10 +61,11 @@ function PreviewDay<T>({
61
61
  move,
62
62
  cellHeight,
63
63
  dayWidth,
64
- hourColumnWidth,
65
64
  minHour,
66
65
  mode,
67
66
  renderEvent: RenderEventComponent,
67
+ minEventHeight,
68
+ eventGap,
68
69
  dayOffsets,
69
70
  index,
70
71
  dayStart,
@@ -99,10 +100,12 @@ function PreviewDay<T>({
99
100
  continuesAfter: end > dayEnd,
100
101
  };
101
102
  }, [dayWidth, dayIndex, dayOffsets, startTimestamp, duration, dayStart, dayEnd]);
102
- const boxHeight = useDerivedValue(() =>
103
- segment.value.hours > 0
104
- ? Math.max(segment.value.hours * cellHeight.value, MIN_EVENT_HEIGHT)
105
- : 0,
103
+ const boxHeight = useDerivedValue(
104
+ () =>
105
+ segment.value.hours > 0
106
+ ? Math.max(segment.value.hours * cellHeight.value, minEventHeight)
107
+ : 0,
108
+ [minEventHeight],
106
109
  );
107
110
  const style = useAnimatedStyle(
108
111
  () => ({
@@ -143,8 +146,8 @@ function PreviewDay<T>({
143
146
  {
144
147
  position: "absolute",
145
148
  overflow: "hidden",
146
- padding: 2,
147
- left: hourColumnWidth + index * dayWidth,
149
+ padding: eventGap,
150
+ left: index * dayWidth,
148
151
  width: dayWidth,
149
152
  zIndex: 100,
150
153
  },