@moltenship/calendar 1.0.0-rc.1 → 2.0.0-beta.1

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 (70) hide show
  1. package/README.md +24 -4
  2. package/dist/index.d.mts +2 -2
  3. package/docs/accessibility.md +304 -0
  4. package/docs/agents/changes.md +449 -0
  5. package/docs/agents/coding-agents.md +117 -0
  6. package/docs/agents/connect.md +435 -0
  7. package/docs/agents/deleting.md +296 -0
  8. package/docs/agents/reference.md +512 -0
  9. package/docs/agents/server.md +317 -0
  10. package/docs/agents/webmcp.md +153 -0
  11. package/docs/agents.md +353 -0
  12. package/docs/annotations.md +196 -0
  13. package/docs/api/changes.md +248 -0
  14. package/docs/api/dnd-kit.md +267 -0
  15. package/docs/api/events.md +152 -0
  16. package/docs/api/ics.md +524 -0
  17. package/docs/api/primitives.md +168 -0
  18. package/docs/api/react.md +236 -0
  19. package/docs/api/recurrence.md +586 -0
  20. package/docs/api/solid.md +460 -0
  21. package/docs/api/store.md +92 -0
  22. package/docs/api/temporal.md +172 -0
  23. package/docs/api.md +57 -0
  24. package/docs/availability.md +573 -0
  25. package/docs/comparison.md +279 -0
  26. package/docs/concepts/anatomy.md +73 -0
  27. package/docs/concepts/events.md +164 -0
  28. package/docs/concepts/how-it-works.md +95 -0
  29. package/docs/concepts/recurrence.md +127 -0
  30. package/docs/concepts/state.md +244 -0
  31. package/docs/concepts/time.md +170 -0
  32. package/docs/guides/dnd-kit.md +333 -0
  33. package/docs/guides/google-calendar-sync.md +1246 -0
  34. package/docs/guides/google-calendar.md +367 -0
  35. package/docs/guides/ics.md +486 -0
  36. package/docs/guides/motion.md +414 -0
  37. package/docs/guides/nextjs-app-router.md +630 -0
  38. package/docs/guides/nextjs.md +149 -0
  39. package/docs/guides/performance.md +103 -0
  40. package/docs/guides/recurring-events.md +583 -0
  41. package/docs/guides/tanstack-query.md +485 -0
  42. package/docs/index.md +118 -0
  43. package/docs/installation.md +194 -0
  44. package/docs/interactions.md +408 -0
  45. package/docs/llms.txt +86 -0
  46. package/docs/migrating-to-2.md +322 -0
  47. package/docs/quick-start.md +159 -0
  48. package/docs/stylex.md +265 -0
  49. package/docs/testing.md +581 -0
  50. package/docs/theme-builder.md +81 -0
  51. package/docs/theming.md +169 -0
  52. package/docs/undo-redo.md +339 -0
  53. package/docs/views/agenda.md +221 -0
  54. package/docs/views/custom-views.md +192 -0
  55. package/docs/views/month.md +109 -0
  56. package/docs/views/resource-columns.md +261 -0
  57. package/docs/views/resource-timeline.md +225 -0
  58. package/docs/views/scrolling.md +192 -0
  59. package/docs/views/week-and-day.md +257 -0
  60. package/docs/views/year.md +138 -0
  61. package/docs/views.md +69 -0
  62. package/package.json +41 -14
  63. package/skills/moltenship-time/SKILL.md +75 -0
  64. package/skills/moltenship-time/references/agent-ready.md +272 -0
  65. package/skills/moltenship-time/references/changes.md +188 -0
  66. package/skills/moltenship-time/references/compose.md +168 -0
  67. package/skills/moltenship-time/references/mistakes.md +98 -0
  68. package/skills/moltenship-time/references/solid.md +202 -0
  69. package/skills/moltenship-time/references/state.md +129 -0
  70. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,192 @@
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/views/scrolling
6
+
7
+ **Week**
8
+
9
+ > Live example of the `scrolling-week` view: see it at https://time.molten.sh/docs/views/scrolling
10
+
11
+ **3 days**
12
+
13
+ > Live example of the `scrolling-3-day` view: see it at https://time.molten.sh/docs/views/scrolling
14
+
15
+ **Day**
16
+
17
+ > Live example of the `scrolling-day` view: see it at https://time.molten.sh/docs/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/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.
180
+
181
+ ## How it's built
182
+
183
+ `useScrollingAxis` in `registry/calendar/scrolling-axis.tsx` places days, or weeks, on an axis
184
+ thousands of items long, and the view renders only the items near its load range. The header,
185
+ all-day row, and hour gutter are sticky in the same scrolling element, so they never lag behind the
186
+ days. The gutter's [secondary time zones](./week-and-day.md#secondary-time-zones) follow the
187
+ first visible day on which neither zone changes its clocks. Scroll positions are never React
188
+ state: the view renders again only when the anchor moves.
189
+
190
+ Server markup puts the visible dates at the start of the axis, so the page shows them before
191
+ scripts run. Once laid out, the axis extends before them and the scroll position follows, before
192
+ the browser paints. In right-to-left layouts, pass `direction="rtl"` to `Root`.
@@ -0,0 +1,257 @@
1
+ # Week and day
2
+
3
+ Time-grid views with an all-day row, a current-time line, and DST-aware hours.
4
+
5
+ Source: https://time.molten.sh/docs/views/week-and-day
6
+
7
+ > Live example of the `week` view: see it at https://time.molten.sh/docs/views/week-and-day
8
+
9
+ Try both views in the [live demo](https://moltenship-time-demo.vercel.app).
10
+
11
+ `createWeekView` and `createDayView` show the hours of the day down the side and one column per day.
12
+ The week view has seven columns, starting on `weekRules.firstDay`. The day view has one column for
13
+ the anchor date. `createThreeDayView` has three, from the anchor date: on a phone, where a week's
14
+ seven columns are too narrow to read, it shows more than a day.
15
+
16
+ ## Add them
17
+
18
+ Add the views to your app with the shadcn CLI, as described in
19
+ [UI source](../installation.md#ui-source-optional). The item brings the theme, the shared
20
+ `calendar` parts, and the shadcn components it uses:
21
+
22
+ ```bash
23
+ npx shadcn@latest add https://time.molten.sh/r/time-grid-view.json
24
+ ```
25
+
26
+ Then register the views:
27
+
28
+ ```tsx
29
+ import { createDayView, createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
30
+
31
+ const getEventColor = (meeting: Meeting) => meeting.color;
32
+
33
+ export const Calendar = createCalendar<Meeting>()({
34
+ eventAdapter,
35
+ views: [
36
+ createWeekView<Meeting>({ dayView: "day", getEventColor }),
37
+ createDayView<Meeting>({ getEventColor }),
38
+ ],
39
+ });
40
+ ```
41
+
42
+ The views are named `week`, `day` and `3-day`. Pass your event type, as in
43
+ `createWeekView<Meeting>`, so `getEventColor` receives your records.
44
+
45
+ ## Anatomy
46
+
47
+ All three views render `TimeGridView` from `registry/time-grid-view`, with seven day columns for the
48
+ week, three for the 3-day view and one for the day. The view builds these parts itself, so they're
49
+ not parts you compose: to change one, edit its file. The tree shows where each part lives.
50
+
51
+ > Diagram: see it at https://time.molten.sh/docs/views/week-and-day
52
+
53
+ ```txt title="Rendered by TimeGridView"
54
+ TimeGridView time-grid-view.tsx
55
+ ├── TimeGridHeader time-grid-header.tsx
56
+ ├── TimeGridAllDay time-grid-all-day.tsx
57
+ └── TimeGridBody time-grid-body.tsx, scrolls
58
+ ├── Time gutter --calendar-gutter-width
59
+ │ └── TimeGridZoneHours time-grid-zones.tsx, one per secondary time zone
60
+ └── TimeGridColumn time-grid-column.tsx, one per day, data-date
61
+ ├── TimeGridEvent time-grid-event.tsx
62
+ │ ├── Title and time
63
+ │ └── Resize handles data-resize="start" and "end"
64
+ └── Now line data-slot="time-grid-now"
65
+ ```
66
+
67
+ - The gutter is `--calendar-gutter-width` wide: `--calendar-hours-width` for the hours (3rem, or
68
+ 4rem from the `sm` breakpoint), plus `--calendar-zone-width` (4rem) for each
69
+ [secondary time zone](#secondary-time-zones). To change the hours' width, edit
70
+ `--calendar-hours-width` in `time-grid-zones.tsx`.
71
+ - An event's `TimeGridEventLayout` sets its `top` and `height` from its times, and its `left` and
72
+ `width` from the [overlap layout](#overlapping-events). A column renders its events in layout
73
+ order, so a stacked event draws over the ones it overlaps.
74
+ - `useNow()` moves the now line.
75
+
76
+ ## Options
77
+
78
+ | Name | Type | Default | Description |
79
+ | ----------------------- | ----------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
80
+ | `dayView` | `string` | | A registered view that opens when you click a date in the header, usually `"day"`. Without it the header dates are plain text. |
81
+ | `getEventColor` | `(event: TEvent) => CalendarEventColor \| undefined` | | The color for each event. See [event colors](../theming.md#event-colors). |
82
+ | `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). |
83
+ | `getEventOverlapLayout` | `(event: TEvent) => "columns" \| "equal" \| "stack" \| undefined` | | An event's own layout, such as its calendar's. A group of overlapping events takes it when they all agree. See [by calendar](#by-calendar). |
84
+ | `overlapLayout` | `"columns" \| "equal" \| "stack"` | `"columns"` | How overlapping events share a day column. See [overlapping events](#overlapping-events). |
85
+ | `stackIndent` | `number` | `0.15` | How far each level of a stack is indented, as a fraction of the column width, the same for every stacked group. A value that isn't positive throws, whatever the layout. |
86
+ | `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
87
+ | `renderUnavailable` | `UnavailableTimeRender` | | Replaces the shading of closed time: an element, or a function of its props. See [customize the shading](../availability.md#customize-the-shading). |
88
+ | `annotations` | `TimeGridAnnotationOptions` | | How the root's annotations draw: a rail beside the events or an overlay (`placement`), the rail's size and side, or your own parts. See [Annotations](../annotations.md#options). |
89
+
90
+ Set options when you create the view, or per calendar with
91
+ `viewOptions={{ week: { dayView: "day" } }}` on `Root`.
92
+
93
+ ## What it shows
94
+
95
+ - **Header:** the weekday and date of each column, with today highlighted and marked
96
+ `aria-current="date"`. The corner shows the time zone's offset, such as "GMT+2", after the name
97
+ of each [secondary time zone](#secondary-time-zones).
98
+ - **All-day row:** all-day events, plus timed and floating events that last 24 hours or more. Busy days collapse
99
+ to three rows with "+N more", and a chevron in the corner expands the row.
100
+ - **Hours:** labels come from `Intl`, so they read "1 PM" or "13:00" depending on the locale. Each hour
101
+ is `--calendar-hour-height` tall (3rem by default).
102
+ - **Events:** overlapping events sit side by side, or as `overlapLayout` sets. Events shorter than 45 minutes show on one line,
103
+ as "Standup, 9:30 AM". Events that run past midnight show their real times on both days, as
104
+ "10:00 PM – 2:00 AM". A title that doesn't fit its event shows in full in a tooltip while you
105
+ hover or focus the event.
106
+ - **Daylight saving time:** hours skipped when the clocks go forward are hatched, and hours repeated
107
+ when they go back are tinted, with both occurrences side by side.
108
+ - **Current time:** a line across today's column, from [`useNow()`](../concepts/time.md#the-current-time).
109
+ The grid opens scrolled to the current time, or to 08:00 when today isn't visible, and keeps its
110
+ scroll position when you move between weeks.
111
+ - **Editing:** with `onEventChange` on `Root`, drag an event to move it (onto the all-day row to
112
+ make it all-day), drag its top or bottom edge to resize it, and drag across empty time or all-day
113
+ cells to create one. See [Interactions](../interactions.md#drag-resize-and-create).
114
+ - **Changes being saved:** events with a [pending change](../interactions.md#pending-changes) get
115
+ `data-pending` and render at 60% opacity.
116
+
117
+ The day view works on narrow screens:
118
+
119
+ > Live example of the `day` view: see it at https://time.molten.sh/docs/views/week-and-day
120
+
121
+ ## Overlapping events
122
+
123
+ `overlapLayout` sets how events that overlap share a day column. Switch between the layouts here,
124
+ and drag an event to see the others make room. "Stack focus time" gives the purple focus time
125
+ calendar a layout of its own, as [by calendar](#by-calendar) describes:
126
+
127
+ > Live example: see it at https://time.molten.sh/docs/views/week-and-day
128
+
129
+ - **`"columns"`** (the default) puts overlapping events side by side, in as few lanes as they
130
+ need. Each event widens into lanes that stay free beside it, as Google Calendar draws them.
131
+ - **`"equal"`** uses the same lanes, but every event in a busy stretch is one lane wide, so the
132
+ lanes line up.
133
+ - **`"stack"`** cascades them. Each event is indented past the earlier events it overlaps and drawn
134
+ on top of them, reaching to the column's end. `stackIndent` sets the indent as a fraction of the
135
+ column width (0.15 by default). A deep stack indents less, so the top event keeps at least half
136
+ the column. Hover or focus a covered event to bring it to the top and read its title.
137
+
138
+ ```tsx
139
+ createWeekView<Meeting>({ dayView: "day", overlapLayout: "stack" });
140
+
141
+ // Or switch it at runtime, per view:
142
+ <Calendar.Root viewOptions={{ week: { overlapLayout }, day: { overlapLayout } }} />;
143
+ ```
144
+
145
+ Every layout keeps the same rules:
146
+
147
+ - Events that touch, one ending as the next starts, don't overlap. An event shorter than 15
148
+ minutes still takes up 15 so it stays readable, so it can overlap the next one.
149
+ - Overlapping events form a group, laid out on its own, so a change to one group never moves
150
+ events in another.
151
+ - The order is fixed: by start, then longer first, then event ID. It's the order events are drawn
152
+ in, and the order ↑ and ↓ walk them. ← and → step to the overlapping event drawn beside, and
153
+ mirror right to left.
154
+ - An event picked up with the keyboard, and changes still being saved, are laid out the same way,
155
+ so an event lands where it will stay.
156
+
157
+ The resource columns view takes the same options, for each resource's column, and can give each
158
+ resource a layout of its own: see [rooms and people](./resource-columns.md#rooms-and-people).
159
+ The [scrolling](./scrolling.md) week and day views take them too.
160
+
161
+ ### By calendar
162
+
163
+ `getEventOverlapLayout` gives events a layout of their own, usually their calendar's. Return
164
+ `undefined` for events that should follow the view's `overlapLayout`:
165
+
166
+ ```tsx
167
+ const layouts: Partial<Record<CalendarId, OverlapLayout>> = { focus: "stack" };
168
+
169
+ createWeekView<Meeting>({
170
+ getEventOverlapLayout: (meeting) => layouts[meeting.calendarId],
171
+ });
172
+ ```
173
+
174
+ One column can hold a group of overlapping events from several calendars, and a group is drawn
175
+ one way. So a group takes its events' own layout only when they all agree, and otherwise the
176
+ view's `overlapLayout`. An event without a layout of its own counts as the view's.
177
+
178
+ - An afternoon of focus time stacks, while a focus block that overlaps a meeting stays in lanes
179
+ beside it.
180
+ - A group's layout depends only on its own events, so an event that overlaps none of them never
181
+ changes how they're drawn. An event that joins a group from another calendar can switch the
182
+ group back to the view's layout, as joining a group already redraws it.
183
+ - Agreement doesn't depend on order, and `stackIndent` is the same for every stacked group.
184
+ - While an event is being moved or saved, `getEventOverlapLayout` still gets the event as you
185
+ stored it, not its new time or resources. Base it on what a move doesn't change, such as the
186
+ calendar.
187
+
188
+ ## Secondary time zones
189
+
190
+ Pass `secondaryTimeZones` to `Root` to label the hours in other time zones too, like Google
191
+ Calendar's secondary time zone. Each zone gets a column of hours beside the calendar's own:
192
+
193
+ > Live example: see it at https://time.molten.sh/docs/views/week-and-day
194
+
195
+ ```tsx
196
+ <Calendar.Root
197
+ timeZone="Europe/Berlin"
198
+ secondaryTimeZones={["America/New_York", { timeZone: "Asia/Tokyo", label: "Tokyo" }]}
199
+ // …
200
+ />
201
+ ```
202
+
203
+ - **Names:** each column is named by its `label`, or by the zone's short name from `Intl` in the
204
+ calendar's locale, such as "EDT" or "GMT+5:30". Without a `label`, hover it for the zone's full
205
+ name.
206
+ - **Hours:** each line is read on its own date, in both zones' rules, so the labels stay right when
207
+ either zone changes its clocks. Zones off the hour show minutes, such as "4:30 PM" in India.
208
+ "+1" or "-1" marks a time on the next or previous day there.
209
+ - **Daylight saving time:** an hour the calendar's zone skips has no label, and an hour it repeats
210
+ shows its first time. The gutter follows the first day shown on which neither zone changes its
211
+ clocks. A day that reads differently, because a zone changes its offset, says so under its date,
212
+ such as "EST -1h". Hover the note to see from when, and until when if it ends that day.
213
+ - **Width:** each zone's column is `--calendar-zone-width` wide, 4rem by default, which fits
214
+ "12:30 AM+1". Some locales write longer times; set the variable to a rem or px length on an
215
+ element around the calendar, such as `[--calendar-zone-width:4.5rem]`.
216
+ - **Clock:** 12 or 24 hours, as the locale says, including a `-u-hc-h23` extension.
217
+ - **Screen readers:** the extra hours are hidden, like the calendar's own hour labels, so the grid's
218
+ columns stay the same. A focused slot names its time in each zone instead, as in "Monday,
219
+ October 12 at 9:00 PM, 3:00 PM Eastern Daylight Time". Each time is named as its zone is at that
220
+ moment, so the hour repeated in London reads "1:30 AM British Summer Time or 1:30 AM Greenwich
221
+ Mean Time".
222
+
223
+ The scrolling week and day views and the resource columns view show the same columns. The parts
224
+ live in `time-grid-zones.tsx`, and [Time and time zones](../concepts/time.md#secondary-time-zones)
225
+ explains how each line is read.
226
+
227
+ ## Keyboard
228
+
229
+ Tab into the preview above, or click a slot, and try these keys. The
230
+ [Accessibility](../accessibility.md#keyboard) page has the full map and what a screen reader hears.
231
+
232
+ | Focus | Key | Effect |
233
+ | --------------- | ------------------ | --------------------------------------------------------------------------------- |
234
+ | An all-day cell | ↓ | First slot of the day |
235
+ | A slot | ↑ ↓ | Previous or next 15-minute slot. Up from the first slot reaches the all-day cell |
236
+ | A day or slot | ← → | Same slot on the previous or next day |
237
+ | A day or slot | Home, End | First or last day shown |
238
+ | A day or slot | Page Up, Page Down | Back or forward a whole week (or day) |
239
+ | A slot | Enter | The event covering it. Escape goes back to the slot it starts in |
240
+ | An all-day cell | Enter | Go into the day's all-day events |
241
+ | A timed event | ↑ ↓, ← → | Previous or next event in the column, or the event beside it that overlaps it |
242
+ | A day or slot | Shift+Enter | Open that date in the day view, when the week has `dayView` |
243
+ | A slot | Space | Start an hour-long event there. Arrow keys extend it, and Enter saves it |
244
+ | An all-day cell | Space | Start an all-day event there |
245
+ | An event | Space | Pick it up. Arrow keys move it by slots and days, Enter saves, and Escape cancels |
246
+ | An event | Shift+Space | Pick up its end to resize it. Shift+Space again switches to its start |
247
+
248
+ Moving a picked-up timed event above the first slot makes it all-day, and moving an all-day event
249
+ below the all-day row makes it timed. Only the focused slot is an element, so a week's 672 slots
250
+ cost nothing until you visit them.
251
+
252
+ ## Markup for interactions
253
+
254
+ The view connects the pointer layer for you. If you change its markup, keep the attributes the
255
+ pointer layer reads: day columns have `data-date` and cover the full 24 hours, all-day cells have
256
+ `data-date` and `data-all-day`, each event is a `<button>` with `data-event-id`, and events you can
257
+ edit have `data-resize="start"` and `data-resize="end"` handles.
@@ -0,0 +1,138 @@
1
+ # Year
2
+
3
+ Twelve months at a glance, with a dot for each event color on a day and a popover of its events.
4
+
5
+ Source: https://time.molten.sh/docs/views/year
6
+
7
+ > Live example of the `year` view: see it at https://time.molten.sh/docs/views/year
8
+
9
+ Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Year in the view switcher,
10
+ or press Y.
11
+
12
+ `createYearView` shows the anchor's calendar year, January to December, as twelve small month
13
+ grids. Weeks start on `weekRules.firstDay`. Each date shows once: a week that reaches into the
14
+ month before or after leaves those cells empty, so every month keeps its own shape.
15
+
16
+ ## Add it
17
+
18
+ Add the view to your app with the shadcn CLI, as described in
19
+ [UI source](../installation.md#ui-source-optional). The item brings the theme, the shared
20
+ `calendar` parts, and shadcn's `popover`:
21
+
22
+ ```bash
23
+ npx shadcn@latest add https://time.molten.sh/r/year-view.json
24
+ ```
25
+
26
+ Then register the view:
27
+
28
+ ```tsx
29
+ import { createYearView } from "@/components/calendar/year-view/year-view";
30
+
31
+ export const Calendar = createCalendar<Meeting>()({
32
+ eventAdapter,
33
+ views: [
34
+ createMonthView<Meeting>({ getEventColor: (meeting) => meeting.color }),
35
+ createYearView<Meeting>({ getEventColor: (meeting) => meeting.color }),
36
+ createDayView<Meeting>(),
37
+ ],
38
+ });
39
+ ```
40
+
41
+ The view is named `year`. Previous and Next move by one year. Its range is the whole year, so
42
+ `onVisibleRangeChange` asks for a year of events at a time: see
43
+ [loading events by range](./scrolling.md#loading-events-as-you-scroll).
44
+
45
+ ## Anatomy
46
+
47
+ `YearView` renders the parts below. To change one, edit it in the `components/calendar/year-view`
48
+ files you added.
49
+
50
+ > Diagram: see it at https://time.molten.sh/docs/views/year
51
+
52
+ ```txt title="Rendered by YearView"
53
+ YearView year-view.tsx
54
+ ├── YearMonthGrid year-month.tsx, one per month
55
+ │ ├── Month name opens the month view
56
+ │ ├── Weekday initials
57
+ │ └── Day cell data-date, the popover's trigger
58
+ │ ├── Date aria-current="date" on today
59
+ │ └── Event dots data-color, one per color
60
+ └── YearDayPopover year-day-popover.tsx, one for the whole year
61
+ ├── Date opens the day view
62
+ └── YearEvent a [data-event-id] button per event
63
+ ```
64
+
65
+ The popover is one Base UI popover with a detached trigger in every day, so the year never mounts
66
+ hundreds of popovers.
67
+
68
+ ## Options
69
+
70
+ | Name | Type | Default | Description |
71
+ | ------------------- | ---------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
72
+ | `getEventColor` | `(event: TEvent) => CalendarEventColor` | | The color of each event's dot and of its row in the popover. See [event colors](../theming.md#event-colors). |
73
+ | `getEventIcon` | `(event: TEvent) => ReactNode` | | A small icon before each event's title in the popover, such as a repeat mark on recurring events, or nothing; the dots don't show it. 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). |
74
+ | `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
75
+ | `dayView` | `string` | `"day"` | The registered view a date opens. |
76
+ | `monthView` | `string` | `"month"` | The registered view a month's name opens. |
77
+ | `closedDays` | `"exceptions" \| "all" \| "none"` | `"exceptions"` | Which closed days are shaded: the dates an exception closes, such as holidays; those and the weekly closed days, such as weekends; or none. A closed day is named "closed" either way. See [Closed days](#closed-days). |
78
+ | `renderUnavailable` | `UnavailableTimeRender` | | Replaces the shading of the closed days `closedDays` picks. See [Availability](../availability.md#customize-the-shading). |
79
+
80
+ ## What it shows
81
+
82
+ - **Months:** two to a row on a phone, up to six on a wide screen. Each keeps room for six weeks, so
83
+ months side by side line up.
84
+ - **Days:** today's date sits in a filled circle. Under each date, a dot for every event color on
85
+ that day, up to three, in the order the day's events start. All-day and multi-day events count on
86
+ every date they cover.
87
+ - **A day's events:** clicking a day opens a popover with its events, all-day first, then by start
88
+ time. Each event is a `<button data-event-id>`, so the app's own event details open from it as from
89
+ any other view. The date at the top opens the day in the view named `day`.
90
+ - **Month names** open that month in the view named `month`.
91
+ - **Closed days:** with [availability](../availability.md), see [below](#closed-days).
92
+ - **Scrolling:** where the months don't fit, the view opens with today's month, or the day you last
93
+ focused, in view. Today, Previous, Next and a picked date scroll their month into view. Only the
94
+ view scrolls, never the page around it.
95
+ - **Editing:** none. The year shows events without moving or creating them; open a day or a month
96
+ to edit.
97
+
98
+ ## Closed days
99
+
100
+ With [availability](../availability.md), a day without working hours is named "closed" for screen
101
+ readers, as in the month view. What's shaded depends on `closedDays`:
102
+
103
+ - `"exceptions"` (the default) shades the dates an exception closes, such as a public holiday or an
104
+ offsite. Weekly closed days, such as weekends, stay plain: the weekday columns already show them,
105
+ and a third of the year in gray would bury the holidays.
106
+ - `"all"` shades the weekly closed days too.
107
+ - `"none"` shades nothing.
108
+
109
+ Shaded days next to each other in a week join into one band with rounded ends, so a weekend or a
110
+ long holiday reads as one stretch, and the rows stay apart. To draw it differently, such as hatching,
111
+ pass `renderUnavailable`; its `band` carries the reason, the exception's label and whether open time
112
+ meets each end.
113
+
114
+ Set `closedDays` when you create the view, or per calendar with
115
+ `viewOptions={{ year: { closedDays: "all" } }}` on `Root`.
116
+
117
+ ## Keyboard
118
+
119
+ Tab into the preview above, or click a day, and try these keys. The
120
+ [Accessibility](../accessibility.md#keyboard) page has the full map.
121
+
122
+ | Focus | Key | Effect |
123
+ | ----- | ------------------ | ------------------------------------------------------------------------ |
124
+ | A day | ← → | Previous or next day, across months |
125
+ | A day | ↑ ↓ | Same weekday a week earlier or later, across months |
126
+ | A day | Home, End | First or last day of the week's row in its month |
127
+ | A day | Page Up, Page Down | Same day in the previous or next month |
128
+ | A day | Enter, Space | Open the day's events. Tab moves through them; Escape returns to the day |
129
+ | A day | Shift+Enter | Open the day in the day view |
130
+
131
+ Moving past December 31 or before January 1 navigates to the next or previous year.
132
+
133
+ ## Build your own
134
+
135
+ The strategy pieces are exported, for a year that looks different, such as a heat map of busy days:
136
+ `getYearRange`, `navigateYear`, `getYearTitle`, `projectYear` and `yearSpatialNavigation`.
137
+ `projectYear` returns twelve months of week rows, each day with its event fragments in display
138
+ order, or `null` outside the month. See [Custom views](./custom-views.md).