Components
Week View
A week, or any number of days, on the time grid.
Week View shows several days side by side on the Time Grid: an all-day row on top, an hour grid below. It reads the date, events and selection from the surrounding CalendarProvider, so it has almost no props of its own.
Installation
pnpm dlx shadcn add @calendarcn/week-viewUsage
import { CalendarProvider } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
export function Schedule() {
return (
<CalendarProvider defaultEvents={events}>
{/* Week View fills its parent's height */}
<div className="h-[600px]">
<WeekView scrollToHour={8} />
</div>
</CalendarProvider>
);
}Show fewer days with the provider's numberOfDays (or defaultNumberOfDays). Below 7, the columns start on the current day and previous/next move by that many days.
<CalendarProvider defaultEvents={events} defaultNumberOfDays={3}>
<WeekView />
</CalendarProvider>Features
- Drag an event to move it, including to another day. The grid scrolls when you reach its edge.
- Drag the top or bottom edge of an event to resize it.
- Double-click an empty slot to create an event, or press and drag to draw one, then type its title. Do the same in the all-day row for an all-day event. See Creating events.
- Click an event to open its details in a popover. Right-click it to change its color or calendar.
- Overlapping events sit side by side. All-day and multi-day events sit in the all-day row.
- Scroll sideways to move through days. Scrolling snaps to the nearest day.
- Touch: long-press an event to drag it, or empty space to create one.
- Move and resize from the keyboard. See Keyboard & accessibility.
API Reference
WeekView
Everything else (date, events, number of days, hours, clock, locale) is set on CalendarProvider.
| Prop | Type | Default |
|---|---|---|
numberOfDaysNumber of day columns. Defaults to the provider's numberOfDays. When set, it fixes the column count, and prev/next step by it below 7 while the provider's numberOfDays is uncontrolled. | number | – |
showEventPopoverWhether the selected event opens a details popover beside it. Turn it off when the details are shown elsewhere, such as a side panel. | boolean | true |
onEventPopoverExpandCalled by the popover's expand button, e.g. to move the details into a side panel. The button is hidden when this is not set. | () => void | – |
scrollToHourHour the grid scrolls to when it mounts, e.g. 8 for 8 AM or 8.5 for 8:30. Applied once and clamped to the provider's dayStartHour..dayEndHour. Unset starts at the top. | number | – |
classNameClasses for the root element. | string | – |