Views

Week and day

Time-grid views with an all-day row, a current-time line, and DST-aware hours.

Live, in your time zone. Drag to move, resize or create events.

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.json

Then 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.

  1. Time gridTimeGridView
  2. Day headerTimeGridHeader
  3. All-day rowTimeGridAllDay
  4. Title
  5. Time
  6. Timed eventTimeGridEvent
  7. Resize handledata-resize="end"
  8. Time gutter--calendar-gutter-width
  9. Outside working hoursTimeGridAvailability
  10. Now lineuseNow
  11. Overlap lanesTimeGridEventLayout
  12. Day columnTimeGridColumn
Rendered by TimeGridView
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-width wide: --calendar-hours-width for the hours (3rem, or 4rem from the sm breakpoint), plus --calendar-zone-width (4rem) for each secondary time zone. To change the hours' width, edit --calendar-hours-width in time-grid-zones.tsx.
  • An event's TimeGridEventLayout sets its top and height from its times, and its left and width from 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-height tall (3rem by default).
  • Events: overlapping events sit side by side, or as overlapLayout sets. 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 onEventChange on Root, 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-pending and render at 60% opacity.

The day view works on narrow screens:

Live, in your time zone. Drag to move, resize or create events.

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:

Live. Switch the layout, or drag events to see the others make room.
  • "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. stackIndent sets 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 stackIndent is the same for every stacked group.
  • While an event is being moved or saved, getEventOverlapLayout still 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:

Live, in your time zone. Pick the zones, then go to a week when daylight saving time starts or ends in one of them.
<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 from Intl in the calendar's locale, such as "EDT" or "GMT+5:30". Without a label, 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-width wide, 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-h23 extension.
  • 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.

FocusKeyEffect
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 slotHome, EndFirst or last day shown
A day or slotPage Up, Page DownBack or forward a whole week (or day)
A slotEnterThe event covering it. Escape goes back to the slot it starts in
An all-day cellEnterGo 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 slotShift+EnterOpen that date in the day view, when the week has dayView
A slotSpaceStart an hour-long event there. Arrow keys extend it, and Enter saves it
An all-day cellSpaceStart an all-day event there
An eventSpacePick it up. Arrow keys move it by slots and days, Enter saves, and Escape cancels
An eventShift+SpacePick 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.

On this page