@moltenship/calendar 1.0.0-rc.2 → 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,573 @@
|
|
|
1
|
+
# Availability
|
|
2
|
+
|
|
3
|
+
Working hours, closed days and holidays, people and rooms in their own time zones, shading you can restyle, a busy or free status, and policies that keep bookings inside working hours and rooms from being double-booked.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/availability
|
|
6
|
+
|
|
7
|
+
> Live example of the `week` view: see it at https://time.molten.sh/docs/availability
|
|
8
|
+
|
|
9
|
+
Business hours are open, and everything else is shaded: the evenings, the weekend and Friday's
|
|
10
|
+
holiday. Availability is when the calendar, or a person or a room, can be booked. Views shade the
|
|
11
|
+
time outside it, the month mutes closed days, and a policy decides what happens to a change that
|
|
12
|
+
lands outside it: the change can be blocked, or saved with a warning. Drag an event into the evening above and the
|
|
13
|
+
screen reader strip says "outside working hours". Try it with people in other time zones in the
|
|
14
|
+
[live demo](https://moltenship-time-demo.vercel.app), where the Working hours setting switches
|
|
15
|
+
between hidden, shown, warn and block.
|
|
16
|
+
|
|
17
|
+
## Add working hours
|
|
18
|
+
|
|
19
|
+
Pass the calendar's hours to `Root` as `availability`, and add `availabilityPolicy` to its policies:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { availabilityPolicy, type CalendarAvailability } from "@moltenship/calendar";
|
|
23
|
+
|
|
24
|
+
const time = Temporal.PlainTime.from;
|
|
25
|
+
|
|
26
|
+
const officeHours: CalendarAvailability = {
|
|
27
|
+
weekly: [{ days: [1, 2, 3, 4, 5], start: time("09:00"), end: time("17:00") }],
|
|
28
|
+
exceptions: [
|
|
29
|
+
{ date: Temporal.PlainDate.from("2026-12-25"), label: "Christmas" },
|
|
30
|
+
{
|
|
31
|
+
date: Temporal.PlainDate.from("2026-12-24"),
|
|
32
|
+
hours: [{ start: time("09:00"), end: time("12:00") }],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const policies = [availabilityPolicy<Meeting, string, string>({ mode: "warn" })];
|
|
38
|
+
|
|
39
|
+
<Calendar.Root availability={officeHours} policies={policies} {...props} />;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Without `availabilityPolicy`, views still shade the hours, but nothing stops a change outside
|
|
43
|
+
them.
|
|
44
|
+
|
|
45
|
+
## Hours and exceptions
|
|
46
|
+
|
|
47
|
+
- **Weekly hours.** Each rule opens `start` to `end` on its `days`, ISO days of the week from `1`
|
|
48
|
+
(Monday) to `7` (Sunday). A day can have several rules, such as a lunch break between two. An
|
|
49
|
+
`end` at or before `start` runs past midnight, so `22:00` to `06:00` is a night and `00:00` to
|
|
50
|
+
`00:00` a whole day. Leave `weekly` out to open every day all day.
|
|
51
|
+
- **Exceptions.** An exception replaces one date's hours. Without `hours` it closes the date; its
|
|
52
|
+
`label`, such as "Christmas", names the closed day in the month and year views.
|
|
53
|
+
- **Time zones.** The hours are on the display time zone's clock unless `availability.timeZone`
|
|
54
|
+
says otherwise, such as the office's.
|
|
55
|
+
- **Daylight saving time.** Hours are half-open, `[start, end)`, and read on the wall clock. On a
|
|
56
|
+
spring-forward day, hours that start in the skipped hour open when the clock jumps. On a
|
|
57
|
+
fall-back day, hours that end in the repeated hour close after the repeat, so they cover both.
|
|
58
|
+
|
|
59
|
+
Invalid rules, exceptions and time zones are left out and reported through `onDiagnosticsChange`
|
|
60
|
+
as `invalid-availability`. The calendar never throws over them.
|
|
61
|
+
|
|
62
|
+
## People and rooms
|
|
63
|
+
|
|
64
|
+
> Live example of the `resources` view: see it at https://time.molten.sh/docs/availability
|
|
65
|
+
|
|
66
|
+
Resources follow the calendar's hours unless they have their own:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import type { AvailabilityRule } from "@moltenship/calendar";
|
|
70
|
+
|
|
71
|
+
const weekdays = (start: string, end: string): AvailabilityRule => ({
|
|
72
|
+
days: [1, 2, 3, 4, 5],
|
|
73
|
+
start: Temporal.PlainTime.from(start),
|
|
74
|
+
end: Temporal.PlainTime.from(end),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const resources = [
|
|
78
|
+
{
|
|
79
|
+
id: "orchid",
|
|
80
|
+
title: "Orchid",
|
|
81
|
+
data: room,
|
|
82
|
+
availability: { weekly: [weekdays("08:00", "20:00")] },
|
|
83
|
+
},
|
|
84
|
+
{ id: "alex", title: "Alex", data: person, timeZone: "America/Los_Angeles" },
|
|
85
|
+
{ id: "lee", title: "Lee", data: person, timeZone: "Asia/Kolkata" },
|
|
86
|
+
];
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **Own hours.** A resource's `weekly` replaces the calendar's. Its `exceptions` add to the
|
|
90
|
+
calendar's, so a company holiday closes every room, and the resource's own win on the same date.
|
|
91
|
+
- **Own time zone.** A resource with a `timeZone` keeps its hours on that clock: Alex's 9 to 5 in
|
|
92
|
+
Los Angeles shows as the evening in Berlin.
|
|
93
|
+
- **One time axis.** Resource columns and the timeline keep a single axis in the display time
|
|
94
|
+
zone. Only the shading follows each resource's clock, and its header shows its local time and
|
|
95
|
+
UTC offset, such as "7:18 AM GMT-7", while that clock differs from the display time zone's.
|
|
96
|
+
- **The same instant.** Moving an event to a resource in another time zone keeps its instant: a
|
|
97
|
+
9:00 call in New York stays 9:00 in New York, which is 14:00 for London.
|
|
98
|
+
|
|
99
|
+
## Customize the shading
|
|
100
|
+
|
|
101
|
+
Each stretch of closed time is a `div` hidden from screen readers. It carries why it is closed and
|
|
102
|
+
where it meets open time, so CSS can restyle it:
|
|
103
|
+
|
|
104
|
+
| Attribute or variable | Value |
|
|
105
|
+
| --------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
106
|
+
| `data-slot` | `time-grid-unavailable`, `resource-timeline-unavailable`, `month-closed` or `year-closed` |
|
|
107
|
+
| `data-reason` | `outside-hours`, `closed-day` (no weekly hours that day) or `exception` (a closed date) |
|
|
108
|
+
| `data-label` | The exception's `label`, such as "Company holiday" |
|
|
109
|
+
| `data-opens-before`, `data-opens-after` | Present where open time meets the band's start or end in the view |
|
|
110
|
+
| `--band-start`, `--band-end` | Where the band starts and ends along its column or row, as percentages |
|
|
111
|
+
|
|
112
|
+
> Live example: see it at https://time.molten.sh/docs/availability
|
|
113
|
+
|
|
114
|
+
```css title="globals.css"
|
|
115
|
+
/* Gradient: closed time fades out over the last hour and a half before working hours. */
|
|
116
|
+
[data-slot="time-grid-unavailable"] {
|
|
117
|
+
--calendar-unavailable: color-mix(in oklch, var(--muted-foreground) 16%, transparent);
|
|
118
|
+
/* Never more than half the band, so a short closure between open hours still shows. */
|
|
119
|
+
--fade: min(calc(var(--calendar-hour-height) * 1.5), 50%);
|
|
120
|
+
}
|
|
121
|
+
[data-slot="time-grid-unavailable"][data-opens-after] {
|
|
122
|
+
mask-image: linear-gradient(to bottom, black calc(100% - var(--fade)), transparent);
|
|
123
|
+
}
|
|
124
|
+
[data-slot="time-grid-unavailable"][data-opens-before] {
|
|
125
|
+
mask-image: linear-gradient(to top, black calc(100% - var(--fade)), transparent);
|
|
126
|
+
}
|
|
127
|
+
[data-slot="time-grid-unavailable"][data-opens-before][data-opens-after] {
|
|
128
|
+
mask-image: linear-gradient(
|
|
129
|
+
transparent,
|
|
130
|
+
black var(--fade),
|
|
131
|
+
black calc(100% - var(--fade)),
|
|
132
|
+
transparent
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* Hatching, with holidays tinted. */
|
|
137
|
+
[data-slot="time-grid-unavailable"] {
|
|
138
|
+
background: repeating-linear-gradient(
|
|
139
|
+
-45deg,
|
|
140
|
+
transparent 0 6px,
|
|
141
|
+
color-mix(in oklch, var(--muted-foreground) 25%, transparent) 6px 7px
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
[data-slot="time-grid-unavailable"][data-reason="exception"] {
|
|
145
|
+
background-color: color-mix(in oklch, var(--brand) 8%, transparent);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* A brand tint, through the token every view reads. */
|
|
149
|
+
:root {
|
|
150
|
+
--calendar-unavailable: color-mix(in oklch, var(--brand) 12%, transparent);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The default tint is `--calendar-unavailable` for closed time and `--calendar-closed` for closed
|
|
155
|
+
days in the month. In the dark theme closed time is lighter than open time, since a near-black
|
|
156
|
+
surface has little room to get darker. Recipes built on `--muted-foreground` or your own tokens
|
|
157
|
+
follow the theme the same way.
|
|
158
|
+
|
|
159
|
+
To draw something else, pass `renderUnavailable` to a view. It works like Base UI's `render`:
|
|
160
|
+
give it an element, or a function of the band's props and its state. The state holds the `band`
|
|
161
|
+
(its `reason`, `label` and edges), the column's `date` and the `resource` whose hours it shows,
|
|
162
|
+
so rooms can look different from people. Keep the props on your element: they place it and keep it
|
|
163
|
+
hidden from screen readers.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import type { UnavailableTimeRender } from "@/components/calendar/unavailable-time";
|
|
167
|
+
|
|
168
|
+
const tintRooms: UnavailableTimeRender = (props, { resource }) =>
|
|
169
|
+
// Views hand over resources as the root got them; read your own fields from `data`.
|
|
170
|
+
(resource?.data as Room | Person | undefined)?.kind === "room" ? (
|
|
171
|
+
<div
|
|
172
|
+
{...props}
|
|
173
|
+
style={{
|
|
174
|
+
...props.style,
|
|
175
|
+
"--calendar-unavailable": "color-mix(in oklch, var(--color-sky-500) 14%, transparent)",
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
) : (
|
|
179
|
+
<div {...props} />
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const views = [
|
|
183
|
+
createWeekView<Meeting>({ renderUnavailable: tintRooms }),
|
|
184
|
+
createResourceColumnsView<Meeting, Room | Person>({ renderUnavailable: tintRooms }),
|
|
185
|
+
];
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Every view that shades closed time takes `renderUnavailable`: week, day, month, year, the scrolling
|
|
189
|
+
week, day and month views, resource columns and the timeline. The agenda views don't shade closed
|
|
190
|
+
time.
|
|
191
|
+
|
|
192
|
+
## Busy or available
|
|
193
|
+
|
|
194
|
+
Working hours and events answer two different questions. **Unavailable** means outside working
|
|
195
|
+
hours. **Busy** means an event occupies the time. A person can be busy outside their hours, at a
|
|
196
|
+
late call, or free during them. The status API keeps the two apart:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { availabilityAt, busyAt, resourceStatusAt } from "@moltenship/calendar";
|
|
200
|
+
|
|
201
|
+
availabilityAt(availability, now, "maya");
|
|
202
|
+
// { available: true, closesAt: Temporal.Instant }
|
|
203
|
+
// { available: false, reason: "outside-hours" | "closed-day" | "exception", label?, opensAt }
|
|
204
|
+
|
|
205
|
+
// `events` is the root's event snapshot, as views get it in their props.
|
|
206
|
+
busyAt(events, now, { resourceId: "maya", timeZone: "Europe/Berlin" });
|
|
207
|
+
// { busy: true, events: [...], freeAt: Temporal.Instant }
|
|
208
|
+
// { busy: false, nextEventAt: Temporal.Instant | null }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
- **Time zones.** Hours are read on the resource's own clock, as the shading is, and are safe
|
|
212
|
+
across daylight saving changes. All-day and floating events count on the wall clock you pass,
|
|
213
|
+
usually the display time zone, as the views show them.
|
|
214
|
+
- **Which events are busy.** Timed and floating events are; all-day ones, such as a holiday
|
|
215
|
+
banner, aren't, as in Google Calendar. The event adapter's `isBusy` overrides that; see
|
|
216
|
+
[Customize](#customize).
|
|
217
|
+
- **Overlaps.** `events` lists everything in progress. `freeAt` is when the last of a run of
|
|
218
|
+
overlapping or back-to-back events ends, so a 10:00 standup followed by an 11:00 review is busy
|
|
219
|
+
until the review ends.
|
|
220
|
+
- **Horizons.** `opensAt` and `closesAt` look up to a year ahead, and `freeAt` and `nextEventAt`
|
|
221
|
+
a month ahead. They are `null` past that.
|
|
222
|
+
|
|
223
|
+
In React, `useResourceStatus(resourceId, at?)` returns both, plus `changesAt`, the next instant
|
|
224
|
+
either can change. Without `at` it follows the calendar's `clock` or `now`. It re-renders only
|
|
225
|
+
when the status changes, waking at `changesAt` rather than on every tick. It is `null` while
|
|
226
|
+
server rendering, unless the calendar fixes `now`.
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
import { useResourceStatus } from "@moltenship/calendar";
|
|
230
|
+
|
|
231
|
+
function Presence({ id }: { id: string }) {
|
|
232
|
+
const status = useResourceStatus(id);
|
|
233
|
+
if (status === null) return null;
|
|
234
|
+
return status.busy.busy ? "In a meeting" : status.availability.available ? "Around" : "Away";
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Busy badge in resource views
|
|
239
|
+
|
|
240
|
+
> Live example of the `resources` view: see it at https://time.molten.sh/docs/availability
|
|
241
|
+
|
|
242
|
+
Set `resourceStatus: true` on the resource columns or timeline view to show a badge on each
|
|
243
|
+
resource:
|
|
244
|
+
|
|
245
|
+
| State | Shows |
|
|
246
|
+
| ------------- | ---------------------------------------------------------- |
|
|
247
|
+
| Busy | "Busy until 3:00 PM", while events occupy it |
|
|
248
|
+
| Free | "Free until 5:00 PM", until its next event or closing time |
|
|
249
|
+
| Outside hours | "Outside hours until Mon 9:00 AM", until it opens |
|
|
250
|
+
| Closed today | "Closed today", or "Closed today, Company holiday" |
|
|
251
|
+
|
|
252
|
+
The words carry the state; the dot before them is colored with `--calendar-busy` or
|
|
253
|
+
`--calendar-free`. Times are on the display clock, with the weekday within the next six days and the date further out. Busy
|
|
254
|
+
wins over the hours, so a late call shows as busy. The badge is shadcn's Base UI `Badge`. In
|
|
255
|
+
your own `ResourceHeader`, add `ResourceHeaderStatus` where you want it:
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
import {
|
|
259
|
+
ResourceHeaderStatus,
|
|
260
|
+
ResourceHeaderTitle,
|
|
261
|
+
ResourceHeaderToggle,
|
|
262
|
+
} from "@/components/calendar/resource-columns-view/resource-header";
|
|
263
|
+
|
|
264
|
+
function ResourceHeader() {
|
|
265
|
+
return (
|
|
266
|
+
<>
|
|
267
|
+
<ResourceHeaderToggle />
|
|
268
|
+
<span className="flex min-w-0 flex-col">
|
|
269
|
+
<ResourceHeaderTitle />
|
|
270
|
+
<ResourceHeaderStatus />
|
|
271
|
+
</span>
|
|
272
|
+
</>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
`ResourceHeaderStatus` shows nothing for a group, whose own bookings aren't its members', or
|
|
278
|
+
without `resourceStatus`, which makes room for it in the header. For a badge anywhere else,
|
|
279
|
+
`useResourceStatusSummary(environment, resourceId)` from `resource-status.tsx` returns the words
|
|
280
|
+
and state, and `ResourceStatusBadge` draws them; `environment` is the `locale` and `timeZone` a
|
|
281
|
+
view gets in its props.
|
|
282
|
+
|
|
283
|
+
## Scheduling: who's busy?
|
|
284
|
+
|
|
285
|
+
> Live example of the `timeline-day` view: see it at https://time.molten.sh/docs/availability
|
|
286
|
+
|
|
287
|
+
While you place an event, by dragging or with the keyboard, each resource's header says whether
|
|
288
|
+
it's busy then: **Busy** when an event overlaps the draft, **Outside hours** when the time is
|
|
289
|
+
outside its hours, **Free** otherwise. Create or move an event above, and watch the row headers.
|
|
290
|
+
The draft's own event never conflicts with itself, and events that only touch don't conflict.
|
|
291
|
+
|
|
292
|
+
It all rests on one function. `busyResources` answers for many resources at once, with one query
|
|
293
|
+
of the event index, bucketed by each event's resources, so a busy person never marks the others:
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
import { busyResources } from "@moltenship/calendar";
|
|
297
|
+
|
|
298
|
+
const busy = busyResources(
|
|
299
|
+
events,
|
|
300
|
+
{ start, end },
|
|
301
|
+
{
|
|
302
|
+
exclude: "evt_42", // the event being moved, if any
|
|
303
|
+
resourceIds: ["room-orchid", "room-lotus", "maya"], // or leave out for every resource
|
|
304
|
+
timeZone: "Europe/Berlin", // for all-day and floating events
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
busy.get("maya"); // [standup, review]: the events that make Maya busy then
|
|
308
|
+
busy.has("room-lotus"); // false: free resources are absent
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
The range can also be a placement, all-day or floating, read on `timeZone`. In React:
|
|
312
|
+
|
|
313
|
+
| Hook | Returns |
|
|
314
|
+
| -------------------------------- | ----------------------------------------------------------------------------------- |
|
|
315
|
+
| `useBusyResources(range, opts?)` | `busyResources` over the root's events, once per change of events or range |
|
|
316
|
+
| `useCalendarDraft()` | The change being placed, by pointer or keyboard: `{ eventId, proposed }`, or `null` |
|
|
317
|
+
| `useDraftBusy(resourceId)` | A resource during the draft: `{ events, outsideHours }`, or `null` without one |
|
|
318
|
+
|
|
319
|
+
Drafts step by slots, so these change at most once a step. `useDraftBusy` works the draft's busy
|
|
320
|
+
resources out once for every header that asks. During a pointer drag or a keyboard create, a header
|
|
321
|
+
re-renders only when its own answer changes; a keyboard move or resize changes the events the view
|
|
322
|
+
shows on each step, so headers re-render then too, which stays cheap.
|
|
323
|
+
|
|
324
|
+
An all-day draft shows who has busy time that day, even though an all-day event is free by default
|
|
325
|
+
and so doesn't conflict under `conflictPolicy`; the status is information, not a rule. To flag or
|
|
326
|
+
prevent double-booking on save, see [double booking](#double-booking).
|
|
327
|
+
|
|
328
|
+
### Customize
|
|
329
|
+
|
|
330
|
+
Everything the views draw is a layer over these hooks, so you can replace any of it.
|
|
331
|
+
|
|
332
|
+
**Your own status in the header.** Pass `resourceStatus` options instead of `true`. `DraftStatus`
|
|
333
|
+
draws the status during a draft in place of the badge, and gets the resource, its busy events and
|
|
334
|
+
whether the draft is outside its hours. Headers also carry `data-busy` and `data-outside-hours`
|
|
335
|
+
during a draft, so CSS alone can style them.
|
|
336
|
+
|
|
337
|
+
```tsx
|
|
338
|
+
function AvatarRing({ resource, events, outsideHours }: ResourceDraftStatusProps) {
|
|
339
|
+
const ring =
|
|
340
|
+
events.length > 0 ? "ring-red-500" : outsideHours ? "ring-amber-500" : "ring-green-500";
|
|
341
|
+
return (
|
|
342
|
+
<span
|
|
343
|
+
className={`size-5 rounded-full ring-2 ${ring}`}
|
|
344
|
+
title={events.map((e) => e.title).join(", ")}
|
|
345
|
+
/>
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
createResourceColumnsView<Meeting>({ resourceStatus: { DraftStatus: AvatarRing } });
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
```css
|
|
353
|
+
[data-slot="resource-header"][data-busy] {
|
|
354
|
+
background: color-mix(in oklch, var(--calendar-busy) 12%, transparent);
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Your own words.** `labels` replaces the English the badge shows and screen readers hear, now and
|
|
359
|
+
during a draft. `until` is a time on the display clock, absent during a draft:
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
createTimelineWeekView<Meeting>({
|
|
363
|
+
resourceStatus: {
|
|
364
|
+
labels: {
|
|
365
|
+
busy: (until) => (until ? `Occupé jusqu'à ${until}` : "Occupé"),
|
|
366
|
+
free: (until) => (until ? `Libre jusqu'à ${until}` : "Libre"),
|
|
367
|
+
outsideHours: (until) => (until ? `Hors horaires jusqu'à ${until}` : "Hors horaires"),
|
|
368
|
+
closedToday: (label) => (label ? `Fermé aujourd'hui, ${label}` : "Fermé aujourd'hui"),
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Your own idea of busy.** The event adapter's `isBusy` is the one place that decides, for the
|
|
375
|
+
status, the draft headers, `busyResources` and `conflictPolicy` alike:
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
const eventAdapter = defineEventAdapter<Meeting>()({
|
|
379
|
+
// ...getId, getInterval, getResourceIds, getTitle
|
|
380
|
+
// Focus time and tentative meetings leave you bookable; all-day ones block when marked busy.
|
|
381
|
+
isBusy: (meeting) =>
|
|
382
|
+
meeting.title !== "Focus time" &&
|
|
383
|
+
meeting.showAs !== "tentative" &&
|
|
384
|
+
(meeting.kind !== "all-day" || meeting.showAs === "busy"),
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**Your own "who's busy" UI.** Any component can ask. The [live demo](https://moltenship-time-demo.vercel.app)'s
|
|
389
|
+
event dialog has a room and people picker split into Available and Busy, built on
|
|
390
|
+
`useBusyResources` rather than shipped as a part; busy rooms stay selectable, since a double
|
|
391
|
+
booking can be on purpose:
|
|
392
|
+
|
|
393
|
+
```tsx
|
|
394
|
+
function RoomPicker({ interval, eventId }: { interval: CalendarEventInterval; eventId?: string }) {
|
|
395
|
+
const busy = useBusyResources(interval, { exclude: eventId });
|
|
396
|
+
const [free, taken] = partition(rooms, (room) => !busy.has(room.id));
|
|
397
|
+
return (
|
|
398
|
+
<>
|
|
399
|
+
<Group title="Available" rooms={free} />
|
|
400
|
+
<Group
|
|
401
|
+
title="Busy"
|
|
402
|
+
rooms={taken}
|
|
403
|
+
chip={(room) =>
|
|
404
|
+
busy
|
|
405
|
+
.get(room.id)!
|
|
406
|
+
.map((e) => e.title)
|
|
407
|
+
.join(", ")
|
|
408
|
+
}
|
|
409
|
+
/>
|
|
410
|
+
</>
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
## Double booking
|
|
416
|
+
|
|
417
|
+
`conflictPolicy` in the root's `policies` checks a change against double-booking: a busy event
|
|
418
|
+
may not overlap another busy event of a resource it books. It runs the same query as
|
|
419
|
+
`busyResources`, with the reason `"resource-conflict"`. Each resource can follow its own mode, so a
|
|
420
|
+
room can't be double-booked while a person can, with a warning. Drag a booking onto another one
|
|
421
|
+
here, and switch the modes:
|
|
422
|
+
|
|
423
|
+
> Live example: see it at https://time.molten.sh/docs/availability
|
|
424
|
+
|
|
425
|
+
```tsx
|
|
426
|
+
import { conflictPolicy } from "@moltenship/calendar";
|
|
427
|
+
|
|
428
|
+
const rooms = new Set(resources.filter((r) => r.data.kind === "room").map((r) => r.id));
|
|
429
|
+
|
|
430
|
+
const policies = [
|
|
431
|
+
conflictPolicy<Meeting, string, string>({
|
|
432
|
+
mode: "warn", // people, and any resource getResourceMode leaves out
|
|
433
|
+
getResourceMode: (resourceId) => (rooms.has(resourceId) ? "block" : undefined),
|
|
434
|
+
}),
|
|
435
|
+
];
|
|
436
|
+
|
|
437
|
+
<Calendar.Root policies={policies} resources={resources} /* … */ />;
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
| Mode | Double-booking the resource… |
|
|
441
|
+
| --------- | --------------------------------------------------------------------------------------- |
|
|
442
|
+
| `"block"` | Rejects the change, and the event goes back where it was. The default. |
|
|
443
|
+
| `"warn"` | Saves it, with `"resource-conflict"` in its `warnings`, so you can say so or ask first. |
|
|
444
|
+
| `"allow"` | Saves it as it is, as if the resource had no check. |
|
|
445
|
+
|
|
446
|
+
- `mode` is the mode for every resource. `getResourceMode` gives a resource its own, by its ID;
|
|
447
|
+
`undefined` keeps `mode`. Policies don't see your resources, so look the ID up in yours, as above.
|
|
448
|
+
- When a change double-books several resources, the strictest of their modes decides: any
|
|
449
|
+
`"block"` rejects it, and otherwise any `"warn"` flags it. A room that's free doesn't block a
|
|
450
|
+
meeting whose person is busy.
|
|
451
|
+
- Only what a change alters is checked: its time, or the resources it adds when the time stays.
|
|
452
|
+
An event that's already double-booked can still be edited. Resources in `"allow"` mode aren't
|
|
453
|
+
queried at all, and deletes always pass.
|
|
454
|
+
- Events that only touch don't conflict, and an event that isn't busy books nothing: the event
|
|
455
|
+
adapter's [`isBusy`](#busy-or-available) decides, for `conflictPolicy` as for the status.
|
|
456
|
+
- The modes decide what saving does, not who's busy. A person in `"allow"` mode still shows as busy
|
|
457
|
+
in the [badge](#busy-badge-in-resource-views) and while you place an event.
|
|
458
|
+
- Previews follow the modes: dragging a meeting over a busy room that blocks marks the preview red,
|
|
459
|
+
and over a busy person who warns, amber. See [keep changes inside](#keep-changes-inside).
|
|
460
|
+
|
|
461
|
+
There's no mode per calendar. A conflict is between two bookings of one resource, often from
|
|
462
|
+
different calendars, and a new event has no calendar yet when the policies run. To keep a whole
|
|
463
|
+
calendar out of conflicts, such as tentative holds, mark its events free in `isBusy`. For stricter
|
|
464
|
+
checks on one calendar's events, choose between two policies in your own, since a policy is a
|
|
465
|
+
function:
|
|
466
|
+
|
|
467
|
+
```ts
|
|
468
|
+
import { conflictPolicy, type CalendarPolicy } from "@moltenship/calendar";
|
|
469
|
+
|
|
470
|
+
const strict = conflictPolicy<Meeting, string, string>({ mode: "block" });
|
|
471
|
+
const lenient = conflictPolicy<Meeting, string, string>({ mode: "warn" });
|
|
472
|
+
const byCalendar: CalendarPolicy<Meeting, string, string> = (change, context) =>
|
|
473
|
+
change.event?.calendarId === "interviews" ? strict(change, context) : lenient(change, context);
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
How overlapping events are drawn is separate: see
|
|
477
|
+
[rooms and people](./views/resource-columns.md#rooms-and-people) for a layout per resource.
|
|
478
|
+
|
|
479
|
+
## Keep changes inside
|
|
480
|
+
|
|
481
|
+
`availabilityPolicy({ mode })` checks every move, resize and create, whether it comes from a drag,
|
|
482
|
+
the keyboard, or `actions.proposeEventChange`. An event with resources must fit the hours of each
|
|
483
|
+
resource it books, on that resource's clock: its own hours, or the calendar's when it has none. So a
|
|
484
|
+
room open until 20:00 takes an 18:00 booking even when the office closes at 17:00. An event without
|
|
485
|
+
resources must fit the calendar's hours. A timed event must fall in open time, and an all-day event
|
|
486
|
+
on dates with open time. Only what a change alters is checked, so events already outside the hours
|
|
487
|
+
can still be edited.
|
|
488
|
+
|
|
489
|
+
| Mode | Outside the hours, the change is… |
|
|
490
|
+
| --------- | -------------------------------------------------------------------------------------------- |
|
|
491
|
+
| `"block"` | Rejected with the reason `"outside-availability"`, and the event goes back where it was. |
|
|
492
|
+
| `"warn"` | Saved, with `"outside-availability"` in its `warnings`, so you can say so or ask to confirm. |
|
|
493
|
+
|
|
494
|
+
While a gesture is in progress, its preview shows what the policies would say: a drag preview or a
|
|
495
|
+
keyboard create's draft gets a dashed outline, and an event moved or resized from the keyboard a
|
|
496
|
+
ring, red when the change would be rejected and amber when it would be saved with a warning. Your
|
|
497
|
+
own UI can ask the same question with
|
|
498
|
+
`actions.checkEventChange(proposal)`, which runs the policies without saving anything.
|
|
499
|
+
|
|
500
|
+
## Keyboard and screen readers
|
|
501
|
+
|
|
502
|
+
Availability adds no keys and no tab stops; each view keeps its [key map](./accessibility.md).
|
|
503
|
+
The shading is hidden from screen readers, which hear the same information in words:
|
|
504
|
+
|
|
505
|
+
| Where | What a screen reader hears |
|
|
506
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
507
|
+
| A time-grid slot, with ↑ ↓ | "Thursday, October 8 at 8:45 AM, outside working hours" |
|
|
508
|
+
| A month or year day | "Friday, December 25, 2026, Christmas, closed, no events" |
|
|
509
|
+
| A timeline day | "Orchid, Friday, December 25, 2026, closed" |
|
|
510
|
+
| A step of a move, resize or create | "Thursday, October 8, 4:45 – 5:15 PM, outside working hours" |
|
|
511
|
+
| A blocked drop | "Standup can't go outside working hours, so it's back where it was." |
|
|
512
|
+
| A saved change with a warning | "Moved Standup to Thursday, October 8, 4:45 – 5:15 PM, outside working hours." |
|
|
513
|
+
| A drop that double-books a room that blocks | "Standup would double-book a room or person, so it's back where it was." |
|
|
514
|
+
| A double booking saved with a warning | "Moved Standup to Thursday, October 8, 9:00 – 9:30 AM, Maya, double-booked." |
|
|
515
|
+
| A resource header in another zone | "Lee, local time 7:48 PM GMT+5:30" |
|
|
516
|
+
| A resource header with its status | "Maya, Busy until 3:00 PM" |
|
|
517
|
+
| A resource header during a draft | "Maya, Busy", or "Leo, Outside hours" |
|
|
518
|
+
|
|
519
|
+
The messages live in `components/calendar/announcements.ts` in your app, ready to translate.
|
|
520
|
+
|
|
521
|
+
## Anatomy
|
|
522
|
+
|
|
523
|
+
> Diagram: see it at https://time.molten.sh/docs/availability
|
|
524
|
+
|
|
525
|
+
```txt title="Rendered by TimeGridColumn"
|
|
526
|
+
TimeGridColumn time-grid-column.tsx
|
|
527
|
+
├── TimeGridAvailability time-grid-availability.tsx, data-slot="time-grid-unavailable"
|
|
528
|
+
├── TimeGridAnnotations time-grid-annotations.tsx
|
|
529
|
+
└── TimeGridEvent time-grid-event.tsx
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
- **Time grid and resource columns.** `TimeGridAvailability` draws an `UnavailableTime` band behind
|
|
533
|
+
the events for each closed stretch of a column, in `--calendar-unavailable`.
|
|
534
|
+
- **Timeline.** `TimelineAvailability` shades each resource's closed time along hour rows, and its
|
|
535
|
+
closed days along day rows, whose cells also get `data-closed`.
|
|
536
|
+
- **Month.** A closed day gets a `month-closed` band in `--calendar-closed`, light enough that its
|
|
537
|
+
date and events stay readable, and its cell gets `data-closed`.
|
|
538
|
+
- **Year.** Every closed day's cell gets `data-closed`; a shaded one also gets a `year-closed` band
|
|
539
|
+
in `--calendar-closed`, joined with the shaded days beside it in its row. By default only dates an
|
|
540
|
+
exception closes are shaded; `closedDays: "all"` adds the weekly closed days.
|
|
541
|
+
- **Resource headers.** `ResourceHeaderTime` shows a resource's local time and
|
|
542
|
+
`ResourceHeaderStatus` its status; add them to your own `ResourceHeader` composition.
|
|
543
|
+
|
|
544
|
+
## Your own view
|
|
545
|
+
|
|
546
|
+
The shading is separate from the event projection, like annotations, so working hours never
|
|
547
|
+
change event layout. These hooks give a view what to draw, for the calendar's hours or, with a
|
|
548
|
+
resource ID, that resource's:
|
|
549
|
+
|
|
550
|
+
| Hook | Returns |
|
|
551
|
+
| --------------------------------------- | --------------------------------------------------------------------------- |
|
|
552
|
+
| `useTimeGridAvailability(columns, id?)` | The closed bands of each time-grid column, as fractions of 24 h |
|
|
553
|
+
| `useTimelineAvailability(columns, id?)` | The closed stretches along a timeline, as fractions of its width |
|
|
554
|
+
| `useClosedDates(range, id?)` | The dates with no open time, keyed by ISO date, with a `reason` and `label` |
|
|
555
|
+
| `useResourceStatus(id?, at?)` | Working hours and events at an instant, and when either changes |
|
|
556
|
+
| `useCalendarAvailability()` | The resolved hours: `calendar`, `forResource(id)`, `timeZone` |
|
|
557
|
+
|
|
558
|
+
Bands and stretches carry their `reason`, `label`, `opensBefore` and `opensAfter`, as the
|
|
559
|
+
attributes above do.
|
|
560
|
+
|
|
561
|
+
Each schedule answers `available(range)`, `unavailable(range)` and `isAvailable(range)` for any
|
|
562
|
+
instant range, and resolves each date once, so views can ask on every render.
|
|
563
|
+
|
|
564
|
+
## Data model
|
|
565
|
+
|
|
566
|
+
| Name | Type | Default | Description |
|
|
567
|
+
| ------------ | ------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
568
|
+
| `weekly` | `AvailabilityRule[]` | | Hours by day of the week: { days, start, end }. Without it every day is open; an empty list opens only the exceptions. |
|
|
569
|
+
| `exceptions` | `AvailabilityException[]` | | Dates with other hours: { date, hours?, label? }. Without hours the date is closed. |
|
|
570
|
+
| `timeZone` | `string` | `the display time zone` | The clock the calendar's hours are on. A resource's hours follow its own timeZone instead. |
|
|
571
|
+
|
|
572
|
+
A resource's `availability` takes `weekly` and `exceptions`, and its `timeZone` sits on the
|
|
573
|
+
resource itself.
|