react-native-bigger-calendar 0.1.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.
@@ -0,0 +1,302 @@
1
+ import { SharedValue, useSharedValue } from "react-native-reanimated";
2
+ import { TextStyle } from "react-native";
3
+ import { ComponentType } from "react";
4
+
5
+ //#region src/theme.d.ts
6
+ /**
7
+ * The full set of colours, text styles and metrics the calendar paints with.
8
+ * Supply a `Partial<CalendarTheme>` to `<Calendar theme={...} />`; missing keys
9
+ * fall back to {@link defaultTheme}, so you only override what you care about.
10
+ */
11
+ interface CalendarTheme {
12
+ colors: {
13
+ /** Hour lines, day separators and month-cell borders. */gridLine: string; /** Background tint behind weekend columns/cells. */
14
+ weekendBackground: string; /** Fill of the "today" badge (and any today highlight). */
15
+ todayBackground: string; /** Text on top of the today badge. */
16
+ todayText: string; /** The current-time indicator line on the week/day grid. */
17
+ nowIndicator: string; /** Default text colour (day numbers, weekday labels). */
18
+ text: string; /** Muted text (hour labels, "+N more"). */
19
+ textMuted: string; /** Dimmed text for days outside the current month. */
20
+ textDisabled: string; /** Background of the built-in default event box. */
21
+ eventBackground: string; /** Text colour inside the built-in default event box. */
22
+ eventText: string;
23
+ };
24
+ text: {
25
+ /** Large day number in the week/day header. */dayNumber: TextStyle; /** Short weekday label ("Mon") in headers. */
26
+ weekday: TextStyle; /** Date number inside a month cell. */
27
+ dateCell: TextStyle; /** Hour labels down the left of the time grid. */
28
+ hourLabel: TextStyle; /** The "+N more" overflow label in month cells. */
29
+ more: TextStyle; /** Title inside the built-in default event box. */
30
+ eventTitle: TextStyle;
31
+ };
32
+ /** Corner radius of the today badge. Use a large value for a circle. */
33
+ todayBadgeRadius: number;
34
+ }
35
+ declare const defaultTheme: CalendarTheme;
36
+ /** Deep-merge a partial theme over {@link defaultTheme}. */
37
+ declare function mergeTheme(theme?: PartialCalendarTheme): CalendarTheme;
38
+ type PartialCalendarTheme = {
39
+ colors?: Partial<CalendarTheme['colors']>;
40
+ text?: Partial<CalendarTheme['text']>;
41
+ todayBadgeRadius?: number;
42
+ };
43
+ declare const CalendarThemeProvider: import("react").Provider<CalendarTheme>;
44
+ declare const useCalendarTheme: () => CalendarTheme;
45
+ //#endregion
46
+ //#region src/types.d.ts
47
+ type CalendarMode = 'day' | 'week' | 'month';
48
+ /**
49
+ * The minimal shape every calendar event must have. Layout (positioning,
50
+ * overlap resolution, paging) only ever reads `start`/`end`; `title` is used by
51
+ * the built-in default renderer. Anything else lives in your own type and is
52
+ * threaded through untouched via the `T` generic.
53
+ */
54
+ interface ICalendarEvent {
55
+ start: Date;
56
+ end: Date;
57
+ title?: string;
58
+ }
59
+ /**
60
+ * An event carrying arbitrary extra fields `T` alongside the required shape.
61
+ * `ICalendarEvent` is authoritative: keys it reserves (`start`/`end`/`title`)
62
+ * cannot be re-typed by `T`.
63
+ */
64
+ type CalendarEvent<T = unknown> = ICalendarEvent & Omit<T, keyof ICalendarEvent>;
65
+ type RenderEventArgs<T = unknown> = {
66
+ event: CalendarEvent<T>;
67
+ mode: CalendarMode;
68
+ /**
69
+ * Live pixel height of the event box on the week/day grid, driven on the UI
70
+ * thread by pinch-to-zoom. Use it to reveal detail progressively as the box
71
+ * grows. `undefined` in month mode, where events render at a fixed size.
72
+ */
73
+ boxHeight?: SharedValue<number>;
74
+ /**
75
+ * On the week/day grid, true when this is a clipped segment of a multi-day
76
+ * event that started on an earlier day / continues onto a later day. Lets a
77
+ * renderer draw "continues" affordances. `undefined` in month mode.
78
+ */
79
+ continuesBefore?: boolean;
80
+ continuesAfter?: boolean;
81
+ onPress: () => void;
82
+ };
83
+ /**
84
+ * A component that renders a single event. It is rendered as a real component
85
+ * (not called as a function), so it may safely use hooks — including Reanimated
86
+ * hooks driven by `boxHeight`. Render an element that fills its container
87
+ * (`flex: 1`); the calendar positions and sizes the wrapping box for you.
88
+ */
89
+ type RenderEvent<T = unknown> = ComponentType<RenderEventArgs<T>>;
90
+ /** Build a stable key for an event. Defaults to start-time + index. */
91
+ type EventKeyExtractor<T = unknown> = (event: CalendarEvent<T>, index: number) => string;
92
+ /** Sunday = 0 … Saturday = 6, matching `Date.prototype.getDay()`. */
93
+ type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
94
+ //#endregion
95
+ //#region src/components/Calendar.d.ts
96
+ type CalendarProps<T> = {
97
+ events: CalendarEvent<T>[];
98
+ mode: CalendarMode;
99
+ date: Date;
100
+ onChangeDate: (date: Date) => void;
101
+ onPressEvent: (event: CalendarEvent<T>) => void; /** Tap a day cell (month mode) — e.g. drill into the day view. */
102
+ onPressDay?: (date: Date) => void; /** Tap the "+N more" overflow label in a month cell. */
103
+ onPressMore?: (events: CalendarEvent<T>[], date: Date) => void; /** Tap empty space on the week/day grid; receives the date+time pressed. */
104
+ onPressCell?: (date: Date) => void; /** Max events shown per month cell before they collapse into "+N more". */
105
+ maxVisibleEventCount?: number; /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
106
+ weekStartsOn?: WeekStartsOn; /** Replace the built-in event box. Return a `flex: 1` element. */
107
+ renderEvent?: RenderEvent<T>; /** Stable key per event. Defaults to start-time + index. */
108
+ keyExtractor?: EventKeyExtractor<T>; /** Partial theme merged over the defaults. */
109
+ theme?: PartialCalendarTheme; /** Externally-owned per-hour row height (week/day). Created internally if omitted. */
110
+ cellHeight?: ReturnType<typeof useSharedValue<number>>; /** Initial per-hour row height in px (week/day). Default 64. */
111
+ hourHeight?: number;
112
+ minHourHeight?: number;
113
+ maxHourHeight?: number;
114
+ hourColumnWidth?: number; /** First hour shown on the week/day grid (0–23). Default 0. */
115
+ minHour?: number; /** Last hour shown on the week/day grid, exclusive (1–24). Default 24. */
116
+ maxHour?: number; /** Show hour labels in 12-hour AM/PM form. Default false (24h). */
117
+ ampm?: boolean; /** Initial vertical scroll, in minutes from midnight (week/day). */
118
+ scrollOffsetMinutes?: number; /** Show the current-time line on the week/day grid. Default true. */
119
+ showNowIndicator?: boolean; /** BCP-47 locale for weekday labels. Defaults to the device locale. */
120
+ locale?: string;
121
+ /**
122
+ * Allow a fling to carry across several pages before snapping. Default false:
123
+ * one day/week/month per swipe.
124
+ */
125
+ freeSwipe?: boolean; /** Custom header above the week/day grid. Receives the visible days. */
126
+ renderTimeGridHeader?: (days: Date[]) => React.ReactNode;
127
+ };
128
+ declare function Calendar<T>({
129
+ events,
130
+ mode,
131
+ date,
132
+ onChangeDate,
133
+ onPressEvent,
134
+ onPressDay,
135
+ onPressMore,
136
+ onPressCell,
137
+ maxVisibleEventCount,
138
+ weekStartsOn,
139
+ renderEvent,
140
+ keyExtractor,
141
+ theme,
142
+ cellHeight: cellHeightProp,
143
+ hourHeight,
144
+ minHourHeight,
145
+ maxHourHeight,
146
+ hourColumnWidth,
147
+ minHour,
148
+ maxHour,
149
+ ampm,
150
+ scrollOffsetMinutes,
151
+ showNowIndicator,
152
+ locale,
153
+ freeSwipe,
154
+ renderTimeGridHeader
155
+ }: CalendarProps<T>): import("react").JSX.Element;
156
+ //#endregion
157
+ //#region src/components/MonthView.d.ts
158
+ type MonthViewProps<T> = {
159
+ date: Date;
160
+ events: CalendarEvent<T>[];
161
+ maxVisibleEventCount: number;
162
+ weekStartsOn: WeekStartsOn;
163
+ renderEvent: RenderEvent<T>;
164
+ keyExtractor: EventKeyExtractor<T>;
165
+ onPressDay?: (date: Date) => void;
166
+ onPressEvent: (event: CalendarEvent<T>) => void;
167
+ onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
168
+ };
169
+ declare function MonthViewInner<T>({
170
+ date,
171
+ events,
172
+ maxVisibleEventCount,
173
+ weekStartsOn,
174
+ renderEvent,
175
+ keyExtractor,
176
+ onPressDay,
177
+ onPressEvent,
178
+ onPressMore
179
+ }: MonthViewProps<T>): import("react").JSX.Element;
180
+ declare const MonthView: typeof MonthViewInner;
181
+ //#endregion
182
+ //#region src/components/MonthPager.d.ts
183
+ type MonthPagerProps<T> = {
184
+ date: Date;
185
+ events: CalendarEvent<T>[];
186
+ maxVisibleEventCount: number;
187
+ weekStartsOn: WeekStartsOn;
188
+ renderEvent: RenderEvent<T>;
189
+ keyExtractor: EventKeyExtractor<T>;
190
+ onPressDay?: (date: Date) => void;
191
+ onPressEvent: (event: CalendarEvent<T>) => void;
192
+ onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
193
+ onChangeDate: (date: Date) => void;
194
+ freeSwipe?: boolean;
195
+ };
196
+ declare function MonthPagerInner<T>({
197
+ date,
198
+ events,
199
+ maxVisibleEventCount,
200
+ weekStartsOn,
201
+ renderEvent,
202
+ keyExtractor,
203
+ onPressDay,
204
+ onPressEvent,
205
+ onPressMore,
206
+ onChangeDate,
207
+ freeSwipe
208
+ }: MonthPagerProps<T>): import("react").JSX.Element;
209
+ declare const MonthPager: typeof MonthPagerInner;
210
+ //#endregion
211
+ //#region src/components/TimeGrid.d.ts
212
+ declare const DEFAULT_HOUR_HEIGHT = 64;
213
+ type TimeGridProps<T> = {
214
+ mode: 'day' | 'week';
215
+ date: Date;
216
+ events: CalendarEvent<T>[];
217
+ cellHeight: SharedValue<number>; /** Initial per-hour row height in px; seeds scroll/zoom without reading the shared value during render. */
218
+ hourHeight?: number;
219
+ weekStartsOn: WeekStartsOn;
220
+ renderEvent: RenderEvent<T>;
221
+ keyExtractor: EventKeyExtractor<T>;
222
+ scrollOffsetMinutes?: number;
223
+ hourColumnWidth?: number; /** First hour shown (0–23). Default 0. */
224
+ minHour?: number; /** Last hour shown, exclusive (1–24). Default 24. */
225
+ maxHour?: number; /** Show hour labels in 12-hour AM/PM form. Default false (24h). */
226
+ ampm?: boolean;
227
+ minHourHeight?: number;
228
+ maxHourHeight?: number;
229
+ showNowIndicator?: boolean;
230
+ locale?: string;
231
+ freeSwipe?: boolean;
232
+ onPressEvent: (event: CalendarEvent<T>) => void;
233
+ onPressCell?: (date: Date) => void;
234
+ onChangeDate: (date: Date) => void; /** Optional header above the grid (e.g. weekday labels). Rendered full-width. */
235
+ renderHeader?: (days: Date[]) => React.ReactNode;
236
+ };
237
+ declare function TimeGridInner<T>({
238
+ mode,
239
+ date,
240
+ events,
241
+ cellHeight,
242
+ hourHeight,
243
+ weekStartsOn,
244
+ renderEvent,
245
+ keyExtractor,
246
+ scrollOffsetMinutes,
247
+ hourColumnWidth,
248
+ minHour,
249
+ maxHour,
250
+ ampm,
251
+ minHourHeight,
252
+ maxHourHeight,
253
+ showNowIndicator,
254
+ locale,
255
+ freeSwipe,
256
+ onPressEvent,
257
+ onPressCell,
258
+ onChangeDate,
259
+ renderHeader
260
+ }: TimeGridProps<T>): import("react").JSX.Element;
261
+ declare const TimeGrid: typeof TimeGridInner;
262
+ //#endregion
263
+ //#region src/components/DefaultEvent.d.ts
264
+ /**
265
+ * The built-in event renderer: a filled, rounded box showing the event title
266
+ * and (on the day/week grid) its time range. Pass your own `renderEvent` to
267
+ * `<Calendar>` to replace it entirely.
268
+ */
269
+ declare function DefaultEvent<T>({
270
+ event,
271
+ mode,
272
+ onPress
273
+ }: RenderEventArgs<T>): import("react").JSX.Element;
274
+ //#endregion
275
+ //#region src/utils/dates.d.ts
276
+ /** The seven dates of the week containing `date`, starting on `weekStartsOn`. */
277
+ declare const getWeekDays: (date: Date, weekStartsOn: WeekStartsOn) => Date[];
278
+ declare const isWeekend: (date: Date) => boolean;
279
+ declare const getIsToday: (date: Date) => boolean;
280
+ declare const isSameCalendarDay: (a: Date, b: Date) => boolean;
281
+ /** Minutes elapsed since midnight (0–1439). */
282
+ declare const minutesIntoDay: (date: Date) => number;
283
+ //#endregion
284
+ //#region src/utils/layout.d.ts
285
+ type PositionedEvent<T> = {
286
+ event: CalendarEvent<T>; /** Hours from midnight to the event's segment start on this day (fractional). */
287
+ startHours: number; /** Segment duration in hours on this day (clamped to a small minimum). */
288
+ durationHours: number; /** Zero-based column index within its overlap cluster. */
289
+ column: number; /** Total columns in this event's overlap cluster. */
290
+ columns: number; /** True when the segment is clipped because the event continues before/after this day. */
291
+ continuesBefore: boolean;
292
+ continuesAfter: boolean;
293
+ };
294
+ /**
295
+ * Lay out a single day's events: events that overlap in time are split into
296
+ * side-by-side columns. Multi-day events are clipped to the portion that falls
297
+ * on `day` (e.g. a 23:00→01:00 event renders 23:00–24:00 on the start day and
298
+ * 00:00–01:00 on the next). Pure — safe to call per render, never per frame.
299
+ */
300
+ declare function layoutDayEvents<T>(events: CalendarEvent<T>[], day: Date): PositionedEvent<T>[];
301
+ //#endregion
302
+ export { Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarTheme, CalendarThemeProvider, DEFAULT_HOUR_HEIGHT, DefaultEvent, type EventKeyExtractor, type ICalendarEvent, MonthPager, type MonthPagerProps, MonthView, type MonthViewProps, type PartialCalendarTheme, type PositionedEvent, type RenderEvent, type RenderEventArgs, TimeGrid, type TimeGridProps, type WeekStartsOn, defaultTheme, getIsToday, getWeekDays, isSameCalendarDay, isWeekend, layoutDayEvents, mergeTheme, minutesIntoDay, useCalendarTheme };