@moltenship/calendar 1.0.0-rc.2 → 2.0.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.
Files changed (78) hide show
  1. package/README.md +27 -6
  2. package/dist/index.d.mts +3 -3
  3. package/dist/index.mjs +2 -2
  4. package/docs/accessibility.md +305 -0
  5. package/docs/agents/changes.md +449 -0
  6. package/docs/agents/coding-agents.md +116 -0
  7. package/docs/agents/connect.md +444 -0
  8. package/docs/agents/deleting.md +296 -0
  9. package/docs/agents/reference.md +511 -0
  10. package/docs/agents/server.md +317 -0
  11. package/docs/agents/webmcp.md +153 -0
  12. package/docs/agents.md +355 -0
  13. package/docs/annotations.md +198 -0
  14. package/docs/api/changes.md +264 -0
  15. package/docs/api/components.md +245 -0
  16. package/docs/api/dnd-kit.md +265 -0
  17. package/docs/api/events.md +153 -0
  18. package/docs/api/primitives.md +218 -0
  19. package/docs/api/store.md +92 -0
  20. package/docs/api.md +57 -0
  21. package/docs/availability.md +576 -0
  22. package/docs/comparison.md +278 -0
  23. package/docs/concepts/anatomy.md +73 -0
  24. package/docs/concepts/events.md +163 -0
  25. package/docs/concepts/how-it-works.md +112 -0
  26. package/docs/concepts/state.md +244 -0
  27. package/docs/concepts/time.md +168 -0
  28. package/docs/customization.md +271 -0
  29. package/docs/frameworks.md +116 -0
  30. package/docs/guides/dnd-kit.md +333 -0
  31. package/docs/guides/google-calendar-sync.md +1246 -0
  32. package/docs/guides/google-calendar.md +367 -0
  33. package/docs/guides/motion.md +414 -0
  34. package/docs/guides/nextjs-app-router.md +630 -0
  35. package/docs/guides/nextjs.md +149 -0
  36. package/docs/guides/performance.md +103 -0
  37. package/docs/guides/tanstack-query.md +485 -0
  38. package/docs/ics/feed.md +484 -0
  39. package/docs/ics/import.md +183 -0
  40. package/docs/ics/reference.md +482 -0
  41. package/docs/ics.md +142 -0
  42. package/docs/index.md +149 -0
  43. package/docs/installation.md +209 -0
  44. package/docs/interactions.md +441 -0
  45. package/docs/llms.txt +99 -0
  46. package/docs/migrating-to-2.md +497 -0
  47. package/docs/quick-start.md +163 -0
  48. package/docs/recurrence/calendar.md +598 -0
  49. package/docs/recurrence/model.md +128 -0
  50. package/docs/recurrence/reference.md +547 -0
  51. package/docs/recurrence.md +122 -0
  52. package/docs/stylex.md +290 -0
  53. package/docs/temporal/daylight-saving-time.md +172 -0
  54. package/docs/temporal/month-grid.md +119 -0
  55. package/docs/temporal/reference.md +167 -0
  56. package/docs/temporal.md +105 -0
  57. package/docs/testing.md +600 -0
  58. package/docs/theme-builder.md +82 -0
  59. package/docs/theming.md +275 -0
  60. package/docs/undo-redo.md +347 -0
  61. package/docs/views/agenda.md +222 -0
  62. package/docs/views/custom-views.md +195 -0
  63. package/docs/views/month.md +110 -0
  64. package/docs/views/resource-columns.md +265 -0
  65. package/docs/views/resource-timeline.md +226 -0
  66. package/docs/views/scrolling.md +193 -0
  67. package/docs/views/week-and-day.md +258 -0
  68. package/docs/views/year.md +138 -0
  69. package/docs/views.md +69 -0
  70. package/package.json +42 -14
  71. package/skills/moltenship-time/SKILL.md +77 -0
  72. package/skills/moltenship-time/references/agent-ready.md +272 -0
  73. package/skills/moltenship-time/references/changes.md +188 -0
  74. package/skills/moltenship-time/references/compose.md +175 -0
  75. package/skills/moltenship-time/references/mistakes.md +100 -0
  76. package/skills/moltenship-time/references/solid.md +213 -0
  77. package/skills/moltenship-time/references/state.md +129 -0
  78. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,226 @@
