@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.
- package/README.md +24 -4
- package/dist/index.d.mts +2 -2
- package/docs/accessibility.md +304 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +117 -0
- package/docs/agents/connect.md +435 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +512 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +353 -0
- package/docs/annotations.md +196 -0
- package/docs/api/changes.md +248 -0
- package/docs/api/dnd-kit.md +267 -0
- package/docs/api/events.md +152 -0
- package/docs/api/ics.md +524 -0
- package/docs/api/primitives.md +168 -0
- package/docs/api/react.md +236 -0
- package/docs/api/recurrence.md +586 -0
- package/docs/api/solid.md +460 -0
- package/docs/api/store.md +92 -0
- package/docs/api/temporal.md +172 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +573 -0
- package/docs/comparison.md +279 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +164 -0
- package/docs/concepts/how-it-works.md +95 -0
- package/docs/concepts/recurrence.md +127 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +170 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/ics.md +486 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/recurring-events.md +583 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/index.md +118 -0
- package/docs/installation.md +194 -0
- package/docs/interactions.md +408 -0
- package/docs/llms.txt +86 -0
- package/docs/migrating-to-2.md +322 -0
- package/docs/quick-start.md +159 -0
- package/docs/stylex.md +265 -0
- package/docs/testing.md +581 -0
- package/docs/theme-builder.md +81 -0
- package/docs/theming.md +169 -0
- package/docs/undo-redo.md +339 -0
- package/docs/views/agenda.md +221 -0
- package/docs/views/custom-views.md +192 -0
- package/docs/views/month.md +109 -0
- package/docs/views/resource-columns.md +261 -0
- package/docs/views/resource-timeline.md +225 -0
- package/docs/views/scrolling.md +192 -0
- package/docs/views/week-and-day.md +257 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +41 -14
- package/skills/moltenship-time/SKILL.md +75 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +168 -0
- package/skills/moltenship-time/references/mistakes.md +98 -0
- package/skills/moltenship-time/references/solid.md +202 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Agenda
|
|
2
|
+
|
|
3
|
+
A chronological list of upcoming events, grouped by day, and a version that scrolls through months or years.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/views/agenda
|
|
6
|
+
|
|
7
|
+
> Live example of the `agenda` view: see it at https://time.molten.sh/docs/views/agenda
|
|
8
|
+
|
|
9
|
+
Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Agenda in the view switcher.
|
|
10
|
+
|
|
11
|
+
`createAgendaView` lists the events in the coming weeks, one group per day. Days without events are
|
|
12
|
+
left out. Only the days in view render, so a long range, such as `weeks: 104`, stays fast. For a
|
|
13
|
+
list that scrolls without end and loads events as you go, use the
|
|
14
|
+
[scrolling agenda](#scrolling-agenda).
|
|
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 and the shared
|
|
20
|
+
`calendar` parts:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx shadcn@latest add https://time.molten.sh/r/list-view.json
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then register the view:
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { createAgendaView } from "@/components/calendar/list-view/agenda-view";
|
|
30
|
+
|
|
31
|
+
export const Calendar = createCalendar<Meeting>()({
|
|
32
|
+
eventAdapter,
|
|
33
|
+
views: [createAgendaView<Meeting>({ weeks: 2, getEventColor: (meeting) => meeting.color })],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The view is named `agenda`. It renders with `@tanstack/react-virtual`, which the registry item
|
|
38
|
+
installs.
|
|
39
|
+
|
|
40
|
+
## Scrolling agenda
|
|
41
|
+
|
|
42
|
+
> Live example of the `scrolling-agenda` view: see it at https://time.molten.sh/docs/views/agenda
|
|
43
|
+
|
|
44
|
+
`createScrollingAgendaView` from the `scrolling-list-view` item is the agenda as a
|
|
45
|
+
[scrolling view](./scrolling.md): one list that scrolls through months or years, with the
|
|
46
|
+
anchor date on top. This preview holds a year of events either way of today, a few thousand of
|
|
47
|
+
them, and fetches them from a pretend server as you scroll. Try it in the demo with "Scroll days,
|
|
48
|
+
weeks, months and agenda" on in the settings.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx shadcn@latest add https://time.molten.sh/r/scrolling-list-view.json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { createScrollingAgendaView } from "@/components/calendar/scrolling-list-view/scrolling-agenda-view";
|
|
56
|
+
|
|
57
|
+
views: [createScrollingAgendaView<Meeting>({ dayView: "scrolling-day", getEventColor })];
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
| View | Shows | Loads | Previous and Next | Today |
|
|
61
|
+
| ------------------ | -------------------------------- | ------------------ | ----------------- | ------------ |
|
|
62
|
+
| `scrolling-agenda` | `weeks` from the anchor date (4) | A page either side | `weeks` | Today on top |
|
|
63
|
+
|
|
64
|
+
- **The anchor date is the day on top.** The range starts at the anchor date rather than its week,
|
|
65
|
+
since the list comes to rest on any day. When a scroll comes to rest, the anchor date moves to the
|
|
66
|
+
day on top, so `Calendar.Title`, `onAnchorDateChange`, and a URL that stores the date follow it.
|
|
67
|
+
On a long scroll it moves every half page on the way, so the next weeks load before they scroll
|
|
68
|
+
into view.
|
|
69
|
+
- **Today, Previous, Next, and any other anchor date jump the list** to put that date on top, or
|
|
70
|
+
the next day with events, at once, as Google Calendar's agenda does, rather than gliding there as
|
|
71
|
+
the other scrolling views do over a page or two. The list holds that date on top while its events
|
|
72
|
+
load, until you scroll. With a controlled `anchorDate`, the list stays where it was scrolled until
|
|
73
|
+
your state takes the latest date `onAnchorDateChange` sent, as in the other
|
|
74
|
+
[scrolling views](./scrolling.md#how-they-move).
|
|
75
|
+
- **Only the days in view render.** Each is measured once it renders, as its events wrap, and days
|
|
76
|
+
that load above or below the ones on screen don't move them.
|
|
77
|
+
- **The end of the list** follows the last loaded day. It's as tall as the view, so any day can
|
|
78
|
+
scroll to the top, and says "Loading events…" while `loading` is set, or that nothing more is
|
|
79
|
+
scheduled. Scrolling on past either end of the loaded days moves a page that way, once per
|
|
80
|
+
gesture, so the list crosses weeks without events. Weeks shown without events get the empty
|
|
81
|
+
state, at the end of the list or among the days after them.
|
|
82
|
+
|
|
83
|
+
### Loading events as you scroll
|
|
84
|
+
|
|
85
|
+
The scrolling agenda's load range is a page of weeks either way of the ones it shows. As with the
|
|
86
|
+
other scrolling views, `onVisibleRangeChange` on `Root` reports it after the first render and
|
|
87
|
+
whenever the anchor date moves it. Fetch what you haven't fetched yet, and set `loading` while some
|
|
88
|
+
is on its way:
|
|
89
|
+
|
|
90
|
+
```tsx title="long-agenda.tsx"
|
|
91
|
+
const timeZone = "Europe/Berlin";
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fetches meetings for the dates the agenda lists, each date once, as it scrolls, and says so
|
|
95
|
+
* while some are still on their way.
|
|
96
|
+
*/
|
|
97
|
+
export function LongAgenda({
|
|
98
|
+
loadMeetings,
|
|
99
|
+
}: {
|
|
100
|
+
readonly loadMeetings: (from: Temporal.Instant, to: Temporal.Instant) => Promise<Meeting[]>;
|
|
101
|
+
}) {
|
|
102
|
+
const [loaded, setLoaded] = useState<ReadonlyMap<string, Meeting>>(new Map());
|
|
103
|
+
const [fetching, setFetching] = useState(0);
|
|
104
|
+
const requested = useRef(new Set<string>());
|
|
105
|
+
const meetings = useMemo(() => [...loaded.values()], [loaded]);
|
|
106
|
+
|
|
107
|
+
const load = useCallback(
|
|
108
|
+
({ loadRange }: CalendarVisibleRange) => {
|
|
109
|
+
const missing = [...iteratePlainDates(loadRange)].filter(
|
|
110
|
+
(date) => !requested.current.has(date.toString()),
|
|
111
|
+
);
|
|
112
|
+
if (missing.length === 0) return;
|
|
113
|
+
for (const date of missing) requested.current.add(date.toString());
|
|
114
|
+
const from = missing[0]!.toZonedDateTime(timeZone).toInstant();
|
|
115
|
+
const to = missing.at(-1)!.add({ days: 1 }).toZonedDateTime(timeZone).toInstant();
|
|
116
|
+
setFetching((count) => count + 1);
|
|
117
|
+
void loadMeetings(from, to)
|
|
118
|
+
.then((arrived) =>
|
|
119
|
+
setLoaded((current) => new Map([...current, ...arrived.map((m) => [m.id, m] as const)])),
|
|
120
|
+
)
|
|
121
|
+
.finally(() => setFetching((count) => count - 1));
|
|
122
|
+
},
|
|
123
|
+
[loadMeetings],
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Calendar.Root
|
|
128
|
+
events={meetings}
|
|
129
|
+
defaultAnchorDate={Temporal.Now.plainDateISO(timeZone)}
|
|
130
|
+
onVisibleRangeChange={load}
|
|
131
|
+
timeZone={timeZone}
|
|
132
|
+
locale="en-US"
|
|
133
|
+
viewOptions={{ "scrolling-agenda": { loading: fetching > 0 } }}
|
|
134
|
+
weekRules={weekRules}
|
|
135
|
+
>
|
|
136
|
+
<Calendar.ActiveView />
|
|
137
|
+
</Calendar.Root>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
While `loading` is set, the end of the list says "Loading events…", and a view without events
|
|
143
|
+
shows a loading state in place of the empty one. Time never fetches or keeps events itself.
|
|
144
|
+
|
|
145
|
+
## Anatomy
|
|
146
|
+
|
|
147
|
+
`AgendaView` from `registry/list-view` renders a list with one group per day. The view builds these
|
|
148
|
+
parts itself, so they're not parts you compose: to change one, edit its file. The tree shows where
|
|
149
|
+
each part lives.
|
|
150
|
+
|
|
151
|
+
> Diagram: see it at https://time.molten.sh/docs/views/agenda
|
|
152
|
+
|
|
153
|
+
```txt title="Rendered by AgendaView"
|
|
154
|
+
AgendaView agenda-view.tsx
|
|
155
|
+
├── AgendaList agenda-list.tsx, scrolls the days in view
|
|
156
|
+
│ ├── Day group agenda-day.tsx, data-date, one per day
|
|
157
|
+
│ │ ├── Day group header weekday and date, sticky
|
|
158
|
+
│ │ └── AgendaItem agenda-item.tsx, one per event
|
|
159
|
+
│ └── End of list agenda-states.tsx, AgendaEnd: scrolling agenda only
|
|
160
|
+
└── Empty state agenda-states.tsx, EmptyAgenda: in place of the list
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`AgendaItem` shows the time range or an "All day" badge, the title, and "Day 2 of 3", which comes
|
|
164
|
+
from `dayIndex` and `dayCount`. `use-agenda-virtualizer.ts` decides which days render. The
|
|
165
|
+
scrolling agenda's `ScrollingAgendaView` renders the same parts, and `use-agenda-scroll.ts` in
|
|
166
|
+
`registry/scrolling-list-view` keeps its scroll position and the anchor date together.
|
|
167
|
+
|
|
168
|
+
## Options
|
|
169
|
+
|
|
170
|
+
| Name | Type | Default | Description |
|
|
171
|
+
| --------------- | ---------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
172
|
+
| `weeks` | `number` | `4` | How many whole weeks to show, from the week of the anchor date, or from the anchor date itself in the scrolling agenda. Previous and Next move by the same number of weeks. |
|
|
173
|
+
| `getEventColor` | `(event: TEvent) => CalendarEventColor` | | The color for each event. See [event colors](../theming.md#event-colors). |
|
|
174
|
+
| `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). |
|
|
175
|
+
| `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
|
|
176
|
+
| `loading` | `boolean` | `false` | Events for the view's dates are still being fetched: the view says they're loading instead of that nothing is scheduled. |
|
|
177
|
+
| `dayView` | `string` | `"day"` | Scrolling agenda only: the registered view a date opens. |
|
|
178
|
+
|
|
179
|
+
## What it shows
|
|
180
|
+
|
|
181
|
+
- **Days:** each day with events gets a date column that stays in view while you scroll its
|
|
182
|
+
events. Today is highlighted.
|
|
183
|
+
- **Times** are formatted as a range with `Intl`, as in "10:00 – 11:30 AM". Events that started the
|
|
184
|
+
day before read "Until 2:00 AM"; events that run into the next day read "From 10:00 PM".
|
|
185
|
+
- **All-day events** show an "All day" badge, and events longer than a day show "Day 2 of 3".
|
|
186
|
+
- **Empty range:** a short message when the weeks shown have no events, or a loading one while
|
|
187
|
+
`loading` is set.
|
|
188
|
+
- **Clicking a date** opens that day in the view named `day`. Register a
|
|
189
|
+
[day view](./week-and-day.md) so the click has somewhere to go.
|
|
190
|
+
- **Changes being saved:** events with a [pending change](../interactions.md#pending-changes) get
|
|
191
|
+
`aria-busy` and render at 60% opacity.
|
|
192
|
+
|
|
193
|
+
Each day has `data-date`, and each event is a `<button>` with `data-event-id`.
|
|
194
|
+
|
|
195
|
+
## Keyboard
|
|
196
|
+
|
|
197
|
+
Tab into the preview above and try these keys. The [Accessibility](../accessibility.md#keyboard)
|
|
198
|
+
page has the full map.
|
|
199
|
+
|
|
200
|
+
| Focus | Key | Effect |
|
|
201
|
+
| ---------------------- | ---------------------------- | --------------------------------------- |
|
|
202
|
+
| An event | ↑ ↓ | Previous or next event |
|
|
203
|
+
| An event | Page Up, Page Down | First event of the previous or next day |
|
|
204
|
+
| An event | Home, End | First or last event |
|
|
205
|
+
| An event | Enter | Open it, as a click does |
|
|
206
|
+
| An event | Shift+Enter | Open its date in the day view |
|
|
207
|
+
| A range without events | ↑ or Page Up, ↓ or Page Down | The previous or next range |
|
|
208
|
+
|
|
209
|
+
Moving past the first or last event shows the previous or next weeks. In the scrolling agenda the
|
|
210
|
+
keys move through the weeks it shows, and moving past them pages on as focus moves to the next
|
|
211
|
+
event, scrolling it into view. The list scrolls to keep the focused event in view, and the focused
|
|
212
|
+
day stays rendered while focus is in the list. Focus belongs to an event on a date, not to an
|
|
213
|
+
element: if its day scrolls out of the loaded weeks, focus goes with it, and it returns once the day
|
|
214
|
+
is in view again. The agenda doesn't move or create events from the keyboard, since it has no days or
|
|
215
|
+
times to move them to.
|
|
216
|
+
|
|
217
|
+
## Screen readers
|
|
218
|
+
|
|
219
|
+
The list is an `<ol>` named by its weeks. Only the days in view render, so each day's `<li>`
|
|
220
|
+
carries `aria-posinset` and `aria-setsize`, counting every day listed: "list item, 5 of 41". The
|
|
221
|
+
list is `aria-busy` while `loading` is set.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Custom views
|
|
2
|
+
|
|
3
|
+
Define a view with a pure strategy and a Renderer component.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/views/custom-views
|
|
6
|
+
|
|
7
|
+
A view has two halves:
|
|
8
|
+
|
|
9
|
+
- a **strategy**: four plain functions that pick the visible dates, move them, title them, and turn
|
|
10
|
+
the events into whatever the view needs to draw (its **projection**), plus two optional ones;
|
|
11
|
+
- a **Renderer**: a React component that receives that projection.
|
|
12
|
+
|
|
13
|
+
`Root` runs the strategy and passes the result to the Renderer, so the Renderer only draws.
|
|
14
|
+
|
|
15
|
+
## Define a view
|
|
16
|
+
|
|
17
|
+
This view shows a few days at a time and counts the meetings on each one. Everything it imports
|
|
18
|
+
comes from `@moltenship/calendar`.
|
|
19
|
+
|
|
20
|
+
```tsx title="days-view.tsx"
|
|
21
|
+
import {
|
|
22
|
+
createCalendar,
|
|
23
|
+
defineCalendarView,
|
|
24
|
+
iteratePlainDates,
|
|
25
|
+
plainDateInterval,
|
|
26
|
+
zonedDayRange,
|
|
27
|
+
} from "@moltenship/calendar";
|
|
28
|
+
|
|
29
|
+
import { eventAdapter, meetings, weekRules, type Meeting } from "./quick-start";
|
|
30
|
+
|
|
31
|
+
export const daysView = defineCalendarView({
|
|
32
|
+
name: "days",
|
|
33
|
+
defaultOptions: { days: 3 },
|
|
34
|
+
strategy: {
|
|
35
|
+
getRange: (anchor, _environment, { days }) => plainDateInterval(anchor, anchor.add({ days })),
|
|
36
|
+
navigate: (anchor, delta, { days }) => anchor.add({ days: delta * days }),
|
|
37
|
+
getTitle: (range, { locale }) =>
|
|
38
|
+
new Intl.DateTimeFormat(locale, { day: "numeric", month: "short" }).formatRange(
|
|
39
|
+
range.start,
|
|
40
|
+
range.end.subtract({ days: 1 }),
|
|
41
|
+
),
|
|
42
|
+
project: ({ snapshot, range, environment }) =>
|
|
43
|
+
Array.from(iteratePlainDates(range), (date) => {
|
|
44
|
+
const day = zonedDayRange(date, environment.timeZone);
|
|
45
|
+
return { date, events: day.interval ? snapshot.queryTimed(day.interval) : [] };
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
Renderer: ({ projection, actions }) => (
|
|
49
|
+
<ol>
|
|
50
|
+
{projection.map(({ date, events }) => (
|
|
51
|
+
<li key={date.toString()}>
|
|
52
|
+
<button type="button" onClick={() => actions.setAnchorDate(date)}>
|
|
53
|
+
{date.toString()}
|
|
54
|
+
</button>{" "}
|
|
55
|
+
{events.length} meetings
|
|
56
|
+
</li>
|
|
57
|
+
))}
|
|
58
|
+
</ol>
|
|
59
|
+
),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Write `strategy` before `Renderer`. TypeScript reads the object in order, so the Renderer's
|
|
64
|
+
`projection` gets its type from `project`.
|
|
65
|
+
|
|
66
|
+
## Register it and set options
|
|
67
|
+
|
|
68
|
+
Pass views to `createCalendar`. View names must be unique; `createCalendar` throws on a duplicate.
|
|
69
|
+
`viewOptions` on `Root` overrides a view's `defaultOptions`, keyed by view name:
|
|
70
|
+
|
|
71
|
+
```tsx title="days-view.tsx"
|
|
72
|
+
export const Calendar = createCalendar<Meeting>()({
|
|
73
|
+
eventAdapter,
|
|
74
|
+
views: [daysView],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export function WorkWeek() {
|
|
78
|
+
return (
|
|
79
|
+
<Calendar.Root
|
|
80
|
+
events={meetings}
|
|
81
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-05")}
|
|
82
|
+
defaultTimeZone="Europe/Berlin"
|
|
83
|
+
locale="en-US"
|
|
84
|
+
weekRules={weekRules}
|
|
85
|
+
viewOptions={{ days: { days: 5 } }}
|
|
86
|
+
>
|
|
87
|
+
<Calendar.Title />
|
|
88
|
+
<Calendar.ActiveView />
|
|
89
|
+
</Calendar.Root>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The title reads "Oct 5 – 9", and the list has five days.
|
|
95
|
+
|
|
96
|
+
## Strategy
|
|
97
|
+
|
|
98
|
+
| Name | Type | Description |
|
|
99
|
+
| ---------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `getRange` | `(anchor, environment, options) => PlainDateInterval` | Required. The visible dates, end excluded. Build it with `plainDateInterval`. |
|
|
101
|
+
| `navigate` | `(anchor, delta, options) => Temporal.PlainDate` | Required. The anchor date after moving `delta` steps. Previous and Next pass -1 and 1. |
|
|
102
|
+
| `getLoadRange` | `(anchor, environment, options) => PlainDateInterval` | The dates to project and have events for, around the visible ones, as a [scrolling view](./scrolling.md) keeps a page on each side. It must contain `getRange`'s dates. Without it, the view projects what it shows. |
|
|
103
|
+
| `getTitle` | `(range, environment, options) => string` | Required. The text for `<Calendar.Title />`. |
|
|
104
|
+
| `project` | `(input) => TProjection` | Required. Turns the events into what the Renderer draws. See the input below. |
|
|
105
|
+
| `getSpatialNavigation` | `(input) => CalendarSpatialNavigation \| null` | Where the arrows, Home, End, Page Up and Page Down move focus, and where Enter and Escape go into and out of a cell's events. A view without it has no keyboard navigation. See [in your own views](../accessibility.md#in-your-own-views). |
|
|
106
|
+
|
|
107
|
+
`anchor` is the date in the `anchorDate` state. `environment` holds `locale`, `timeZone`,
|
|
108
|
+
`secondaryTimeZones`, `weekRules`, `direction`, and `disambiguation`. The functions should be pure:
|
|
109
|
+
`Root` calls them during render and reuses the projection until one of its inputs changes.
|
|
110
|
+
|
|
111
|
+
`project` receives:
|
|
112
|
+
|
|
113
|
+
| Field | Contents |
|
|
114
|
+
| --------------------- | ----------------------------------------------------------------------------------- |
|
|
115
|
+
| `snapshot` | The validated, indexed events. Query it with `queryTimed` and friends. |
|
|
116
|
+
| `range` | The visible dates, from `getRange` |
|
|
117
|
+
| `instantRange` | The same dates as instants in the calendar's time zone, ready for `queryTimed` |
|
|
118
|
+
| `loadRange` | The dates to project: `getLoadRange`'s, or `range` without it. Always set by `Root` |
|
|
119
|
+
| `environment` | Locale, time zone, secondary time zones, week rules, direction, disambiguation |
|
|
120
|
+
| `resources` | The `resources` prop as a tree by `parentId` (`roots`, `byId`) |
|
|
121
|
+
| `expandedResourceIds` | The groups whose children show; pass it to `visibleResources` |
|
|
122
|
+
| `options` | The view's options after `viewOptions` overrides |
|
|
123
|
+
| `today` | Today's date in the calendar's time zone, or `null` before a clock is known |
|
|
124
|
+
|
|
125
|
+
`today` is fixed when `Root` has `now`, so server and browser agree. Without `now` it's `null`
|
|
126
|
+
during server rendering and fills in after hydration.
|
|
127
|
+
|
|
128
|
+
### Typed events
|
|
129
|
+
|
|
130
|
+
Inside `project`, events are typed `unknown` unless you say otherwise, because a view can be used by
|
|
131
|
+
calendars with different records. To work with your own fields, annotate the input:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import type { CalendarViewProjectionInput } from "@moltenship/calendar";
|
|
135
|
+
|
|
136
|
+
project: ({ snapshot, instantRange }: CalendarViewProjectionInput<DaysOptions, Meeting>) =>
|
|
137
|
+
snapshot.queryTimed(instantRange).map(({ event }) => event.title),
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Renderer
|
|
141
|
+
|
|
142
|
+
The Renderer is a regular component, so it can use hooks. It receives:
|
|
143
|
+
|
|
144
|
+
| Prop | Contents |
|
|
145
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
146
|
+
| `projection` | What `project` returned |
|
|
147
|
+
| `range` | The visible dates |
|
|
148
|
+
| `loadRange` | The dates `project` covered: `range`, or the strategy's wider `getLoadRange` |
|
|
149
|
+
| `options` | The view's options |
|
|
150
|
+
| `environment` | Locale, time zone, secondary time zones, week rules, direction, disambiguation |
|
|
151
|
+
| `events` | The snapshot `project` received, with [pending changes](../interactions.md#pending-changes) applied |
|
|
152
|
+
| `isReadOnly` | `true` when `Root` has no `onEventChange`: start no drags and draw no resize handles. Keyboard grabs stay off by themselves |
|
|
153
|
+
| `actions` | `setAnchorDate`, `setView`, `setSelection`, `setFocus`, `navigateNext`, `navigatePrevious`, `navigateToday`, `proposeEventChange`, `checkEventChange` |
|
|
154
|
+
|
|
155
|
+
`actions` never changes identity. `setView` takes any registered view name; an unknown name shows up
|
|
156
|
+
as an `unregistered-active-view` diagnostic. `proposeEventChange` and `events` are what a view needs
|
|
157
|
+
to let people [drag and resize events](../interactions.md#drag-resize-and-create).
|
|
158
|
+
|
|
159
|
+
To declare a Renderer as its own component, type its props with `CalendarViewRendererProps`:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import type { CalendarViewRendererProps } from "@moltenship/calendar";
|
|
163
|
+
|
|
164
|
+
function DaysRenderer({ projection }: CalendarViewRendererProps<DaysProjection, DaysOptions>) {
|
|
165
|
+
// …
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Reading the view from other components
|
|
170
|
+
|
|
171
|
+
Components inside `Root` can read the active view without being part of it:
|
|
172
|
+
|
|
173
|
+
```tsx title="days-view.tsx"
|
|
174
|
+
export function VisibleRange() {
|
|
175
|
+
const range = Calendar.useVisibleRange();
|
|
176
|
+
if (range === null) return null;
|
|
177
|
+
return (
|
|
178
|
+
<p>
|
|
179
|
+
{range.start.toString()} to {range.end.subtract({ days: 1 }).toString()}
|
|
180
|
+
</p>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
- `Calendar.useVisibleRange()` returns the visible dates, or `null` when the active view isn't
|
|
186
|
+
registered.
|
|
187
|
+
- `Calendar.useViewProjection()` returns the active view's `view` name, `definition`,
|
|
188
|
+
`projection`, `range`, `instantRange`, `loadRange`, `loadInstantRange`, `options`,
|
|
189
|
+
`environment`, and `events`, or `null`. Check `view` to
|
|
190
|
+
narrow `projection` to that view's type.
|
|
191
|
+
- `useNow({ intervalMs })` returns the current instant for a now-line and re-renders on each tick.
|
|
192
|
+
It's `null` during server rendering and hydration unless `Root` has `now`.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Month
|
|
2
|
+
|
|
3
|
+
A month grid with multi-day bars and a "+N more" popover.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/views/month
|
|
6
|
+
|
|
7
|
+
> Live example of the `month` view: see it at https://time.molten.sh/docs/views/month
|
|
8
|
+
|
|
9
|
+
Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Month in the view switcher.
|
|
10
|
+
|
|
11
|
+
`createMonthView` shows every week that touches the month, starting on `weekRules.firstDay`. Most
|
|
12
|
+
months need five rows; some need four or six.
|
|
13
|
+
|
|
14
|
+
## Add it
|
|
15
|
+
|
|
16
|
+
Add the view to your app with the shadcn CLI, as described in
|
|
17
|
+
[UI source](../installation.md#ui-source-optional). The item brings the theme, the shared
|
|
18
|
+
`calendar` parts, and shadcn's `popover`:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx shadcn@latest add https://time.molten.sh/r/month-view.json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then register the view:
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { createMonthView } from "@/components/calendar/month-view/month-view";
|
|
28
|
+
|
|
29
|
+
export const Calendar = createCalendar<Meeting>()({
|
|
30
|
+
eventAdapter,
|
|
31
|
+
views: [createMonthView<Meeting>({ getEventColor: (meeting) => meeting.color })],
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The view is named `month`. Previous and Next move by one month.
|
|
36
|
+
|
|
37
|
+
## Anatomy
|
|
38
|
+
|
|
39
|
+
`MonthView` renders the parts below. The view builds them itself from its projection, so they're not
|
|
40
|
+
parts you compose: to change one, edit it in the `components/calendar/month-view` files you added.
|
|
41
|
+
The tree shows where each part lives.
|
|
42
|
+
|
|
43
|
+
> Diagram: see it at https://time.molten.sh/docs/views/month
|
|
44
|
+
|
|
45
|
+
```txt title="Rendered by MonthView"
|
|
46
|
+
MonthView month-view.tsx
|
|
47
|
+
├── Weekday header
|
|
48
|
+
└── MonthWeekRow month-week.tsx, one per week
|
|
49
|
+
├── Day cell data-date
|
|
50
|
+
│ └── DateButton aria-current="date" on today
|
|
51
|
+
├── MonthEvent month-event.tsx
|
|
52
|
+
└── MoreEvents "+N more" and its popover
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A bar is a `MonthEvent` with `bar` set. `startsBefore` and `endsAfter` mark the ends that continue
|
|
56
|
+
into another week, and days with `inMonth: false` are muted.
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
| Name | Type | Description |
|
|
61
|
+
| ------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `getEventColor` | `(event: TEvent) => CalendarEventColor` | The color for each event. See [event colors](../theming.md#event-colors). |
|
|
63
|
+
| `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). |
|
|
64
|
+
| `describeEvent` | `(event: TEvent) => string \| undefined` | Extra words for each event's accessible name, such as its calendar. |
|
|
65
|
+
| `renderUnavailable` | `UnavailableTimeRender` | Replaces the shading of closed days: an element, or a function of its props. See [customize the shading](../availability.md#customize-the-shading). |
|
|
66
|
+
|
|
67
|
+
## What it shows
|
|
68
|
+
|
|
69
|
+
- **Days:** weekday names across the top. Days outside the month are muted, today's date sits in a
|
|
70
|
+
filled circle, and the first of each month reads "Oct 1".
|
|
71
|
+
- **Multi-day and all-day events** are bars across the days they cover. A bar that continues into
|
|
72
|
+
the previous or next week ends with a chevron. Timed bars start with their start time.
|
|
73
|
+
- **Single-day timed events** show a colored dot, the start time, and the title. On narrow screens
|
|
74
|
+
they become small tinted blocks.
|
|
75
|
+
- **"+N more":** rows grow to fill the available height, at least 80px each, and show as many
|
|
76
|
+
events as fit. The rest collapse into "+N more", which opens a popover with the day's events.
|
|
77
|
+
- **Clicking a date number** opens that day in the view named `day`. Register a
|
|
78
|
+
[day view](./week-and-day.md) so the click has somewhere to go.
|
|
79
|
+
- **Editing:** with `onEventChange` on `Root`, drag an event to another day (timed events keep their
|
|
80
|
+
time), and drag across days to create an all-day event. See
|
|
81
|
+
[Interactions](../interactions.md#drag-resize-and-create).
|
|
82
|
+
- **Changes being saved:** events with a [pending change](../interactions.md#pending-changes) get
|
|
83
|
+
`aria-busy` and render at 60% opacity.
|
|
84
|
+
|
|
85
|
+
## Keyboard
|
|
86
|
+
|
|
87
|
+
Tab into the preview above, or click a day, and try these keys. The
|
|
88
|
+
[Accessibility](../accessibility.md#keyboard) page has the full map and what a screen reader hears.
|
|
89
|
+
|
|
90
|
+
| Focus | Key | Effect |
|
|
91
|
+
| -------- | ------------------ | ----------------------------------------------------------------------------- |
|
|
92
|
+
| A day | ← → | Previous or next day |
|
|
93
|
+
| A day | ↑ ↓ | Same weekday a week earlier or later |
|
|
94
|
+
| A day | Home, End | First or last day of the week |
|
|
95
|
+
| A day | Page Up, Page Down | Same day in the previous or next month |
|
|
96
|
+
| A day | Enter | Go into the day's events. ↑ ↓ walk them, and Escape goes back to the day |
|
|
97
|
+
| A day | Shift+Enter | Open the day in the day view |
|
|
98
|
+
| A day | Space | Start an all-day event there. Arrow keys extend it, and Enter saves it |
|
|
99
|
+
| An event | Space | Pick it up. Arrow keys move it by days, Enter saves, and Escape cancels |
|
|
100
|
+
| An event | Shift+Space | Pick up its end to resize it by days. Shift+Space again switches to its start |
|
|
101
|
+
|
|
102
|
+
Events behind "+N more" are reachable too: while focus is on one, its week shows every event.
|
|
103
|
+
|
|
104
|
+
## Markup for interactions
|
|
105
|
+
|
|
106
|
+
The view connects the pointer layer for you. If you change its markup, keep the attributes it reads:
|
|
107
|
+
each day cell holds an element with `data-date` underneath its events, and each event is a
|
|
108
|
+
`<button>` with `data-event-id`. The events sit beside that element, not inside it, so a drag over
|
|
109
|
+
a bar still finds the day under the pointer.
|