Week and day
Time-grid views with an all-day row, a current-time line, and DST-aware hours.
Try both views in the live demo.
createWeekView and createDayView show the hours of the day down the side and one column per day.
The week view has seven columns, starting on weekRules.firstDay. The day view has one column for
the anchor date. createThreeDayView has three, from the anchor date: on a phone, where a week's
seven columns are too narrow to read, it shows more than a day.
Add them
Add the views to your app with the shadcn CLI, as described in
UI source. The item brings the theme, the shared
calendar parts, and the shadcn components it uses:
npx shadcn@latest add https://time.molten.sh/r/time-grid-view.jsonThen register the views:
import { createDayView, createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
const getEventColor = (meeting: Meeting) => meeting.color;
export const Calendar = createCalendar<Meeting>()({
eventAdapter,
views: [
createWeekView<Meeting>({ dayView: "day", getEventColor }),
createDayView<Meeting>({ getEventColor }),
],
});The views are named week, day and 3-day. Pass your event type, as in
createWeekView<Meeting>, so getEventColor receives your records.
Anatomy
All three views render TimeGridView from registry/time-grid-view, with seven day columns for the
week, three for the 3-day view and one for the day. The view builds these parts itself, so they're
not parts you compose: to change one, edit its file. The tree shows where each part lives.
- Time grid
TimeGridView - Day header
TimeGridHeader - All-day row
TimeGridAllDay - Title
- Time
- Timed event
TimeGridEvent - Resize handle
data-resize="end" - Time gutter
--calendar-gutter-width - Outside working hours
TimeGridAvailability - Now line
useNow - Overlap lanes
TimeGridEventLayout - Day column
TimeGridColumn
TimeGridView time-grid-view.tsx
├── TimeGridHeader time-grid-header.tsx
├── TimeGridAllDay time-grid-all-day.tsx
└── TimeGridBody time-grid-body.tsx, scrolls
├── Time gutter --calendar-gutter-width
│ └── TimeGridZoneHours time-grid-zones.tsx, one per secondary time zone
└── TimeGridColumn time-grid-column.tsx, one per day, data-date
├── TimeGridEvent time-grid-event.tsx
│ ├── Title and time
│ └── Resize handles data-resize="start" and "end"
└── Now line data-slot="time-grid-now"- The gutter is
--calendar-gutter-widthwide:--calendar-hours-widthfor the hours (3rem, or 4rem from thesmbreakpoint), plus--calendar-zone-width(4rem) for each secondary time zone. To change the hours' width, edit--calendar-hours-widthintime-grid-zones.tsx. - An event's
TimeGridEventLayoutsets itstopandheightfrom its times, and itsleftandwidthfrom the overlap layout. A column renders its events in layout order, so a stacked event draws over the ones it overlaps. useNow()moves the now line.
Options
Prop
Type
Set options when you create the view, or per calendar with
viewOptions={{ week: { dayView: "day" } }} on Root.
What it shows
- Header: the weekday and date of each column, with today highlighted and marked
aria-current="date". The corner shows the time zone's offset, such as "GMT+2", after the name of each secondary time zone. - All-day row: all-day events, plus timed and floating events that last 24 hours or more. Busy days collapse to three rows with "+N more", and a chevron in the corner expands the row.
- Hours: labels come from
Intl, so they read "1 PM" or "13:00" depending on the locale. Each hour is--calendar-hour-heighttall (3rem by default). - Events: overlapping events sit side by side, or as
overlapLayoutsets. Events shorter than 45 minutes show on one line, as "Standup, 9:30 AM". Events that run past midnight show their real times on both days, as "10:00 PM – 2:00 AM". A title that doesn't fit its event shows in full in a tooltip while you hover or focus the event. - Daylight saving time: hours skipped when the clocks go forward are hatched, and hours repeated when they go back are tinted, with both occurrences side by side.
- Current time: a line across today's column, from
useNow(). The grid opens scrolled to the current time, or to 08:00 when today isn't visible, and keeps its scroll position when you move between weeks. - Editing: with
onEventChangeonRoot, drag an event to move it (onto the all-day row to make it all-day), drag its top or bottom edge to resize it, and drag across empty time or all-day cells to create one. See Interactions. - Changes being saved: events with a pending change get
data-pendingand render at 60% opacity.
The day view works on narrow screens:
Overlapping events
overlapLayout sets how events that overlap share a day column. Switch between the layouts here,
and drag an event to see the others make room. "Stack focus time" gives the purple focus time
calendar a layout of its own, as by calendar describes:
"columns"(the default) puts overlapping events side by side, in as few lanes as they need. Each event widens into lanes that stay free beside it, as Google Calendar draws them."equal"uses the same lanes, but every event in a busy stretch is one lane wide, so the lanes line up."stack"cascades them. Each event is indented past the earlier events it overlaps and drawn on top of them, reaching to the column's end.stackIndentsets the indent as a fraction of the column width (0.15 by default). A deep stack indents less, so the top event keeps at least half the column. Hover or focus a covered event to bring it to the top and read its title.
createWeekView<Meeting>({ dayView: "day", overlapLayout: "stack" });
// Or switch it at runtime, per view:
<Calendar.Root viewOptions={{ week: { overlapLayout }, day: { overlapLayout } }} />;Every layout keeps the same rules:
- Events that touch, one ending as the next starts, don't overlap. An event shorter than 15 minutes still takes up 15 so it stays readable, so it can overlap the next one.
- Overlapping events form a group, laid out on its own, so a change to one group never moves events in another.
- The order is fixed: by start, then longer first, then event ID. It's the order events are drawn in, and the order ↑ and ↓ walk them. ← and → step to the overlapping event drawn beside, and mirror right to left.
- An event picked up with the keyboard, and changes still being saved, are laid out the same way, so an event lands where it will stay.
The resource columns view takes the same options, for each resource's column, and can give each resource a layout of its own: see rooms and people. The scrolling week and day views take them too.
By calendar
getEventOverlapLayout gives events a layout of their own, usually their calendar's. Return
undefined for events that should follow the view's overlapLayout:
const layouts: Partial<Record<CalendarId, OverlapLayout>> = { focus: "stack" };
createWeekView<Meeting>({
getEventOverlapLayout: (meeting) => layouts[meeting.calendarId],
});One column can hold a group of overlapping events from several calendars, and a group is drawn
one way. So a group takes its events' own layout only when they all agree, and otherwise the
view's overlapLayout. An event without a layout of its own counts as the view's.
- An afternoon of focus time stacks, while a focus block that overlaps a meeting stays in lanes beside it.
- A group's layout depends only on its own events, so an event that overlaps none of them never changes how they're drawn. An event that joins a group from another calendar can switch the group back to the view's layout, as joining a group already redraws it.
- Agreement doesn't depend on order, and
stackIndentis the same for every stacked group. - While an event is being moved or saved,
getEventOverlapLayoutstill gets the event as you stored it, not its new time or resources. Base it on what a move doesn't change, such as the calendar.
Secondary time zones
Pass secondaryTimeZones to Root to label the hours in other time zones too, like Google
Calendar's secondary time zone. Each zone gets a column of hours beside the calendar's own:
<Calendar.Root
timeZone="Europe/Berlin"
secondaryTimeZones={["America/New_York", { timeZone: "Asia/Tokyo", label: "Tokyo" }]}
// …
/>- Names: each column is named by its
label, or by the zone's short name fromIntlin the calendar's locale, such as "EDT" or "GMT+5:30". Without alabel, hover it for the zone's full name. - Hours: each line is read on its own date, in both zones' rules, so the labels stay right when either zone changes its clocks. Zones off the hour show minutes, such as "4:30 PM" in India. "+1" or "-1" marks a time on the next or previous day there.
- Daylight saving time: an hour the calendar's zone skips has no label, and an hour it repeats shows its first time. The gutter follows the first day shown on which neither zone changes its clocks. A day that reads differently, because a zone changes its offset, says so under its date, such as "EST -1h". Hover the note to see from when, and until when if it ends that day.
- Width: each zone's column is
--calendar-zone-widthwide, 4rem by default, which fits "12:30 AM+1". Some locales write longer times; set the variable to a rem or px length on an element around the calendar, such as[--calendar-zone-width:4.5rem]. - Clock: 12 or 24 hours, as the locale says, including a
-u-hc-h23extension. - Screen readers: the extra hours are hidden, like the calendar's own hour labels, so the grid's columns stay the same. A focused slot names its time in each zone instead, as in "Monday, October 12 at 9:00 PM, 3:00 PM Eastern Daylight Time". Each time is named as its zone is at that moment, so the hour repeated in London reads "1:30 AM British Summer Time or 1:30 AM Greenwich Mean Time".
The scrolling week and day views and the resource columns view show the same columns. The parts
live in time-grid-zones.tsx, and Time and time zones
explains how each line is read.
Keyboard
Tab into the preview above, or click a slot, and try these keys. The Accessibility page has the full map and what a screen reader hears.
| Focus | Key | Effect |
|---|---|---|
| An all-day cell | ↓ | First slot of the day |
| A slot | ↑ ↓ | Previous or next 15-minute slot. Up from the first slot reaches the all-day cell |
| A day or slot | ← → | Same slot on the previous or next day |
| A day or slot | Home, End | First or last day shown |
| A day or slot | Page Up, Page Down | Back or forward a whole week (or day) |
| A slot | Enter | The event covering it. Escape goes back to the slot it starts in |
| An all-day cell | Enter | Go into the day's all-day events |
| A timed event | ↑ ↓, ← → | Previous or next event in the column, or the event beside it that overlaps it |
| A day or slot | Shift+Enter | Open that date in the day view, when the week has dayView |
| A slot | Space | Start an hour-long event there. Arrow keys extend it, and Enter saves it |
| An all-day cell | Space | Start an all-day event there |
| An event | Space | Pick it up. Arrow keys move it by slots and days, Enter saves, and Escape cancels |
| An event | Shift+Space | Pick up its end to resize it. Shift+Space again switches to its start |
Moving a picked-up timed event above the first slot makes it all-day, and moving an all-day event below the all-day row makes it timed. Only the focused slot is an element, so a week's 672 slots cost nothing until you visit them.
Markup for interactions
The view connects the pointer layer for you. If you change its markup, keep the attributes the
pointer layer reads: day columns have data-date and cover the full 24 hours, all-day cells have
data-date and data-all-day, each event is a <button> with data-event-id, and events you can
edit have data-resize="start" and data-resize="end" handles.