1
+ # Resource timeline
2
+
3
+ Rooms or people as rows and time as columns, for a day, a week or a month, with hundreds of rows.
4
+
5
+ Source: https://time.molten.sh/docs/react/views/resource-timeline
6
+
7
+ > Live example of the `timeline` view: see it at https://time.molten.sh/docs/react/views/resource-timeline
8
+
9
+ Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Timeline in the view
10
+ switcher.
11
+
12
+ `createTimelineDayView`, `createTimelineWeekView` and `createTimelineMonthView` show one row for
13
+ each resource, such as a room or a person, with time running across. A day is split into hours, and
14
+ a week or a month into days. Each resource's events are bars in its row. Resources with children
15
+ appear as groups that collapse. Only the rows and slots in view are rendered, so the timeline stays
16
+ fast with hundreds of resources over a whole month.
17
+
18
+ ## Add it
19
+
20
+ Add the view to your app with the shadcn CLI, as described in
21
+ [UI source](../installation.md#ui-source-optional). The item brings the theme, the shared
22
+ `calendar` parts, shadcn's `button`, and `@tanstack/virtual-core`:
23
+
24
+ ```bash
25
+ npx shadcn@latest add https://time.molten.sh/r/resource-timeline-view.json
26
+ ```
27
+
28
+ ```tsx
29
+ import {
30
+ createTimelineDayView,
31
+ createTimelineMonthView,
32
+ createTimelineWeekView,
33
+ } from "@/components/calendar/resource-timeline-view/resource-timeline-view";
34
+
35
+ const getEventColor = (meeting: Meeting) => meeting.color;
36
+
37
+ export const Calendar = createCalendar<Meeting, Room>()({
38
+ eventAdapter,
39
+ views: [
40
+ createTimelineDayView<Meeting>({ getEventColor }),
41
+ createTimelineWeekView<Meeting>({ getEventColor }),
42
+ createTimelineMonthView<Meeting>({ getEventColor }),
43
+ ],
44
+ });
45
+ ```
46
+
47
+ The views are named `timeline-day`, `timeline-week` and `timeline-month`. The week starts on
48
+ `weekRules.firstDay`, and the month view shows the anchor's calendar month, from the 1st to its last
49
+ day. Previous and Next move by a day, a week or a month.
50
+
51
+ ## Resources
52
+
53
+ Pass the resources to `Root`, as for [resource columns](./resource-columns.md#resources).
54
+ Each one has an `id`, a `title`, and optionally a `parentId`, which puts it in a group under that
55
+ resource. Events list the resources they book in `resourceIds`, read through your event adapter's
56
+ `getResourceIds`. An event that books several resources shows in each of their rows.
57
+
58
+ ```tsx
59
+ const rooms = [
60
+ { data: null, id: "floor-1", title: "First floor" },
61
+ { data: null, id: "orchid", parentId: "floor-1", title: "Orchid" },
62
+ { data: null, id: "lotus", parentId: "floor-1", title: "Lotus" },
63
+ ];
64
+
65
+ <Calendar.Root resources={rooms} defaultExpandedResourceIds={["floor-1"]} /* … */>
66
+ ```
67
+
68
+ A group's children show while its ID is in `expandedResourceIds`. The chevron beside a group's name
69
+ toggles it. To control expansion yourself, pass `expandedResourceIds` and
70
+ `onExpandedResourceIdsChange`. Groups start collapsed unless you list them in
71
+ `defaultExpandedResourceIds`.
72
+
73
+ ## Anatomy
74
+
75
+ `ResourceTimelineView` renders the parts below. The view builds them itself from its projection, so
76
+ they're not parts you compose: to change one, edit its file. The tree shows where each part lives.
77
+
78
+ > Diagram: see it at https://time.molten.sh/docs/react/views/resource-timeline
79
+
80
+ ```txt title="Rendered by ResourceTimelineView"
81
+ ResourceTimelineView resource-timeline-view.tsx
82
+ └── ResourceTimelineGrid resource-timeline-grid.tsx, scrolls both ways
83
+ ├── ResourceTimelineHeader resource-timeline-header.tsx, sticky at the top
84
+ │ ├── Date or month stays in view while you scroll sideways
85
+ │ └── Hour or day one per rendered slot
86
+ ├── ResourceTimelineRow resource-timeline-row.tsx, one per rendered resource
87
+ │ ├── Resource name sticky at the inline start, with a group's toggle
88
+ │ └── Cell one per rendered slot
89
+ │ ├── Day data-date, in a week or a month
90
+ │ ├── Date strip data-axis="inline" and data-date, in a day
91
+ │ ├── ResourceTimelineEvent resource-timeline-event.tsx
92
+ │ └── Keyboard cursor resource-timeline-focus.tsx, on the focused cell
93
+ └── Now line data-slot="resource-timeline-now"
94
+ ```
95
+
96
+ - `useTimelineVirtualizer` in `use-timeline-virtualizer.ts` decides which rows and slots render:
97
+ the ones in view, a few beyond, and the focused ones. Slots share the width the resource column
98
+ leaves until they are 56px for an hour or 48px for a day, then the view scrolls sideways. The
99
+ resource column is 208px wide, or 128px on narrow screens.
100
+ - The header and the resource column are `position: sticky` inside the one scrolling element, so
101
+ they move with it exactly and a row's name stays inside its row for screen readers.
102
+ - `timeline-placement.ts` puts each bar in the first rendered cell it covers, so a bar that starts
103
+ off-screen still shows. A row is as tall as its lanes, or its stacks, need, and at least 44px.
104
+
105
+ ## Options
106
+
107
+ | Name | Type | Default | Description |
108
+ | -------------------------- | ----------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
109
+ | `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
110
+ | `dragPreview` | `"snapped" \| "free"` | `"snapped"` | How a drag's preview moves: from slot to slot, or with the pointer over a marker of where it would land, snapping there on release. See [snapped and free drags](../interactions.md#snapped-and-free-drags). |
111
+ | `getEventColor` | `(event: TEvent) => CalendarEventColor \| undefined` | | The color for each event. See [event colors](../theming.md#event-colors). |
112
+ | `getEventIcon` | `(event: TEvent) => ReactNode` | | A small icon before each event's title, such as a repeat mark on recurring events, or nothing. It's decorative and hidden from screen readers: say the same in `describeEvent`, which adds to the event's [accessible name](../accessibility.md#event-names). |
113
+ | `getEventOverlapLayout` | `(event: TEvent) => "columns" \| "equal" \| "stack" \| undefined` | | In an hour timeline, an event's own layout, such as its calendar's: a group of overlapping events in a row takes it when they all agree. See [stacked rows](#stacked-rows). |
114
+ | `getResourceOverlapLayout` | `(resource: TResource) => "columns" \| "equal" \| "stack" \| undefined` | | In an hour timeline, a resource's layout in its row, such as `"stack"` for rooms; `undefined` keeps `overlapLayout`. |
115
+ | `overlapLayout` | `"columns" \| "equal" \| "stack"` | `"columns"` | In an hour timeline, how a row shares out overlapping events: a lane for each level of overlap, or `"stack"` to cascade them. See [stacked rows](#stacked-rows). |
116
+ | `slotUnit` | `"hour" \| "day"` | | What a column spans: hours for a day and days for a week or a month unless you set it. |
117
+ | `unassigned` | `"hide" \| "bucket"` | `"hide"` | Events that book no resources: hidden, or shown in an "Unassigned" row after the resources. |
118
+ | `renderUnavailable` | `UnavailableTimeRender` | | Replaces the shading of closed time and closed days: a function of its props and its state. See [customize the shading](../availability.md#customize-the-shading). |
119
+ | `resourceStatus` | `boolean \| ResourceStatusOptions` | | Shows each resource's status, such as "Busy until 3:00 PM". See [busy badge](../availability.md#busy-badge-in-resource-views). |
120
+
121
+ Set options when you create the view, or per calendar with
122
+ `viewOptions={{ "timeline-week": { unassigned: "bucket" } }}` on `Root`.
123
+
124
+ ## What it shows
125
+
126
+ - **Header:** the hours under their date, or the days under their month with today highlighted and
127
+ marked `aria-current="date"`. Weekends are tinted down every row.
128
+ - **Rows:** each resource's name, indented under its group. Groups are tinted, and their chevron
129
+ shows or hides their children.
130
+ - **Events over days:** laid out like a [month](./month.md) row. A timed event within one
131
+ day shows its title and start time, as "Standup 9:30 AM", and drops the time when the day is too
132
+ narrow. Longer events span their days.
133
+ - **Events over hours:** each bar spans its exact times, on the same 24-hour wall clock as the
134
+ [day view](./week-and-day.md). Hours skipped when the clocks go forward are hatched, and
135
+ hours repeated when they go back are tinted.
136
+ - **Both:** an event that starts before or ends after the range is squared off at that edge.
137
+ Events that overlap sit in lanes, and the row grows to fit them. Over hours, a row can
138
+ [stack](#stacked-rows) them instead.
139
+ - **Current time:** a line through today at the current time, from
140
+ [`useNow()`](../concepts/time.md#the-current-time). A day opens scrolled to it, or to 08:00 when
141
+ today isn't shown.
142
+ - **Editing:** with `onEventChange` on `Root`, drag an event along its row to move it, or onto
143
+ another row to move it to that resource. A move swaps the resource you dragged from for the one
144
+ you dropped on and keeps the event's other resources. Drag an event's start or end edge to resize
145
+ it, and drag across empty time to create an event in that resource. Over days these steps are
146
+ whole days, and an event keeps its time; over hours they're half hours. See
147
+ [Interactions](../interactions.md#drag-resize-and-create).
148
+ - **Accessible names:** the grid is named after the range, each row after its resource, and each
149
+ cell after its resource, time and number of events, as in "Orchid, Monday, October 5, 2026, 2
150
+ events". Events end with their resource, as in "Design review, Tuesday, October 6, 10:00 – 11:30
151
+ AM, Orchid".
152
+
153
+ A day of rooms and people, in hours:
154
+
155
+ > Live example of the `timeline-day` view: see it at https://time.molten.sh/docs/react/views/resource-timeline
156
+
157
+ ## Stacked rows
158
+
159
+ A busy room takes a lane for each level of overlap, so its row grows. In an hour timeline,
160
+ `overlapLayout: "stack"` cascades a row's overlapping events instead: each bar sits a third of a
161
+ lane below the one it covers and is drawn over it, and a deep stack steps less, so the row is never
162
+ more than two lanes tall. `getResourceOverlapLayout` picks it per resource, as in
163
+ [resource columns](./resource-columns.md#rooms-and-people):
164
+
165
+ > Live example of the `timeline-day` view: see it at https://time.molten.sh/docs/react/views/resource-timeline
166
+
167
+ ```tsx
168
+ const view = createTimelineDayView<Meeting, Resource>({
169
+ getResourceOverlapLayout: (resource) => (resource.data.kind === "room" ? "stack" : undefined),
170
+ });
171
+ ```
172
+
173
+ - `"columns"` and `"equal"` are the same here: a lane per level of overlap. A row has no fixed
174
+ height to share, so no bar narrows.
175
+ - A group's deepest bar sets its step, so a long booking under a busy stretch, such as a desk
176
+ booked all day, compresses every cascade in it. Hover or focus a covered bar to bring it up.
177
+ - The rules are the time grid's. A group of overlapping events takes its events' own layout,
178
+ from `getEventOverlapLayout`, when they all agree, and otherwise its row's. A group's layout
179
+ depends only on its own events. The Unassigned row follows `overlapLayout`.
180
+ - Bars are drawn in time order, so each covers the ones before it. A covered bar rises while you
181
+ hover over it or focus it, so its title shows. ← and → walk a row's bars in the same order, and
182
+ Enter on a cell starts at the bar the others cover, as in lanes.
183
+ - A day timeline lays each row out like a month row, whatever the layout, as the time grid's
184
+ all-day row does.
185
+
186
+ ## Keyboard
187
+
188
+ Tab into a preview, or click a cell, and try these keys. The
189
+ [Accessibility](../accessibility.md#keyboard) page has the full map and what a screen reader hears.
190
+
191
+ | Focus | Key | Effect |
192
+ | -------------- | ------------------ | ------------------------------------------------------------------------ |
193
+ | A cell | ← → | Previous or next day, or half hour in a day |
194
+ | A cell | ↑ ↓ | The same time in the previous or next row |
195
+ | A cell | Home, End | The first or last day or half hour shown |
196
+ | A cell | Page Up, Page Down | Back or forward a whole day, week or month |
197
+ | A cell | Enter | The events covering it in that row. Escape goes back to the event's cell |
198
+ | An event | ← → | Previous or next event in the row |
199
+ | An event | ↑ ↓ | The cell at its start in the previous or next row |
200
+ | A group's cell | Shift+Enter | Expand or collapse the group |
201
+ | A day | Space | Start an all-day event there. Arrow keys extend it, and Enter saves it |
202
+ | A half hour | Space | Start an hour-long event there. Arrow keys extend it, and Enter saves it |
203
+ | An event | Space | Pick it up. Arrow keys move it along its row and to other rows |
204
+ | An event | Shift+Space | Pick up its end to resize it. Shift+Space again switches to its start |
205
+
206
+ Enter drops a picked-up event and Escape puts it back. Moving it to another row moves it to that
207
+ resource, the same change as dropping it there with the pointer, and
208
+ [announcements](../accessibility.md#announcements) name the resource: "Moved Design review to
209
+ Tuesday, October 6, 10:00 – 11:30 AM, Lotus." Focus is a resource and a time, not an element, so
210
+ it survives scrolling: the focused row and slot keep rendering wherever you scroll, and each key
211
+ brings its target into view.
212
+
213
+ ## Markup for interactions
214
+
215
+ The view connects the pointer layer for you. Each resource's row has `resourceIdAttributes(id)`,
216
+ which sets `data-resource-id`: a drop or create inside it lands in that resource.
217
+
218
+ - **Over days:** each day cell has an inner element with `data-date`, beside the events rather than
219
+ around them, so dragging an event by a later day moves it from that day.
220
+ - **Over hours:** each row has a `data-axis="inline"` strip with `data-date` for every date, and
221
+ the view passes its projection's `columns` to the pointer layer, which maps a position along the
222
+ strip to a wall time.
223
+ - **Events:** they're buttons with `data-event-id`, and events you can edit have
224
+ `data-resize="start"` and `data-resize="end"` handles.
225
+ - **Sticky parts:** the header and each row's name have `data-occludes`, so the pointer layer
226
+ doesn't look through them to the cells scrolled beneath.
@@ -0,0 +1,193 @@
1
+ # Scrolling views
2
+
3
+ Week, day and month views that scroll without end, swiping a page at a time.
4
+
5
+ Source: https://time.molten.sh/docs/react/views/scrolling
6
+
7
+ **Week**
8
+
9
+ > Live example of the `scrolling-week` view: see it at https://time.molten.sh/docs/react/views/scrolling
10
+
11
+ **3 days**
12
+
13
+ > Live example of the `scrolling-3-day` view: see it at https://time.molten.sh/docs/react/views/scrolling
14
+
15
+ **Day**
16
+
17
+ > Live example of the `scrolling-day` view: see it at https://time.molten.sh/docs/react/views/scrolling
18
+
19
+ Try them in the [live demo](https://moltenship-time-demo.vercel.app): turn on "Scroll days, weeks,
20
+ months and agenda" in the settings.
21
+
22
+ The [week and day](./week-and-day.md) and [month](./month.md) views move a page at a
23
+ time. The scrolling versions follow your finger, as Apple's Calendar does on iPad, and swipe a page at a
24
+ time: the week and day views sideways, so a week comes to rest on the next week and a day on the
25
+ next day, and the month up and down, a month at a time. They're separate views, so the paged ones
26
+ keep working as they are, and you can register both. The
27
+ [scrolling agenda](./agenda.md#scrolling-agenda) scrolls a list of days the same way, comes
28
+ to rest on any day, and jumps to a date at once.
29
+
30
+ ## Add them
31
+
32
+ Add the views to your app with the shadcn CLI, as described in
33
+ [UI source](../installation.md#ui-source-optional). The items bring what they build on:
34
+ `time-grid-view` and `month-view`, the theme, and the shared `calendar` parts.
35
+
36
+ ```bash
37
+ npx shadcn@latest add \
38
+ https://time.molten.sh/r/scrolling-time-grid-view.json \
39
+ https://time.molten.sh/r/scrolling-month-view.json
40
+ ```
41
+
42
+ Then register the views:
43
+
44
+ ```tsx title="calendar.tsx"
45
+ import { createCalendar, iteratePlainDates, type CalendarVisibleRange } from "@moltenship/calendar";
46
+ import { useCallback, useMemo, useRef, useState } from "react";
47
+
48
+ import { createScrollingMonthView } from "@/components/calendar/scrolling-month-view/scrolling-month-view";
49
+ import {
50
+ createScrollingDayView,
51
+ createScrollingThreeDayView,
52
+ createScrollingWeekView,
53
+ } from "@/components/calendar/scrolling-time-grid-view/scrolling-time-grid-view";
54
+
55
+ import { eventAdapter, weekRules, type Meeting } from "./quick-start";
56
+
57
+ const getEventColor = (meeting: Meeting) => meeting.color;
58
+
59
+ export const Calendar = createCalendar<Meeting>()({
60
+ eventAdapter,
61
+ views: [
62
+ createScrollingWeekView<Meeting>({ dayView: "scrolling-day", getEventColor }),
63
+ createScrollingThreeDayView<Meeting>({ dayView: "scrolling-day", getEventColor }),
64
+ createScrollingDayView<Meeting>({ getEventColor }),
65
+ createScrollingMonthView<Meeting>({ dayView: "scrolling-day", getEventColor }),
66
+ ],
67
+ });
68
+ ```
69
+
70
+ The views are named `scrolling-week`, `scrolling-3-day`, `scrolling-day`, and `scrolling-month`,
71
+ and take the same options as their paged versions. `dayView` names the view a date opens; it
72
+ defaults to `"day"` in the month. For another number of days, define a view with
73
+ `scrollingTimeGridStrategy({ count, kind: "days" })` and `ScrollingTimeGridView`, as
74
+ `createScrollingThreeDayView` does; it swipes that many days at a time.
75
+
76
+ ## How they move
77
+
78
+ | View | Shows | A swipe moves | Previous and Next | Today |
79
+ | ------------------ | --------------------------------------------------------------------------------------------------- | ------------- | ----------------- | ------------------------- |
80
+ | `scrolling-week` | The anchor's week, from `weekRules` | A week | A week | Today's week |
81
+ | `scrolling-3-day` | Three days from the anchor date | Three days | Three days | Today in the first column |
82
+ | `scrolling-day` | The anchor date | A day | A day | Today |
83
+ | `scrolling-month` | Six weeks from the week of the 1st, or up to twelve with `createScrollingMonthView(options, weeks)` | A month | A month | Today's month |
84
+ | `scrolling-agenda` | Four weeks from the anchor date | Free, any day | Four weeks | Today on top |
85
+
86
+ The anchor date is the scroll position. A swipe follows your finger and comes to rest on the
87
+ next page, or back on this one if it went less than halfway; a fling moves one page. When a
88
+ scroll comes to rest, the view sets `anchorDate` to what it shows, so `Calendar.Title`, `onAnchorDateChange`, and a URL that stores the date follow the
89
+ scroll. During a long swipe the anchor follows every half page. When the anchor changes any other
90
+ way, from Today, Next, or your own `setAnchorDate`, the view scrolls there: smoothly over a page or
91
+ two, and at once from further away, from the keyboard, or when the system asks for reduced motion.
92
+ With a controlled `anchorDate`, the view stays where it was scrolled until your state takes the
93
+ latest date `onAnchorDateChange` sent, even a few renders later; any other `anchorDate` moves the
94
+ view to it. If you defer the update, commit the latest date rather than each one in turn.
95
+
96
+ The month shows the anchor's month as the paged month does: six weeks from the one that holds its
97
+ first day, which every month fits, with the days of other months dimmed. A swipe comes to rest on
98
+ the next month with its first week on top, four or five weeks on, so the distance varies.
99
+
100
+ > Live example of the `scrolling-month` view: see it at https://time.molten.sh/docs/react/views/scrolling
101
+
102
+ ## Loading events as you scroll
103
+
104
+ Each scrolling view renders a page of days or weeks on either side of what it shows, with their
105
+ events, so a swipe never reveals an empty page. Its strategy reports those dates as its
106
+ **load range**, and `onVisibleRangeChange` on `Root` hands them to you: after the first render, and
107
+ whenever the view, its dates, or the time zone change, but not when only `events` do.
108
+
109
+ Fetch events for `loadRange` and pass them in `events`. The next page is then loaded before it
110
+ scrolls into view:
111
+
112
+ ```tsx title="scrolling-calendar.tsx"
113
+ const timeZone = "Europe/Berlin";
114
+
115
+ /** Fetches meetings for the dates the view needs, each date once, and keeps what arrived. */
116
+ export function ScrollingCalendar({
117
+ loadMeetings,
118
+ }: {
119
+ readonly loadMeetings: (from: Temporal.Instant, to: Temporal.Instant) => Promise<Meeting[]>;
120
+ }) {
121
+ const [loaded, setLoaded] = useState<ReadonlyMap<string, Meeting>>(new Map());
122
+ const requested = useRef(new Set<string>());
123
+ const meetings = useMemo(() => [...loaded.values()], [loaded]);
124
+
125
+ const load = useCallback(
126
+ ({ loadRange }: CalendarVisibleRange) => {
127
+ const missing = [...iteratePlainDates(loadRange)].filter(
128
+ (date) => !requested.current.has(date.toString()),
129
+ );
130
+ if (missing.length === 0) return;
131
+ for (const date of missing) requested.current.add(date.toString());
132
+ const from = missing[0]!.toZonedDateTime(timeZone).toInstant();
133
+ const to = missing.at(-1)!.add({ days: 1 }).toZonedDateTime(timeZone).toInstant();
134
+ void loadMeetings(from, to).then((arrived) =>
135
+ setLoaded((current) => new Map([...current, ...arrived.map((m) => [m.id, m] as const)])),
136
+ );
137
+ },
138
+ [loadMeetings],
139
+ );
140
+
141
+ return (
142
+ <Calendar.Root
143
+ events={meetings}
144
+ defaultAnchorDate={Temporal.Now.plainDateISO(timeZone)}
145
+ onVisibleRangeChange={load}
146
+ timeZone={timeZone}
147
+ locale="en-US"
148
+ weekRules={weekRules}
149
+ >
150
+ <Calendar.ActiveView />
151
+ </Calendar.Root>
152
+ );
153
+ }
154
+ ```
155
+
156
+ | Field | Contents |
157
+ | ------------------ | ------------------------------------------------------------ |
158
+ | `view` | The active view's name |
159
+ | `range` | The visible dates |
160
+ | `instantRange` | `range` as instants in the calendar's time zone |
161
+ | `loadRange` | The dates to have events for: `range` and a page either side |
162
+ | `loadInstantRange` | `loadRange` as instants, ready to send to an API |
163
+
164
+ Paged views report too: their `loadRange` is the visible `range`. Time still never fetches or keeps
165
+ events itself; keep what you've loaded in your own state. To load them with TanStack Query, see
166
+ [Load events with TanStack Query](../guides/tanstack-query.md).
167
+
168
+ ## Keyboard
169
+
170
+ The keys work as in the [week and day](./week-and-day.md#keyboard) and
171
+ [month](./month.md) views, over the dates on screen. Moving past the last visible day, or
172
+ pressing Page Down, scrolls a whole page. Days and weeks rendered around the visible ones are hidden
173
+ from screen readers, so the grid reads as one week, one day, or six weeks.
174
+
175
+ ## Dragging
176
+
177
+ Drag, resize, and create work as in the paged views. Dragging toward an edge keeps scrolling into
178
+ the days or weeks beyond, rendering them as it goes. The week and day views stop snapping while a
179
+ gesture is under way, and come to rest on the nearest page when you let go. The `dragPreview`
180
+ option picks [snapped or free drags](../interactions.md#snapped-and-free-drags) here too.
181
+
182
+ ## How it's built
183
+
184
+ `useScrollingAxis` in `registry/calendar/scrolling-axis.tsx` places days, or weeks, on an axis
185
+ thousands of items long, and the view renders only the items near its load range. The header,
186
+ all-day row, and hour gutter are sticky in the same scrolling element, so they never lag behind the
187
+ days. The gutter's [secondary time zones](./week-and-day.md#secondary-time-zones) follow the
188
+ first visible day on which neither zone changes its clocks. Scroll positions are never React
189
+ state: the view renders again only when the anchor moves.
190
+
191
+ Server markup puts the visible dates at the start of the axis, so the page shows them before
192
+ scripts run. Once laid out, the axis extends before them and the scroll position follows, before
193
+ the browser paints. In right-to-left layouts, pass `direction="rtl"` to `Root`.