@moltenship/calendar 1.0.0-rc.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -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/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/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -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 +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Custom views
|
|
2
|
+
|
|
3
|
+
Define a view with a pure strategy and a Renderer component.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/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.
|
|
18
|
+
|
|
19
|
+
Everything it imports comes from `@moltenship/calendar`.
|
|
20
|
+
|
|
21
|
+
```tsx title="days-view.tsx"
|
|
22
|
+
import {
|
|
23
|
+
createCalendar,
|
|
24
|
+
defineCalendarView,
|
|
25
|
+
iteratePlainDates,
|
|
26
|
+
plainDateInterval,
|
|
27
|
+
zonedDayRange,
|
|
28
|
+
} from "@moltenship/calendar";
|
|
29
|
+
|
|
30
|
+
import { eventAdapter, meetings, weekRules, type Meeting } from "./quick-start";
|
|
31
|
+
|
|
32
|
+
export const daysView = defineCalendarView({
|
|
33
|
+
name: "days",
|
|
34
|
+
defaultOptions: { days: 3 },
|
|
35
|
+
strategy: {
|
|
36
|
+
getRange: (anchor, _environment, { days }) => plainDateInterval(anchor, anchor.add({ days })),
|
|
37
|
+
navigate: (anchor, delta, { days }) => anchor.add({ days: delta * days }),
|
|
38
|
+
getTitle: (range, { locale }) =>
|
|
39
|
+
new Intl.DateTimeFormat(locale, { day: "numeric", month: "short" }).formatRange(
|
|
40
|
+
range.start,
|
|
41
|
+
range.end.subtract({ days: 1 }),
|
|
42
|
+
),
|
|
43
|
+
project: ({ snapshot, range, environment }) =>
|
|
44
|
+
Array.from(iteratePlainDates(range), (date) => {
|
|
45
|
+
const day = zonedDayRange(date, environment.timeZone);
|
|
46
|
+
return { date, events: day.interval ? snapshot.queryTimed(day.interval) : [] };
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
Renderer: ({ projection, actions }) => (
|
|
50
|
+
<ol>
|
|
51
|
+
{projection.map(({ date, events }) => (
|
|
52
|
+
<li key={date.toString()}>
|
|
53
|
+
<button type="button" onClick={() => actions.setAnchorDate(date)}>
|
|
54
|
+
{date.toString()}
|
|
55
|
+
</button>{" "}
|
|
56
|
+
{events.length} meetings
|
|
57
|
+
</li>
|
|
58
|
+
))}
|
|
59
|
+
</ol>
|
|
60
|
+
),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Write `strategy` before `Renderer`. TypeScript reads the object in order, so the Renderer's
|
|
65
|
+
`projection` gets its type from `project`.
|
|
66
|
+
|
|
67
|
+
## Register it and set options
|
|
68
|
+
|
|
69
|
+
Pass views to `createCalendar`. View names must be unique; `createCalendar` throws on a duplicate.
|
|
70
|
+
`viewOptions` on `Root` overrides a view's `defaultOptions`, keyed by view name:
|
|
71
|
+
|
|
72
|
+
```tsx title="days-view.tsx"
|
|
73
|
+
export const Calendar = createCalendar<Meeting>()({
|
|
74
|
+
eventAdapter,
|
|
75
|
+
views: [daysView],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export function WorkWeek() {
|
|
79
|
+
return (
|
|
80
|
+
<Calendar.Root
|
|
81
|
+
events={meetings}
|
|
82
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-05")}
|
|
83
|
+
defaultTimeZone="Europe/Berlin"
|
|
84
|
+
locale="en-US"
|
|
85
|
+
weekRules={weekRules}
|
|
86
|
+
viewOptions={{ days: { days: 5 } }}
|
|
87
|
+
>
|
|
88
|
+
<Calendar.Title />
|
|
89
|
+
<Calendar.ActiveView />
|
|
90
|
+
</Calendar.Root>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The title reads "Oct 5 – 9", and the list has five days.
|
|
96
|
+
|
|
97
|
+
## Strategy
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
| ---------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `getRange` | `(anchor, environment, options) => PlainDateInterval` | Required. The visible dates, end excluded. Build it with `plainDateInterval`. |
|
|
102
|
+
| `navigate` | `(anchor, delta, options) => Temporal.PlainDate` | Required. The anchor date after moving `delta` steps. Previous and Next pass -1 and 1. |
|
|
103
|
+
| `getLoadRange` | `(anchor, environment, options) => PlainDateInterval` | The dates to project and have events for, around the visible ones, as a scrolling view keeps a page on each side. It must contain `getRange`'s dates. Without it, the view projects what it shows. |
|
|
104
|
+
| `getTitle` | `(range, environment, options) => string` | Required. The text for `<Calendar.Title />`. |
|
|
105
|
+
| `project` | `(input) => TProjection` | Required. Turns the events into what the Renderer draws. See the input below. |
|
|
106
|
+
| `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). |
|
|
107
|
+
|
|
108
|
+
`anchor` is the date in the `anchorDate` state. `environment` holds `locale`, `timeZone`,
|
|
109
|
+
`secondaryTimeZones`, `weekRules`, `direction`, and `disambiguation`. The functions should be pure:
|
|
110
|
+
`Root` calls them during render and reuses the projection until one of its inputs changes.
|
|
111
|
+
|
|
112
|
+
The [scrolling views](./scrolling.md) are the built-in views with a `getLoadRange`.
|
|
113
|
+
|
|
114
|
+
`project` receives:
|
|
115
|
+
|
|
116
|
+
| Field | Contents |
|
|
117
|
+
| --------------------- | ----------------------------------------------------------------------------------- |
|
|
118
|
+
| `snapshot` | The validated, indexed events. Query it with `queryTimed` and friends. |
|
|
119
|
+
| `range` | The visible dates, from `getRange` |
|
|
120
|
+
| `instantRange` | The same dates as instants in the calendar's time zone, ready for `queryTimed` |
|
|
121
|
+
| `loadRange` | The dates to project: `getLoadRange`'s, or `range` without it. Always set by `Root` |
|
|
122
|
+
| `environment` | Locale, time zone, secondary time zones, week rules, direction, disambiguation |
|
|
123
|
+
| `resources` | The `resources` prop as a tree by `parentId` (`roots`, `byId`) |
|
|
124
|
+
| `expandedResourceIds` | The groups whose children show; pass it to `visibleResources` |
|
|
125
|
+
| `options` | The view's options after `viewOptions` overrides |
|
|
126
|
+
| `today` | Today's date in the calendar's time zone, or `null` before a clock is known |
|
|
127
|
+
|
|
128
|
+
`today` is fixed when `Root` has `now`, so server and browser agree. Without `now` it's `null`
|
|
129
|
+
during server rendering and fills in after hydration.
|
|
130
|
+
|
|
131
|
+
### Typed events
|
|
132
|
+
|
|
133
|
+
Inside `project`, events are typed `unknown` unless you say otherwise, because a view can be used by
|
|
134
|
+
calendars with different records. To work with your own fields, annotate the input:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import type { CalendarViewProjectionInput } from "@moltenship/calendar";
|
|
138
|
+
|
|
139
|
+
project: ({ snapshot, instantRange }: CalendarViewProjectionInput<DaysOptions, Meeting>) =>
|
|
140
|
+
snapshot.queryTimed(instantRange).map(({ event }) => event.title),
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Renderer
|
|
144
|
+
|
|
145
|
+
The Renderer is a regular component, so it can use hooks. It receives:
|
|
146
|
+
|
|
147
|
+
| Prop | Contents |
|
|
148
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| `projection` | What `project` returned |
|
|
150
|
+
| `range` | The visible dates |
|
|
151
|
+
| `loadRange` | The dates `project` covered: `range`, or the strategy's wider `getLoadRange` |
|
|
152
|
+
| `options` | The view's options |
|
|
153
|
+
| `environment` | Locale, time zone, secondary time zones, week rules, direction, disambiguation |
|
|
154
|
+
| `events` | The snapshot `project` received, with [pending changes](../interactions.md#pending-changes) applied |
|
|
155
|
+
| `isReadOnly` | `true` when `Root` has no `onEventChange`: start no drags and draw no resize handles. Keyboard grabs stay off by themselves |
|
|
156
|
+
| `actions` | `setAnchorDate`, `setView`, `setSelection`, `setFocus`, `navigateNext`, `navigatePrevious`, `navigateToday`, `proposeEventChange`, `checkEventChange` |
|
|
157
|
+
|
|
158
|
+
`actions` never changes identity. `setView` takes any registered view name; an unknown name shows up
|
|
159
|
+
as an `unregistered-active-view` diagnostic. `proposeEventChange` and `events` are what a view needs
|
|
160
|
+
to let people [drag and resize events](../interactions.md#drag-resize-and-create).
|
|
161
|
+
|
|
162
|
+
To declare a Renderer as its own component, type its props with `CalendarViewRendererProps`:
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import type { CalendarViewRendererProps } from "@moltenship/calendar";
|
|
166
|
+
|
|
167
|
+
function DaysRenderer({ projection }: CalendarViewRendererProps<DaysProjection, DaysOptions>) {
|
|
168
|
+
// …
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Reading the view from other components
|
|
173
|
+
|
|
174
|
+
Components inside `Root` can read the active view without being part of it:
|
|
175
|
+
|
|
176
|
+
```tsx title="days-view.tsx"
|
|
177
|
+
export function VisibleRange() {
|
|
178
|
+
const range = Calendar.useVisibleRange();
|
|
179
|
+
if (range === null) return null;
|
|
180
|
+
return (
|
|
181
|
+
<p>
|
|
182
|
+
{range.start.toString()} to {range.end.subtract({ days: 1 }).toString()}
|
|
183
|
+
</p>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- `Calendar.useVisibleRange()` returns the visible dates, or `null` when the active view isn't
|
|
189
|
+
registered.
|
|
190
|
+
- `Calendar.useViewProjection()` returns the active view's `view` name, `definition`,
|
|
191
|
+
`projection`, `range`, `instantRange`, `loadRange`, `loadInstantRange`, `options`,
|
|
192
|
+
`environment`, and `events`, or `null`. Check `view` to
|
|
193
|
+
narrow `projection` to that view's type.
|
|
194
|
+
- `useNow({ intervalMs })` returns the current instant for a now-line and re-renders on each tick.
|
|
195
|
+
It's `null` during server rendering and hydration unless `Root` has `now`.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Month
|
|
2
|
+
|
|
3
|
+
A month grid with multi-day bars and a "+N more" popover.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/views/month
|
|
6
|
+
|
|
7
|
+
> Live example of the `month` view: see it at https://time.molten.sh/docs/react/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/react/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 | Default | Description |
|
|
61
|
+
| ------------------- | ---------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `dragPreview` | `"snapped" \| "free"` | `"snapped"` | How a drag's preview moves: from slot to slot, or with the pointer over a marker of where it would land, snapping there on release. See [snapped and free drags](../interactions.md#snapped-and-free-drags). |
|
|
63
|
+
| `getEventColor` | `(event: TEvent) => CalendarEventColor` | | The color for each event. See [event colors](../theming.md#event-colors). |
|
|
64
|
+
| `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). |
|
|
65
|
+
| `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
|
|
66
|
+
| `renderUnavailable` | `UnavailableTimeRender` | | Replaces the shading of closed days: a function of its props and its state. See [customize the shading](../availability.md#customize-the-shading). |
|
|
67
|
+
|
|
68
|
+
## What it shows
|
|
69
|
+
|
|
70
|
+
- **Days:** weekday names across the top. Days outside the month are muted, today's date sits in a
|
|
71
|
+
filled circle, and the first of each month reads "Oct 1".
|
|
72
|
+
- **Multi-day and all-day events** are bars across the days they cover. A bar that continues into
|
|
73
|
+
the previous or next week ends with a chevron. Timed bars start with their start time.
|
|
74
|
+
- **Single-day timed events** show a colored dot, the start time, and the title. On narrow screens
|
|
75
|
+
they become small tinted blocks.
|
|
76
|
+
- **"+N more":** rows grow to fill the available height, at least 80px each, and show as many
|
|
77
|
+
events as fit. The rest collapse into "+N more", which opens a popover with the day's events.
|
|
78
|
+
- **Clicking a date number** opens that day in the view named `day`. Register a
|
|
79
|
+
[day view](./week-and-day.md) so the click has somewhere to go.
|
|
80
|
+
- **Editing:** with `onEventChange` on `Root`, drag an event to another day (timed events keep their
|
|
81
|
+
time), and drag across days to create an all-day event. See
|
|
82
|
+
[Interactions](../interactions.md#drag-resize-and-create).
|
|
83
|
+
- **Changes being saved:** events with a [pending change](../interactions.md#pending-changes) get
|
|
84
|
+
`aria-busy` and render at 60% opacity.
|
|
85
|
+
|
|
86
|
+
## Keyboard
|
|
87
|
+
|
|
88
|
+
Tab into the preview above, or click a day, and try these keys. The
|
|
89
|
+
[Accessibility](../accessibility.md#keyboard) page has the full map and what a screen reader hears.
|
|
90
|
+
|
|
91
|
+
| Focus | Key | Effect |
|
|
92
|
+
| -------- | ------------------ | ----------------------------------------------------------------------------- |
|
|
93
|
+
| A day | ← → | Previous or next day |
|
|
94
|
+
| A day | ↑ ↓ | Same weekday a week earlier or later |
|
|
95
|
+
| A day | Home, End | First or last day of the week |
|
|
96
|
+
| A day | Page Up, Page Down | Same day in the previous or next month |
|
|
97
|
+
| A day | Enter | Go into the day's events. ↑ ↓ walk them, and Escape goes back to the day |
|
|
98
|
+
| A day | Shift+Enter | Open the day in the day view |
|
|
99
|
+
| A day | Space | Start an all-day event there. Arrow keys extend it, and Enter saves it |
|
|
100
|
+
| An event | Space | Pick it up. Arrow keys move it by days, Enter saves, and Escape cancels |
|
|
101
|
+
| An event | Shift+Space | Pick up its end to resize it by days. Shift+Space again switches to its start |
|
|
102
|
+
|
|
103
|
+
Events behind "+N more" are reachable too: while focus is on one, its week shows every event.
|
|
104
|
+
|
|
105
|
+
## Markup for interactions
|
|
106
|
+
|
|
107
|
+
The view connects the pointer layer for you. If you change its markup, keep the attributes it reads:
|
|
108
|
+
each day cell holds an element with `data-date` underneath its events, and each event is a
|
|
109
|
+
`<button>` with `data-event-id`. The events sit beside that element, not inside it, so a drag over
|
|
110
|
+
a bar still finds the day under the pointer.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# Resource columns
|
|
2
|
+
|
|
3
|
+
A day or a few days of rooms or people side by side, grouped by team, with hundreds of columns.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/views/resource-columns
|
|
6
|
+
|
|
7
|
+
> Live example of the `resources` view: see it at https://time.molten.sh/docs/react/views/resource-columns
|
|
8
|
+
|
|
9
|
+
Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Resources in the view
|
|
10
|
+
switcher.
|
|
11
|
+
|
|
12
|
+
`createResourceColumnsView` shows one time-grid column for each resource, such as a room or a
|
|
13
|
+
person, for the anchor date. Pass a number of days to give each resource that many day columns.
|
|
14
|
+
Resources with children appear as groups that collapse. Only the columns in view are rendered, so
|
|
15
|
+
the view stays fast with hundreds of resources.
|
|
16
|
+
|
|
17
|
+
## Add it
|
|
18
|
+
|
|
19
|
+
Add the view to your app with the shadcn CLI, as described in
|
|
20
|
+
[UI source](../installation.md#ui-source-optional). The item brings `time-grid-view`, whose
|
|
21
|
+
columns, events and all-day row it reuses, the theme, the shared `calendar` parts, and
|
|
22
|
+
`@tanstack/react-virtual`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx shadcn@latest add https://time.molten.sh/r/resource-columns-view.json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { createResourceColumnsView } from "@/components/calendar/resource-columns-view/resource-columns-view";
|
|
30
|
+
|
|
31
|
+
export const Calendar = createCalendar<Meeting, Room>()({
|
|
32
|
+
eventAdapter,
|
|
33
|
+
views: [createResourceColumnsView<Meeting>({ getEventColor: (meeting) => meeting.color })],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The view is named `resources`. Previous and Next move by its number of days:
|
|
38
|
+
`createResourceColumnsView<Meeting>(options, 3)` shows three days for each resource.
|
|
39
|
+
|
|
40
|
+
## Resources
|
|
41
|
+
|
|
42
|
+
Pass the resources to `Root`. Each one has an `id`, a `title`, and optionally a `parentId`, which
|
|
43
|
+
puts it in a group under that resource. Events list the resources they book in `resourceIds`, read
|
|
44
|
+
through your event adapter's `getResourceIds`. An event that books several resources shows in each
|
|
45
|
+
of their columns.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
const rooms = [
|
|
49
|
+
{ data: null, id: "floor-1", title: "First floor" },
|
|
50
|
+
{ data: null, id: "orchid", parentId: "floor-1", title: "Orchid" },
|
|
51
|
+
{ data: null, id: "lotus", parentId: "floor-1", title: "Lotus" },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
<Calendar.Root resources={rooms} defaultExpandedResourceIds={["floor-1"]} /* … */>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
A group's children show while its ID is in `expandedResourceIds`. The chevron on a group's header
|
|
58
|
+
toggles it. To control expansion yourself, pass `expandedResourceIds` and
|
|
59
|
+
`onExpandedResourceIdsChange`. Groups start collapsed unless you list them in
|
|
60
|
+
`defaultExpandedResourceIds`.
|
|
61
|
+
|
|
62
|
+
## Avatars and icons
|
|
63
|
+
|
|
64
|
+
Columns often mix people and rooms, and a bare name doesn't say which is which. To show it, pass
|
|
65
|
+
your own `ResourceHeader`. It draws each header's name row from small parts, so you can put a
|
|
66
|
+
person's avatar or a room's icon before the name, as the preview above does. Teams there keep just
|
|
67
|
+
their chevron.
|
|
68
|
+
|
|
69
|
+
Keep what the header needs in each resource's `data`, and give it a type. The view takes it as its
|
|
70
|
+
second type parameter, so the component can read it:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import type { CalendarResource } from "@moltenship/calendar";
|
|
74
|
+
import { DoorOpenIcon } from "lucide-react";
|
|
75
|
+
|
|
76
|
+
import {
|
|
77
|
+
ResourceHeaderIcon,
|
|
78
|
+
ResourceHeaderTitle,
|
|
79
|
+
ResourceHeaderToggle,
|
|
80
|
+
type ResourceHeaderProps,
|
|
81
|
+
} from "@/components/calendar/resource-columns-view/resource-header";
|
|
82
|
+
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
83
|
+
|
|
84
|
+
// For example { data: { avatar: "/avatars/maya.png", kind: "person" }, id: "maya", title: "Maya" }
|
|
85
|
+
type Resource = CalendarResource<
|
|
86
|
+
{ kind: "room" } | { kind: "team" } | { avatar: string; kind: "person" }
|
|
87
|
+
>;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Then compose the parts: the chevron, an avatar for a person or a door for a room, and the name.
|
|
91
|
+
Pass the component to the view:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
function ResourceHeader({ resource, title }: ResourceHeaderProps<Resource>) {
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
<ResourceHeaderToggle />
|
|
98
|
+
{resource?.data.kind === "person" && (
|
|
99
|
+
<ResourceHeaderIcon>
|
|
100
|
+
<Avatar size="sm">
|
|
101
|
+
<AvatarImage alt="" src={resource.data.avatar} />
|
|
102
|
+
<AvatarFallback>{title.slice(0, 1)}</AvatarFallback>
|
|
103
|
+
</Avatar>
|
|
104
|
+
</ResourceHeaderIcon>
|
|
105
|
+
)}
|
|
106
|
+
{resource?.data.kind === "room" && (
|
|
107
|
+
<ResourceHeaderIcon className="size-6 justify-center rounded-md bg-muted text-muted-foreground">
|
|
108
|
+
<DoorOpenIcon className="size-3.5" />
|
|
109
|
+
</ResourceHeaderIcon>
|
|
110
|
+
)}
|
|
111
|
+
<ResourceHeaderTitle />
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const view = createResourceColumnsView<Meeting, Resource>({ ResourceHeader });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The parts live in `resource-header.tsx`:
|
|
120
|
+
|
|
121
|
+
- `ResourceHeaderToggle` is a group's chevron. It renders nothing for a resource without children.
|
|
122
|
+
- `ResourceHeaderIcon` wraps anything you draw before the name. Screen readers skip it, because the
|
|
123
|
+
name beside it already says who or what the column is.
|
|
124
|
+
- `ResourceHeaderTitle` is the name, cut short with an ellipsis. Children replace it.
|
|
125
|
+
- `useResourceHeader()` gives your own parts the resource, its name and its groups.
|
|
126
|
+
`DefaultResourceHeader` is the toggle and the title.
|
|
127
|
+
|
|
128
|
+
`resource` is `null` for the Unassigned column. The view keeps the rest of the header: the group
|
|
129
|
+
bands, the row heights and the group names screen readers hear. A row is 2rem tall, so keep
|
|
130
|
+
icons at 24px (`size-6`) or smaller. `Avatar` is shadcn's: `npx shadcn@latest add avatar`. It
|
|
131
|
+
shows the fallback, here the person's initial, until the image loads.
|
|
132
|
+
|
|
133
|
+
## Rooms and people
|
|
134
|
+
|
|
135
|
+
Rooms and people often want different layouts. A room's bookings can stack, so a busy room reads
|
|
136
|
+
at a glance, while a person's meetings sit side by side. `getResourceOverlapLayout` gives each
|
|
137
|
+
resource's columns a layout of its own; it takes the resource with your `data` type, so it can read
|
|
138
|
+
what kind it is:
|
|
139
|
+
|
|
140
|
+
> Live example: see it at https://time.molten.sh/docs/react/views/resource-columns
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
const view = createResourceColumnsView<Meeting, Resource>({
|
|
144
|
+
getResourceOverlapLayout: (resource) => (resource.data.kind === "room" ? "stack" : undefined),
|
|
145
|
+
overlapLayout: "columns",
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The most specific layout wins, and each `undefined` falls through to the next:
|
|
150
|
+
|
|
151
|
+
1. An event's own layout, from `getEventOverlapLayout`, such as its calendar's. A group of
|
|
152
|
+
overlapping events takes it only when they all agree, as in the
|
|
153
|
+
[week and day views](./week-and-day.md#by-calendar).
|
|
154
|
+
2. The column's resource, from `getResourceOverlapLayout`.
|
|
155
|
+
3. The view's `overlapLayout`, then `"columns"`.
|
|
156
|
+
|
|
157
|
+
A group whose events disagree takes its column's layout, from 2 or 3. The Unassigned column isn't
|
|
158
|
+
a resource, so it follows `overlapLayout`. An event that books a room and a person is laid out in
|
|
159
|
+
each column by that column's layout, and a move to another resource redraws it there by the new
|
|
160
|
+
one's, also while the change is still saving. Keyboard focus and the drawing order follow what's
|
|
161
|
+
drawn in each column: ↑ and ↓ walk its events top to bottom, and ← and → step to the overlapping
|
|
162
|
+
event drawn beside.
|
|
163
|
+
|
|
164
|
+
Whether a room may be double-booked at all is a separate rule, with a mode per resource too: see
|
|
165
|
+
[double booking](../availability.md#double-booking).
|
|
166
|
+
|
|
167
|
+
## Anatomy
|
|
168
|
+
|
|
169
|
+
`ResourceColumnsView` renders the parts below. The view builds them itself from its projection, so
|
|
170
|
+
they're not parts you compose: to change one, edit its file. The exception is each header's name
|
|
171
|
+
row, which you can replace with [`ResourceHeader`](#avatars-and-icons). The tree shows where each
|
|
172
|
+
part lives.
|
|
173
|
+
|
|
174
|
+
> Diagram: see it at https://time.molten.sh/docs/react/views/resource-columns
|
|
175
|
+
|
|
176
|
+
```txt title="Rendered by ResourceColumnsView"
|
|
177
|
+
ResourceColumnsView resource-columns-view.tsx
|
|
178
|
+
├── ResourceColumnsHeader resource-columns-header.tsx
|
|
179
|
+
│ └── Resource header one per rendered resource
|
|
180
|
+
│ └── ResourceHeader resource-header.tsx, or your own composition
|
|
181
|
+
├── ResourceColumnsDates resource-columns-dates.tsx, over N days
|
|
182
|
+
├── ResourceColumnsAllDay resource-columns-all-day.tsx
|
|
183
|
+
│ └── TimeGridAllDayCells one set per rendered resource
|
|
184
|
+
└── ResourceColumnsBody resource-columns-body.tsx, scrolls both ways
|
|
185
|
+
├── Time gutter --calendar-gutter-width, with secondary time zones
|
|
186
|
+
└── Resource column data-resource-id
|
|
187
|
+
└── TimeGridColumn time-grid-column.tsx, one per day
|
|
188
|
+
├── TimeGridEvent time-grid-event.tsx
|
|
189
|
+
└── Now line data-slot="time-grid-now"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- The column virtualizer in `column-virtualizer.ts`, which `use-column-virtualizer.ts` binds,
|
|
193
|
+
decides which columns render. Columns share the width until they are 128px per day, then the
|
|
194
|
+
view scrolls sideways.
|
|
195
|
+
- The header, all-day row and gutter sit beside the scrolling body, not over it. The axis sync in
|
|
196
|
+
`axis-sync.ts`, which `use-axis-sync.ts` binds, moves them with the body's scroll, so a drag never
|
|
197
|
+
lands on a column hidden behind them.
|
|
198
|
+
- Words such as "Unassigned" are in `resource-columns-labels.ts`, sizes in
|
|
199
|
+
`resource-columns-layout.ts`, and the classes in `resource-columns.styles.ts`.
|
|
200
|
+
|
|
201
|
+
## Options
|
|
202
|
+
|
|
203
|
+
| Name | Type | Default | Description |
|
|
204
|
+
| -------------------------- | ----------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
205
|
+
| `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
|
|
206
|
+
| `dragPreview` | `"snapped" \| "free"` | `"snapped"` | How a drag's preview moves: from slot to slot, or with the pointer over a marker of where it would land, snapping there on release. See [snapped and free drags](../interactions.md#snapped-and-free-drags). |
|
|
207
|
+
| `getEventColor` | `(event: TEvent) => CalendarEventColor \| undefined` | | The color for each event. See [event colors](../theming.md#event-colors). |
|
|
208
|
+
| `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). |
|
|
209
|
+
| `getEventOverlapLayout` | `(event: TEvent) => "columns" \| "equal" \| "stack" \| undefined` | | An event's own layout, such as its calendar's, as in the [week and day views](./week-and-day.md#by-calendar). A group that disagrees takes its column's. |
|
|
210
|
+
| `getResourceOverlapLayout` | `(resource: TResource) => "columns" \| "equal" \| "stack" \| undefined` | | A resource's layout in its columns, such as `"stack"` for rooms; `undefined` keeps `overlapLayout`. See [rooms and people](#rooms-and-people). |
|
|
211
|
+
| `overlapLayout` | `"columns" \| "equal" \| "stack"` | `"columns"` | How overlapping events share a resource's column, as in the [week and day views](./week-and-day.md#overlapping-events), unless `getResourceOverlapLayout` gives the resource its own. |
|
|
212
|
+
| `ResourceHeader` | `ComponentType<ResourceHeaderProps<TResource>>` | `DefaultResourceHeader` | Draws each header's name row from the `resource-header.tsx` parts. See [avatars and icons](#avatars-and-icons). |
|
|
213
|
+
| `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. |
|
|
214
|
+
| `unassigned` | `"hide" \| "bucket"` | `"hide"` | Events that book no resources: hidden, or shown in an "Unassigned" column after the resources. |
|
|
215
|
+
| `renderUnavailable` | `UnavailableTimeRender` | | Replaces the shading of closed time: a function of its props and its state. See [customize the shading](../availability.md#customize-the-shading). |
|
|
216
|
+
| `resourceStatus` | `boolean \| ResourceStatusOptions` | | Shows each resource's status, such as "Busy until 3:00 PM". See [busy badge](../availability.md#busy-badge-in-resource-views). |
|
|
217
|
+
|
|
218
|
+
Set options when you create the view, or per calendar with
|
|
219
|
+
`viewOptions={{ resources: { unassigned: "bucket" } }}` on `Root`.
|
|
220
|
+
|
|
221
|
+
## What it shows
|
|
222
|
+
|
|
223
|
+
- **Header:** each resource's name, or what your `ResourceHeader` draws. An expanded group's band
|
|
224
|
+
names it across its own column and its children's columns. Over several days, a row under the
|
|
225
|
+
names shows each day's weekday and date.
|
|
226
|
+
- **All-day row:** each resource's all-day events, and timed events of 24 hours or more. Busy days
|
|
227
|
+
collapse to three rows with "+N more" in every column at once, so the row keeps one height.
|
|
228
|
+
- **Columns:** the same hours, events, daylight-saving bands and now line as the
|
|
229
|
+
[day view](./week-and-day.md).
|
|
230
|
+
- **Editing:** with `onEventChange` on `Root`, drag an event within its column to move or resize it,
|
|
231
|
+
or into another resource's column to move it there. A move swaps the resource you dragged from
|
|
232
|
+
for the one you dropped on and keeps the event's other resources. Drag across empty time or
|
|
233
|
+
all-day cells to create an event in that resource. See
|
|
234
|
+
[Interactions](../interactions.md#drag-resize-and-create).
|
|
235
|
+
- **Accessible names:** events, slots and all-day cells include their resource, as in "Design
|
|
236
|
+
review, Tuesday, October 6, 10:00 – 11:30 AM, Orchid". Announcements name it too: "Moved Design
|
|
237
|
+
review to Tuesday, October 6, 10:00 – 11:30 AM, Cedar, Maya, Alex."
|
|
238
|
+
|
|
239
|
+
## Keyboard
|
|
240
|
+
|
|
241
|
+
Tab into the preview above, or click a slot, and try these keys. Columns run resource by resource:
|
|
242
|
+
each resource's days, then the next resource. Inside a column the keys are the
|
|
243
|
+
[day view's](./week-and-day.md#keyboard). The
|
|
244
|
+
[Accessibility](../accessibility.md#keyboard) page has the full map and what a screen reader hears.
|
|
245
|
+
|
|
246
|
+
| Focus | Key | Effect |
|
|
247
|
+
| ------------- | ------------------ | -------------------------------------------------------------------------------------------- |
|
|
248
|
+
| A day or slot | ← → | Same slot in the previous or next column, crossing into the next resource |
|
|
249
|
+
| A day or slot | ← → past the ends | On to the day before or after the range, in the last or first resource |
|
|
250
|
+
| A day or slot | Home, End | First or last column |
|
|
251
|
+
| A day or slot | Page Up, Page Down | Same resource, a whole day (or range) earlier or later |
|
|
252
|
+
| A day or slot | ↑ ↓, Enter | As in the day view: slots, the all-day cell, and the events covering a slot |
|
|
253
|
+
| A day or slot | Space | Start an event there, in that column's resource |
|
|
254
|
+
| An event | Space | Pick it up. ← → move it across columns, and into another resource it swaps that one resource |
|
|
255
|
+
|
|
256
|
+
Focus can move to a resource that's scrolled out of view: its column renders and scrolls in, and
|
|
257
|
+
it stays rendered while you scroll away, so focus is never lost.
|
|
258
|
+
|
|
259
|
+
## Markup for interactions
|
|
260
|
+
|
|
261
|
+
The view connects the pointer layer for you. Each resource's cells sit inside an element with
|
|
262
|
+
`resourceIdAttributes(id)`, which sets `data-resource-id`: a drop or create inside it lands in that
|
|
263
|
+
resource. Inside, the attributes are the [day view's](./week-and-day.md#markup-for-interactions):
|
|
264
|
+
`data-date` on day columns and all-day cells, `data-all-day` on all-day cells, `data-event-id` on
|
|
265
|
+
events, and `data-resize` handles.
|