calendar-components 0.0.0 → 0.7.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brian Hung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,541 @@
1
- # calendar-components
1
+ # Calendar Components
2
2
 
3
- Unstyled, composable calendar views for React. Not released yet.
3
+ Unstyled, composable calendar views for React: a day or week by the hour (`TimeGrid`), a week's strip or a month of days (`DateGrid`), and a schedule as a list (`Agenda`).
4
+
5
+ Docs: [calendar.brianhung.me](https://calendar.brianhung.me). Private for now, on GitHub Packages as `calendar-components`; the API will change. It will be `calendar-components` on npm when it is opened.
6
+
7
+ ## Usage
8
+
9
+ ```tsx
10
+ "use client";
11
+
12
+ import { TimeGrid } from "calendar-components";
13
+
14
+ const days = [{ date: "2026-11-22", events: [{ id: "temple", start: 570, end: 660 }] }];
15
+
16
+ export function Week() {
17
+ return (
18
+ <TimeGrid.Root days={days} onValueChange={(id) => console.log(id)}>
19
+ <TimeGrid.Hours />
20
+ {days.map((day) => (
21
+ <TimeGrid.Column key={day.date} day={day}>
22
+ <TimeGrid.Lines />
23
+ <TimeGrid.Events>{(item) => <TimeGrid.Event {...item} label="Lama Temple" />}</TimeGrid.Events>
24
+ <TimeGrid.Now />
25
+ </TimeGrid.Column>
26
+ ))}
27
+ </TimeGrid.Root>
28
+ );
29
+ }
30
+ ```
31
+
32
+ An event's `start` and `end` are minutes past its day's midnight.
33
+
34
+ ## Conventions
35
+
36
+ The parts follow Base UI's, as `emoji-components` does.
37
+
38
+ | | |
39
+ |---|---|
40
+ | `className`, `style` | A value, or a function of the part's state: `className={(state) => state.selected ? "on" : "off"}` |
41
+ | `children` | Nodes, or a function of the part's state |
42
+ | `render` | An element or a function, to draw the part as something else: `render={<article />}` |
43
+ | `value`, `defaultValue`, `onValueChange(value, details)` | What is selected (an event, or a day), controlled or not. `details.reason` says why, `details.trigger` is the element it came from, and `details.cancel()` keeps the old value, in all three components |
44
+ | `actionsRef` | What a component can be told to do: scroll to a time, an event or a day |
45
+ | Handlers | Yours run first. `event.preventCalendarComponentsHandler()` skips the part's own |
46
+ | `data-slot` | Every part names itself: `time-grid`, `time-grid-event`, … |
47
+ | State attributes | Present or absent: `data-selected`, `data-dragging`, `data-today`, `data-weekend`, `data-hovered`, `data-pressed`, `data-focus-visible`, `data-disabled` |
48
+ | CSS variables | `--time-grid-hour-height`, `--time-grid-height`, `--time-grid-days` on the root; `--time-grid-event-height` on an event (its `short` and `tall` states turn at `eventHeights`, 40 and 52px unless you say); `--date-grid-start-column` on a month's heading |
49
+ | Types | `TimeGrid.Event.Props`, `TimeGrid.Event.State`; every part's attribute names in a module beside it, exported as `TimeGridEventDataAttributes` |
50
+
51
+ An event's `id` is one event's, across every day given: the keyboard, selection and the list's rows go by it. One that repeats, or is listed on two days, needs an id for each.
52
+
53
+ ## shadcn/ui
54
+
55
+ `apps/demo/registry/calendar.tsx` is the styled version, in shadcn/ui's way:
56
+ small wrappers over the parts, with Tailwind classes and your theme's tokens
57
+ (`bg-background`, `border-border`, `bg-primary`), which you own once added.
58
+ `registry.json` lists it for `npx shadcn add https://calendar.brianhung.me/r/calendar.json`.
59
+
60
+ It has the time grid, a day picker, a month with each day's events
61
+ (`MonthGrid`, `MonthGridCell`, `MonthGridEvent`), and a list (`Agenda…`).
62
+ Two more items build on your own shadcn/ui parts, as emoji-components'
63
+ popover does: `calendar-toolbar` (Today, back, on and a view switch, in your
64
+ `button` and `toggle-group`) and `calendar-event-popover` (an event's details
65
+ in a popover that points at the picked event, on Base UI).
66
+
67
+ ```tsx
68
+ <TimeGrid days={days} onEventChange={save}>
69
+ <TimeGridHours />
70
+ {days.map((day) => (
71
+ <TimeGridColumn key={day.date} day={day}>
72
+ <TimeGridLines />
73
+ <TimeGridEvents>{(item) => <TimeGridEvent {...item} label={item.event.name} />}</TimeGridEvents>
74
+ <TimeGridNow />
75
+ </TimeGridColumn>
76
+ ))}
77
+ </TimeGrid>
78
+ ```
79
+
80
+ Run `npm run dev` and open `/gallery/?theme=shadcn`: one set of events as a day, a week, a month and a list.
81
+
82
+ ## Themes
83
+
84
+ The parts are unstyled. Three stylesheets dress them, and the markup is the same for each: the difference is a class.
85
+
86
+ ```tsx
87
+ import "calendar-components/apple.css"; // or "calendar-components/google.css"
88
+
89
+ <TimeGrid.Root days={days} className="calendar calendar-apple calendar-week">
90
+ ```
91
+
92
+ An event takes its colour from `--calendar-color`. `base.css` is the layout both share, for a theme of your own.
93
+
94
+ `apple.css` is Apple Calendar for the width it has: Calendar on macOS from 640px, and under that Calendar on iOS, measured from an iPhone (53pt hours, a 62pt gutter, and its event's insets, bar and colours). An hour's height is a prop, so give `hourHeight` by the same query: 37 in a window, 53 on a phone. Open `/gallery/?theme=apple` at either width.
95
+
96
+ | | Apple, in a window | Google | Apple, on a phone |
97
+ |---|---|---|---|
98
+ | Event | a wash of its colour, a bar down the leading edge, 3pt corners | solid colour, white words, 6px corners | a wash you can see the lines through, a round-ended bar |
99
+ | Picked | the colour itself, white words | lifted on a shadow | the colour itself |
100
+ | Today | red filled date | blue filled date | red filled date |
101
+ | Month | `/gallery/?theme=apple&view=month` | `/gallery/?theme=google&view=month` | compact, stacked and details: `/gallery/?theme=apple&view=month&layout=stacked` |
102
+ | List | | | `/gallery/?theme=apple&view=list` |
103
+ | Two days | | | `/gallery/?theme=apple&view=days` |
104
+ | Round a view, and an event's own screen | | | navigation pills, a large title and Today: `/gallery/?theme=apple&view=month&layout=stacked&chrome`; an event: `/gallery/?theme=apple&view=event` |
105
+
106
+ Each theme's numbers are measured from the app it copies (pixels of
107
+ screenshots for Apple's, computed styles for Google's), written at the top
108
+ of its stylesheet, and held by a test in `apps/demo/e2e`. The Apple and
109
+ Google themes keep those apps' colours, which do not all meet WCAG contrast.
110
+
111
+ A month's day is marked up the same in every theme: the date in
112
+ `.calendar-date`, and the day's events in the cell's `details` as
113
+ `.calendar-chip` (all day) and `.calendar-timed` (its name, then its time).
114
+ Apple's compact and stacked layouts on a phone take `.calendar-dot` and `.calendar-bar`
115
+ in the day itself.
116
+
117
+ Events that overlap in time share their day's width side by side. Give the
118
+ time grid `laneOverlap={0.7}` and each runs under the next instead, as Google
119
+ Calendar lays them out (the Google theme expects it).
120
+
121
+ Give the time grid `workHours={{ from: 8, to: 18 }}` and lines and hours
122
+ outside them carry `data-off-hours`, which the Apple theme draws lighter.
123
+
124
+ Scrolling is continuous unless you say otherwise. Give the time grid
125
+ `scrollSnap="days"`, `"hours"` or `"both"` and a scroll comes to rest on a
126
+ day's start, on an hour's line, or on both. Give it `scrollLock` and a touch
127
+ scrolls one way at a time: the hours, or the days, whichever the finger first
128
+ goes.
129
+
130
+ ## A calendar from your events
131
+
132
+ Keep your events as you have them: a list, each with an id and when it
133
+ starts and ends, as `Date`s or ISO strings. `useEventCalendar` takes them
134
+ from an array or from a server and gives back what a calendar needs: the
135
+ view, the day it is round, stepping through it, and `days` for a grid.
136
+
137
+ ```tsx
138
+ // Events on a server: asked for by the days shown, saved when one is moved.
139
+ const calendar = useEventCalendar({
140
+ loadEvents: (range, { signal }) => fetch(`/events?from=${range.start}&to=${range.end}`, { signal }).then((r) => r.json()),
141
+ onEventChange: (change, times) => fetch(`/events/${change.id}`, { method: "PATCH", body: JSON.stringify(times) }),
142
+ });
143
+
144
+ // Or events in your own state.
145
+ const [events, setEvents] = useState([
146
+ { id: "gym", start: "2026-11-23T15:00:00Z", end: "2026-11-23T16:30:00Z" },
147
+ { id: "stay", start: "2026-11-23", end: "2026-11-26" }, // a day alone lasts the day
148
+ ]);
149
+ const calendar = useEventCalendar({ events, onEventChange: (change) => setEvents((all) => applyEventChange(all, change)) });
150
+
151
+ <TimeGrid.Root days={calendar.days} onEventChange={calendar.changeEvent}>
152
+ ```
153
+
154
+ With `loadEvents` the events are React Stately's
155
+ [`useAsyncList`](https://react-spectrum.adobe.com/react-stately/useAsyncList.html),
156
+ filtered by the days to load:
157
+
158
+ - It asks when the days shown change, for those days and a step either side, so a step on or back is drawn from what is held while its own days load.
159
+ - A new ask aborts the one before it (`signal`), and only the latest answer is taken.
160
+ - A moved event is drawn where it was put at once, whatever a load answers meanwhile. If the promise `onEventChange` returns rejects, it goes back, and `error` says why.
161
+ - `isLoading`, `error` and `reload()` are there for your own words.
162
+
163
+ An instant ("…Z", or a `Date`) is read in the calendar's `timeZone`; a time
164
+ with no zone is that time wherever it is read. With a query library of your
165
+ own, use `useCalendarView` for `range` and `dates`, and `groupByDay` for the
166
+ days. For events that repeat, expand their rules (`rrule`, or ical.js for
167
+ an .ics file) over the range asked for.
168
+
169
+ With shadcn/ui, `EventCalendar` is all of it from one import: a day, a week,
170
+ a month and a list, a toolbar, an event's details, and drag to move and resize.
171
+
172
+ ```tsx
173
+ <EventCalendar loadEvents={loadEvents} onEventChange={saveEvent} />
174
+ ```
175
+
176
+ Run `npm run dev` and open `/gallery/?theme=shadcn`: one set of events as a day, a week, a month and a list.
177
+
178
+ ## Themes
179
+
180
+ The parts are unstyled. Three stylesheets dress them, and the markup is the same for each: the difference is a class.
181
+
182
+ ```tsx
183
+ import "calendar-components/apple.css"; // or "calendar-components/google.css"
184
+
185
+ <TimeGrid.Root days={days} className="calendar calendar-apple calendar-week">
186
+ ```
187
+
188
+ An event takes its colour from `--calendar-color`. `base.css` is the layout both share, for a theme of your own.
189
+
190
+ `apple.css` is Apple Calendar for the width it has: Calendar on macOS from 640px, and under that Calendar on iOS, measured from an iPhone (53pt hours, a 62pt gutter, and its event's insets, bar and colours). An hour's height is a prop, so give `hourHeight` by the same query: 37 in a window, 53 on a phone. Open `/gallery/?theme=apple` at either width.
191
+
192
+ | | Apple, in a window | Google | Apple, on a phone |
193
+ |---|---|---|---|
194
+ | Event | a wash of its colour, a bar down the leading edge, 3pt corners | solid colour, white words, 6px corners | a wash you can see the lines through, a round-ended bar |
195
+ | Picked | the colour itself, white words | lifted on a shadow | the colour itself |
196
+ | Today | red filled date | blue filled date | red filled date |
197
+ | Month | `/gallery/?theme=apple&view=month` | `/gallery/?theme=google&view=month` | compact, stacked and details: `/gallery/?theme=apple&view=month&layout=stacked` |
198
+ | List | | | `/gallery/?theme=apple&view=list` |
199
+ | Two days | | | `/gallery/?theme=apple&view=days` |
200
+ | Round a view, and an event's own screen | | | navigation pills, a large title and Today: `/gallery/?theme=apple&view=month&layout=stacked&chrome`; an event: `/gallery/?theme=apple&view=event` |
201
+
202
+ Each theme's numbers are measured from the app it copies (pixels of
203
+ screenshots for Apple's, computed styles for Google's), written at the top
204
+ of its stylesheet, and held by a test in `apps/demo/e2e`. The Apple and
205
+ Google themes keep those apps' colours, which do not all meet WCAG contrast.
206
+
207
+ A month's day is marked up the same in every theme: the date in
208
+ `.calendar-date`, and the day's events in the cell's `details` as
209
+ `.calendar-chip` (all day) and `.calendar-timed` (its name, then its time).
210
+ Apple's compact and stacked layouts on a phone take `.calendar-dot` and `.calendar-bar`
211
+ in the day itself.
212
+
213
+ Events that overlap in time share their day's width side by side. Give the
214
+ time grid `laneOverlap={0.7}` and each runs under the next instead, as Google
215
+ Calendar lays them out (the Google theme expects it).
216
+
217
+ Give the time grid `workHours={{ from: 8, to: 18 }}` and lines and hours
218
+ outside them carry `data-off-hours`, which the Apple theme draws lighter.
219
+
220
+ Scrolling is continuous unless you say otherwise. Give the time grid
221
+ `scrollSnap="days"`, `"hours"` or `"both"` and a scroll comes to rest on a
222
+ day's start, on an hour's line, or on both. Give it `scrollLock` and a touch
223
+ scrolls one way at a time: the hours, or the days, whichever the finger first
224
+ goes.
225
+
226
+ ## A calendar from a list of events
227
+
228
+ Keep your events as a list, each with when it starts and ends: `Date`s or
229
+ ISO strings, as your database gives them. `useCalendarView` holds the view
230
+ and the day it is round, and says which days to draw; `groupByDay` puts
231
+ your list into them, in the calendar's time zone; `applyEventChange` puts a
232
+ dragged event back in your list.
233
+
234
+ ```tsx
235
+ const [events, setEvents] = useState([
236
+ { id: "gym", start: "2026-11-23T15:00:00Z", end: "2026-11-23T16:30:00Z" },
237
+ { id: "stay", start: "2026-11-23", end: "2026-11-26" }, // a day alone lasts the day
238
+ ]);
239
+ const { dates, range, title, next, previous, today, view, setView } = useCalendarView();
240
+ const days = groupByDay(events, dates);
241
+
242
+ <TimeGrid.Root days={days} onEventChange={(to) => setEvents((all) => applyEventChange(all, to))}>
243
+ ```
244
+
245
+ Events on a server are the same, loaded for what is shown. `range` is the
246
+ first and last day drawn and changes only when they do, so it keys a query;
247
+ `eventTimes` gives a change as two `Date`s to send back.
248
+
249
+ ```tsx
250
+ const { data: events = [] } = useQuery({ queryKey: ["events", range], queryFn: () => listEvents(range), placeholderData: keepPreviousData });
251
+ const days = groupByDay(events, dates);
252
+
253
+ <TimeGrid.Root days={days} onEventChange={(to) => update.mutate({ id: to.id, ...eventTimes(to) })}>
254
+ ```
255
+
256
+ The list can hold more than is shown: only the days drawn are placed. For
257
+ events that repeat, expand their rules (`rrule`, or ical.js for an .ics
258
+ file) over `range` and pass what you get: the gallery's apps do, behind a
259
+ server of their own.
260
+
261
+ Run `npm run dev` and open `/gallery/?theme=shadcn`: one set of events as a day, a week, a month and a list.
262
+
263
+ ## Themes
264
+
265
+ The parts are unstyled. Three stylesheets dress them, and the markup is the same for each: the difference is a class.
266
+
267
+ ```tsx
268
+ import "calendar-components/apple.css"; // or "calendar-components/google.css"
269
+
270
+ <TimeGrid.Root days={days} className="calendar calendar-apple calendar-week">
271
+ ```
272
+
273
+ An event takes its colour from `--calendar-color`. `base.css` is the layout both share, for a theme of your own.
274
+
275
+ `apple.css` is Apple Calendar for the width it has: Calendar on macOS from 640px, and under that Calendar on iOS, measured from an iPhone (53pt hours, a 62pt gutter, and its event's insets, bar and colours). An hour's height is a prop, so give `hourHeight` by the same query: 37 in a window, 53 on a phone. Open `/gallery/?theme=apple` at either width.
276
+
277
+ | | Apple, in a window | Google | Apple, on a phone |
278
+ |---|---|---|---|
279
+ | Event | a wash of its colour, a bar down the leading edge, 3pt corners | solid colour, white words, 6px corners | a wash you can see the lines through, a round-ended bar |
280
+ | Picked | the colour itself, white words | lifted on a shadow | the colour itself |
281
+ | Today | red filled date | blue filled date | red filled date |
282
+ | Month | `/gallery/?theme=apple&view=month` | `/gallery/?theme=google&view=month` | compact, stacked and details: `/gallery/?theme=apple&view=month&layout=stacked` |
283
+ | List | | | `/gallery/?theme=apple&view=list` |
284
+ | Two days | | | `/gallery/?theme=apple&view=days` |
285
+ | Round a view, and an event's own screen | | | navigation pills, a large title and Today: `/gallery/?theme=apple&view=month&layout=stacked&chrome`; an event: `/gallery/?theme=apple&view=event` |
286
+
287
+ Each theme's numbers are measured from the app it copies (pixels of
288
+ screenshots for Apple's, computed styles for Google's), written at the top
289
+ of its stylesheet, and held by a test in `apps/demo/e2e`. The Apple and
290
+ Google themes keep those apps' colours, which do not all meet WCAG contrast.
291
+
292
+ A month's day is marked up the same in every theme: the date in
293
+ `.calendar-date`, and the day's events in the cell's `details` as
294
+ `.calendar-chip` (all day) and `.calendar-timed` (its name, then its time).
295
+ Apple's compact and stacked layouts on a phone take `.calendar-dot` and `.calendar-bar`
296
+ in the day itself.
297
+
298
+ Events that overlap in time share their day's width side by side. Give the
299
+ time grid `laneOverlap={0.7}` and each runs under the next instead, as Google
300
+ Calendar lays them out (the Google theme expects it).
301
+
302
+ Give the time grid `workHours={{ from: 8, to: 18 }}` and lines and hours
303
+ outside them carry `data-off-hours`, which the Apple theme draws lighter.
304
+
305
+ Scrolling is continuous unless you say otherwise. Give the time grid
306
+ `scrollSnap="days"`, `"hours"` or `"both"` and a scroll comes to rest on a
307
+ day's start, on an hour's line, or on both. Give it `scrollLock` and a touch
308
+ scrolls one way at a time: the hours, or the days, whichever the finger first
309
+ goes.
310
+
311
+ ## A calendar from a list of events
312
+
313
+ Keep your events as a list, each with its day. `useCalendarView` holds the
314
+ view and the day it is round, and says which days to draw; `groupByDay`
315
+ puts your list into them; `applyEventChange` puts a dragged event back in
316
+ your list.
317
+
318
+ ```tsx
319
+ const [events, setEvents] = useState([{ id: "gym", date: "2026-11-23", start: 420, end: 510 }]);
320
+ const { dates, title, next, previous, today, view, setView } = useCalendarView();
321
+ const days = groupByDay(events, dates);
322
+
323
+ <TimeGrid.Root days={days} onEventChange={(to) => setEvents((all) => applyEventChange(all, to))}>
324
+ ```
325
+
326
+ An event with no `start` lasts the day. For events that repeat, expand
327
+ their rules (`rrule`, or ical.js for an .ics file) over `dates` and pass
328
+ what you get: the gallery's apps do.
329
+
330
+ Run `npm run dev`: `/` is the docs site (`apps/demo`, deployed to calendar.brianhung.me with `npm run deploy -w demo`), and `/gallery/` shows every view in every theme, each at its own address (`/gallery/?theme=apple&view=list`).
331
+
332
+ ## Packages
333
+
334
+ | Package | Description |
335
+ |---|---|
336
+ | [`calendar-components`](packages/react) | React parts and hooks |
337
+ | [`calendar-components-core`](packages/core) | State, dates, locale, layout and keyboard movement. Its one dependency is `@internationalized/date`, React Aria's date library |
338
+
339
+ ## Parts
340
+
341
+ | Part | Does | State |
342
+ |---|---|---|
343
+ | `Root` | Holds the hours (the whole day, or the `range` you give), the locale and what is selected | `editable`, `dragging`, `direction` |
344
+ | `Hours`, `Hour` | The hours down the side, and one hour's label at its line | `hour`, `label`, `hourLabel`, `dayPeriodLabel`, `noon`, `offHours` |
345
+ | `DayHeader` | A day's weekday and date, for the eye: hidden from a screen reader, which hears the day from its `Column`. Give it `aria-hidden={false}` if you make it a button or a link | `date`, `today`, `weekend`, `weekdayLabel`, `dayLabel` |
346
+ | `AllDay`, `AllDayEvent` | A day's cell in the all-day row, and an event in it: a button, in the same Tab stop and arrow keys as the timed ones | `date`, `today`, `weekend`; `selected` |
347
+ | `Column` | A day, as tall as the hours | `date`, `today`, `weekend` |
348
+ | `Lines`, `Line` | A line at each hour; a `Line` can sit at any time (9.5 is half past nine) | `hour`, `offHours` |
349
+ | `Events` | Gives each event its lane; overlapping ones share the width | |
350
+ | `Event` | A button, placed by its times: one Tab stop, arrow keys between events, Enter to select; draggable in an editable grid | `selected`, `dragging`, `short`, `tall`, `start`, `end`, `startLabel`, `endLabel`, `lane`, `lanes` |
351
+ | `EventResizeHandle` | The foot of an event, pulled to change when it ends; a slider for the keyboard | |
352
+ | `Now` | A line at the time it is, on today only | `minutes`, `label` |
353
+
354
+ Every event part takes the event the same way: `event` (an object with an `id`, and `start` and `end` where it has times) and a `label`, and gives that same object back in its state.
355
+
356
+ ## Keyboard
357
+
358
+ | Key | Moves to |
359
+ |---|---|
360
+ | Tab | The event focused last, or the first: one stop for the whole grid, all-day events included |
361
+ | ↑ ↓ | The previous or next event that day; ↑ from the first goes to the day's all-day events, ↓ from those comes back |
362
+ | ← → | The event nearest in time on the next day that has one (mirrored right-to-left) |
363
+ | Home, End | The day's first or last event |
364
+ | Enter, Space | Picks the event |
365
+ | Alt + Enter | In an editable grid, picks the event up. Then ↑ ↓ go a step, Page Up and Page Down an hour, ← → a day; Enter drops it and Escape puts it back |
366
+ | Tab, from an event | In an editable grid, goes to the handle at its foot, a slider of when it ends: ↑ ↓ move the end a step |
367
+ | Escape | Puts back an event that is being dragged or carried |
368
+
369
+ ## Drawing it your own way
370
+
371
+ Every part that repeats takes a function and has a part for what it repeats,
372
+ so one piece can be yours without the rest being.
373
+
374
+ ```tsx
375
+ <TimeGrid.Hours>
376
+ {(hour) => (
377
+ <TimeGrid.Hour hour={hour} render={<time />}>
378
+ {({ hourLabel, dayPeriodLabel }) => <>{hourLabel}<span className="calendar-period">{dayPeriodLabel}</span></>}
379
+ </TimeGrid.Hour>
380
+ )}
381
+ </TimeGrid.Hours>
382
+
383
+ <TimeGrid.Lines>{(hour) => <TimeGrid.Line hour={hour + 0.5} className="half-hour" />}</TimeGrid.Lines>
384
+ ```
385
+
386
+ | To draw | Use |
387
+ |---|---|
388
+ | Any part as another element | `render={<article />}`, or `render={(props, state) => …}` |
389
+ | Classes, styles or children from state | pass a function: `className={(state) => …}` |
390
+ | One hour, one line, one event, one weekday, one day | the function child of `Hours`, `Lines`, `Events`, `GridHeader`, `GridBody` |
391
+ | Something of your own on the time axis (travel time, working hours) | `useEventPlacement({ start, end })` for its place in the column |
392
+ | A whole part of your own | `useTimeGrid()`, `useTimeGridColumn()`, `useDateGrid()`, `useDateGridGrid()`, `useAgenda()` for what each knows |
393
+ | A resize handle of your own | `useTimeGridEvent().resizeProps`, on whatever is pulled |
394
+
395
+ ## Scrolling to a time
396
+
397
+ The grid does not scroll itself: it is as tall as its hours, in whatever
398
+ scrolls on your page. Its actions scroll that for you.
399
+
400
+ ```tsx
401
+ const grid = useRef<TimeGrid.Root.Actions>(null);
402
+
403
+ <TimeGrid.Root actionsRef={grid} … />
404
+
405
+ grid.current.scrollToTime("now"); // the time it is, on today when today is shown
406
+ grid.current.scrollToTime({ date: "2026-11-27", minutes: 13 * 60 + 30 }, { behavior: "smooth", block: "center" });
407
+ grid.current.scrollToTime({ minutes: 8 * 60 }, { offset: 48 }); // 8:00, clear of a 48px header that stays put
408
+ grid.current.scrollToEvent("flight"); // an event, which also takes the keyboard
409
+ ```
410
+
411
+ `Agenda.Root` has `actionsRef` too, with `scrollToDay("today")` or a date. A
412
+ `DateGrid` shows the month its `focusedValue` is in, so going to a day there
413
+ is setting it.
414
+
415
+ ## DateGrid
416
+
417
+ A strip of days or a month to choose a day from. Its state is React Stately's
418
+ `useCalendarState` and its behaviour React Aria's `useCalendar`,
419
+ `useCalendarGrid` and `useCalendarCell`: this package adds the parts, the
420
+ `render` and state props, and days as YYYY-MM-DD.
421
+
422
+ ```tsx
423
+ <DateGrid.Root aria-label="Day" visibleDuration={{ weeks: 1 }} value={date} onValueChange={setDate}>
424
+ <DateGrid.Previous /> <DateGrid.Heading /> <DateGrid.Next />
425
+ <DateGrid.Grid>{(date) => <DateGrid.Cell date={date} />}</DateGrid.Grid>
426
+ </DateGrid.Root>
427
+ ```
428
+
429
+ `Grid` with a function child draws its header and body for you. To draw
430
+ those yourself, give it `GridHeader` (a `HeaderCell` per weekday) and
431
+ `GridBody` (a `Cell` per day), as React Aria's calendar is composed.
432
+
433
+ A cell's state: `selected`, `today`, `weekend`, `outsideMonth`, `unavailable`,
434
+ and the interaction states. Its children can be a function of it, for a dot
435
+ under the number.
436
+
437
+ | To | Use |
438
+ |---|---|
439
+ | List a day's events in its cell | `Cell`'s `details`: drawn after the day and outside its button, in an element (`detailsProps`) where the grid's keys and focus stop, so buttons and links there work as they do anywhere |
440
+ | Style, rule or redraw the whole cell | the `<td>` carries the day's state attributes; `wrapperProps` gives it props, with `className`, `style` and `render` as on any part |
441
+ | Draw a week's row yourself | `GridBody`'s `renderWeek`, returning a `DateGrid.Week` |
442
+ | Say which month is shown | `focusedValue` and `onFocusedValueChange` (or `defaultFocusedValue`) |
443
+ | Label a month over its first day | `Heading`'s state: `monthLabel`, `shortMonthLabel`, `startColumn` (also `--date-grid-start-column`) |
444
+
445
+ Every part's attributes are written down beside it (`…DataAttributes.ts`) and exported, as `DateGridCellDataAttributes`.
446
+
447
+ ## Agenda
448
+
449
+ A schedule as a list: a section per day, its events as rows. The list is
450
+ React Aria Components' `GridList`, so the arrow keys, typing to find an
451
+ event, selection and the screen reader are theirs.
452
+
453
+ ```tsx
454
+ <Agenda.Root aria-label="Schedule" value={id} onValueChange={setId}>
455
+ {days.map((day) => (
456
+ <Agenda.Day key={day.date} day={day}>
457
+ <Agenda.DayHeader />
458
+ {day.events.map((event) => (
459
+ <Agenda.Event key={event.id} event={event} label={event.name}>
460
+ {({ startLabel, endLabel }) => <>{event.name} {startLabel}–{endLabel}</>}
461
+ </Agenda.Event>
462
+ ))}
463
+ </Agenda.Day>
464
+ ))}
465
+ </Agenda.Root>
466
+ ```
467
+
468
+ A day knows `today`, `past` and `weekend`; an event with no times is `allDay`.
469
+ A row is read as its name and when it is ("Gym, 7:00 AM to 8:30 AM"), in
470
+ your words with `labels`; `onAction` on an event opens it.
471
+
472
+ ## Moving and resizing
473
+
474
+ Give `Root` an `onEventChange` and events can be dragged to another time or
475
+ day, and resized from a `TimeGrid.EventResizeHandle` at their foot. A drag
476
+ snaps to `step` minutes (15). The events stay yours: the callback says where
477
+ one was put, and you put it there.
478
+
479
+ ```tsx
480
+ <TimeGrid.Root days={days} onEventChange={({ id, date, start, end }, details) => save(id, date, start, end)}>
481
+ ```
482
+
483
+ Moving an event is React Aria's drag and drop for collections: the events are
484
+ the draggable collection, and the times of the days drawn are the droppable
485
+ one. So the keyboard and a screen reader move events as they move rows in
486
+ any React Aria list: Alt+Enter picks the focused event up, the arrows carry
487
+ it from time to time (each said by name: "Drop on Monday, November 23, 9:15
488
+ AM"), Enter drops it and Escape puts it back. The handle at an event's foot
489
+ is a slider of when it ends: Tab from the event comes to it, and ↑ and ↓
490
+ move the end a step (React Aria's `useMove`). Each change is announced. The
491
+ grid has no keys of its own invention.
492
+
493
+ Under a finger an event is picked up by resting on it a moment, as on a
494
+ phone's own calendar: a swipe that starts on an event scrolls the calendar
495
+ as it would anywhere else. The handle at its foot pulls at once.
496
+
497
+ The grid moves focus itself only to follow an event the keyboard has moved,
498
+ and to go to another event when the focused one is taken away. `days` should
499
+ keep its identity while the events are the same (memoise it): every part
500
+ reads it.
501
+
502
+ ## Built on React Aria
503
+
504
+ | For | Hook |
505
+ |---|---|
506
+ | Selecting, by mouse, touch, keyboard or a screen reader's press | `usePress` |
507
+ | Hover that touch never triggers | `useHover` |
508
+ | The events as one Tab stop, with selection and disabled events | `useGridList`, `useListState` |
509
+ | Moving an event, by pointer, keyboard or screen reader | `useDraggableCollection`, `useDroppableCollection`, `useDropIndicator` |
510
+ | Resizing an event | `useMove` |
511
+ | Loading events for the days shown, and a list that goes on | `useAsyncList` |
512
+ | A month's days | `useCalendarState`, `useCalendar` |
513
+ | The focus ring, for the keyboard only | `useFocusRing` |
514
+ | The reader's locale and direction, and finding an event by typing | `useLocale` (set with `I18nProvider`), `useCollator` |
515
+ | Saying what a move did | `announce` |
516
+
517
+ ## Locale
518
+
519
+ Hours, times and days come from `@internationalized/date` (React Aria's date
520
+ library) for the locale given to `Root`, or the nearest `I18nProvider`.
521
+ `timeZone` says whose "today" and "now" the grid shows: a trip's is the trip's. Direction, the week's first day and the
522
+ 12- or 24-hour clock follow it.
523
+
524
+ The few words that are not dates or times ("today", how a time range and a list are
525
+ joined, "all-day") are English's own in English. In any other language they are
526
+ put together from what `Intl` knows of it, so nothing is said in English;
527
+ "all-day" is written in fifteen languages and is English elsewhere. `labels`
528
+ replaces any of them with your own (`labelsFor(locale)` gives the defaults).
529
+
530
+ ## Development
531
+
532
+ ```bash
533
+ npm install
534
+ npm test # the core and the parts, in jsdom
535
+ npm run test:e2e # layout and dragging, in Chromium and WebKit
536
+ npm run build
537
+ ```
538
+
539
+ ## License
540
+
541
+ MIT.