# Day & Week View

One day, a week or any number of days on the time grid.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/week-view-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
import { createSampleEvents } from "@/lib/sample-events";

export function WeekViewDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <WeekView scrollToHour={8} />
    </CalendarProvider>
  );
}
```

Day View and Week View are the same time grid with a different number of days: an all-day row on top, an hour grid below. They read the date, events and selection from the surrounding [`CalendarProvider`](/docs/components/calendar-core), so they have almost no props of their own.

## Installation

```bash
npx shadcn@latest add @calendarcn/week-view
```

Or install it by hand:

1. Install the items it builds on: `@calendarcn/time-grid`
2. Copy these files into your project, keeping the paths under your components, hooks and lib folders:
   - [`components/week-view.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view.tsx)

```bash
npx shadcn@latest add @calendarcn/day-view
```

Or install it by hand:

1. Install the items it builds on: `@calendarcn/time-grid`
2. Copy these files into your project, keeping the paths under your components, hooks and lib folders:
   - [`components/day-view.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/day-view.tsx)

## Usage

```tsx
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>
  );
}
```

## 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](/docs/components/calendar-core#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](/docs/components/calendar#keyboard--accessibility).

## Day View

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/day-view-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { DayView } from "@/components/day-view";
import { createSampleEvents } from "@/lib/sample-events";

export function DayViewDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <DayView scrollToHour={8} />
    </CalendarProvider>
  );
}
```

Day View shows a single day on the [Time Grid](#time-grid), with the same drag, resize and create interactions as the week view. Rendered on its own, it sets the provider's view to `"day"`, so prev/next, `T` and the header step by one day.

```tsx
import { CalendarProvider } from "@/components/calendar-provider";
import { DayView } from "@/components/day-view";

export function Today() {
  return (
    <CalendarProvider defaultEvents={events}>
      <div className="h-[600px]">
        <DayView scrollToHour={8} />
      </div>
    </CalendarProvider>
  );
}
```

## Week View

Week View shows several days side by side on the [Time Grid](#time-grid). Show fewer days with the provider's `numberOfDays` (or `defaultNumberOfDays`), as [Three days](#three-days) does. Below 7, the columns start on the current day and previous/next move by that many days.

## Time Grid

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/time-grid-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { TimeGrid } from "@/components/time-grid";
import { createSampleEvents } from "@/lib/sample-events";

export function TimeGridDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      {/* A three-day grid: prev/next step by three days */}
      <TimeGrid view="week" numberOfDays={3} scrollToHour={8} />
    </CalendarProvider>
  );
}
```

The time grid lays out days as columns and hours as rows. Day View and Week View are both built on it, and you can use it directly for a custom layout.

```bash
npx shadcn@latest add @calendarcn/time-grid
```

Or install it by hand:

1. Install the items it builds on: `@calendarcn/calendar-core`, `@calendarcn/event-details`
2. Install the dependencies: `npm install date-fns lucide-react`
3. Add the shadcn/ui components it uses: `npx shadcn@latest add command kbd popover tooltip`
4. Copy these files into your project, keeping the paths under your components, hooks and lib folders:
   - [`components/time-grid.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/time-grid.tsx)
   - [`components/calendar-day-headers.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/calendar-day-headers.tsx)
   - [`components/week-view-all-day-row.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view-all-day-row.tsx)
   - [`components/week-view-grid.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view-grid.tsx)
   - [`components/week-view-time-axis.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view-time-axis.tsx)
   - [`components/week-view-time-indicator.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view-time-indicator.tsx)
   - [`components/week-view-people.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/week-view-people.tsx)
   - [`components/time-zone-axis-label.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/time-zone-axis-label.tsx)
   - [`components/time-zone-list.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/time-zone-list.tsx)
   - [`components/availability-layer.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/availability-layer.tsx)
   - [`hooks/use-all-day-resize.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-all-day-resize.ts)
   - [`hooks/use-event-drag.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-event-drag.ts)
   - [`hooks/use-event-draw.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-event-draw.ts)
   - [`hooks/use-event-resize.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-event-resize.ts)
   - [`hooks/use-horizontal-scroll.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-horizontal-scroll.ts)
   - [`hooks/use-media-query.ts`](https://github.com/vmnog/calendarcn/blob/main/src/hooks/use-media-query.ts)

- A time axis, a column per day and a current-time indicator.
- An all-day row for all-day and multi-day events.
- Overlapping events placed side by side.
- 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, as in Notion Calendar. The all-day row does the same for all-day events. See [Creating events](/docs/components/calendar-core#creating-events).
- Visible hours, snap step and clock come from [`CalendarProvider`](/docs/components/calendar-core#calendarprovider): `dayStartHour`, `dayEndHour`, `snapMinutes` and `hourCycle`.
- Additional time zones' hours beside the time axis, from the provider's [`secondaryTimeZones`](/docs/components/calendar-core#additional-time-zones). Each zone's label opens Notion Calendar's menu for it (change, make primary or secondary, remove), and the "+" left of "All-day" adds one.
- The calendar's own zone, [`timeZone`](/docs/components/calendar-core#time-zone), labels the time axis, and a zone travelled to is filled in the primary color with an x that travels back home.
- The provider's [view settings](/docs/components/calendar-core#view-settings): with weekends hidden the columns are weekdays only, so scrolling, previous and next, and a drag from Friday to the next column all step over the weekend to Monday. Declined events are struck through on a dashed outline, or hidden.
- Other people's events behind yours, hatched in their color, and the free time you share highlighted, while you meet with them or show their calendar: see [Meeting with people](/docs/components/calendar-core#meeting-with-people).
- Hours that fill the screen by default, or the provider's [`hourHeight`](/docs/components/calendar-core#hour-size), which zooming steps through while the middle of the screen stays put.

```tsx
import { CalendarProvider } from "@/components/calendar-provider";
import { TimeGrid } from "@/components/time-grid";

export function ThreeDays() {
  return (
    <CalendarProvider defaultEvents={events}>
      <div className="h-[600px]">
        <TimeGrid view="week" numberOfDays={3} />
      </div>
    </CalendarProvider>
  );
}
```

## Examples

### Three days

`defaultNumberOfDays={3}` on the provider shows three columns that start on today.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/week-view-three-days-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
import { createSampleEvents } from "@/lib/sample-events";

export function WeekViewThreeDaysDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    // Below 7, the columns start on today and previous/next move by that many days
    <CalendarProvider defaultEvents={initialEvents} defaultNumberOfDays={3}>
      {/* The view fills its parent's height */}
      <div className="h-[600px]">
        <WeekView scrollToHour={8} />
      </div>
    </CalendarProvider>
  );
}
```

### Your own toolbar

Week View has no header of its own. Read the month and move between weeks with [`useCalendar()`](/docs/components/calendar-core#usecalendar) from any component inside the provider.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/week-view-toolbar-demo.tsx"
"use client";

import * as React from "react";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
import { Button } from "@/components/ui/button";
import { createSampleEvents } from "@/lib/sample-events";

export function WeekViewToolbarDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <div className="flex h-[600px] flex-col">
        <Toolbar />
        <div className="min-h-0 flex-1">
          <WeekView scrollToHour={8} />
        </div>
      </div>
    </CalendarProvider>
  );
}

/** Any component inside the provider can read the calendar and move it */
function Toolbar() {
  const { monthName, year, goToToday, goToPrev, goToNext } = useCalendar();

  return (
    <header className="flex h-12 shrink-0 items-center gap-1 border-b px-3">
      {/* Follows the week on screen, also while it scrolls sideways */}
      <h2 className="flex-1 truncate text-sm font-semibold">
        {monthName} {year}
      </h2>
      <Button variant="outline" size="sm" onClick={goToToday}>
        Today
      </Button>
      <Button variant="ghost" size="icon" className="size-8" onClick={goToPrev}>
        <ChevronLeftIcon />
        <span className="sr-only">Previous week</span>
      </Button>
      <Button variant="ghost" size="icon" className="size-8" onClick={goToNext}>
        <ChevronRightIcon />
        <span className="sr-only">Next week</span>
      </Button>
    </header>
  );
}
```

### Weekdays only

Hide the weekend with the provider's [view settings](/docs/components/calendar-core#view-settings), and start the week on Monday with `defaultWeekStartsOn`.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/week-view-weekdays-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
import type { WeekStartsOn } from "@/components/calendar-types";
import { createSampleEvents } from "@/lib/sample-events";

/** Weeks start on Monday */
const WEEK_STARTS_ON: WeekStartsOn = 1;

export function WeekViewWeekdaysDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() =>
    createSampleEvents(new Date(), WEEK_STARTS_ON),
  );

  return (
    <CalendarProvider
      defaultEvents={initialEvents}
      defaultWeekStartsOn={WEEK_STARTS_ON}
      // Monday to Friday: scrolling, previous and next step over the weekend
      defaultViewSettings={{ showWeekends: false }}
    >
      <div className="h-[600px]">
        <WeekView scrollToHour={8} />
      </div>
    </CalendarProvider>
  );
}
```

### Details in a side panel

`showEventPopover={false}` turns off the popover, and `useCalendar().selectedEvent` is the event to show in a panel of your own. For the built-in details there, see [Event Details](/docs/components/event-details#the-panel-beside-a-view).

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/week-view-side-panel-demo.tsx"
"use client";

import * as React from "react";
import { format } from "date-fns";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";
import { Button } from "@/components/ui/button";
import type { DetailedCalendarEvent } from "@/components/calendar-types";
import { createSampleEvents } from "@/lib/sample-events";

export function WeekViewSidePanelDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents} defaultNumberOfDays={4}>
      {/* The panel sits beside the view when there's room, below it otherwise */}
      <div className="@container h-[600px]">
        <div className="flex h-full flex-col @lg:flex-row">
          <div className="min-h-0 min-w-0 flex-1">
            {/* No popover beside the event: the panel shows the selection */}
            <WeekView scrollToHour={8} showEventPopover={false} />
          </div>
          <SidePanel />
        </div>
      </div>
    </CalendarProvider>
  );
}

/** The selected event, read from the provider */
function SidePanel() {
  const { selectedEvent, editEvent, deleteEvent, clearSelection } =
    useCalendar<DetailedCalendarEvent>();

  if (!selectedEvent) {
    return (
      <aside className="h-40 shrink-0 border-t p-4 text-sm text-muted-foreground @lg:h-auto @lg:w-56 @lg:border-t-0 @lg:border-l">
        Click an event to see it here.
      </aside>
    );
  }

  return (
    <aside className="flex h-40 shrink-0 flex-col gap-3 border-t p-4 text-sm @lg:h-auto @lg:w-56 @lg:border-t-0 @lg:border-l">
      <input
        aria-label="Title"
        placeholder="Title"
        value={selectedEvent.title}
        // A new event is a draft until its first edit: typing a title saves it
        onChange={(e) => editEvent({ ...selectedEvent, title: e.target.value })}
        className="rounded-sm bg-transparent font-semibold outline-none placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50"
      />
      <p className="text-xs text-muted-foreground tabular-nums">
        {selectedEvent.isAllDay
          ? `${format(selectedEvent.start, "EEE, MMM d")}, all day`
          : `${format(selectedEvent.start, "EEE, MMM d, p")} – ${format(selectedEvent.end, "p")}`}
      </p>
      {selectedEvent.location && (
        <p className="text-xs">{selectedEvent.location}</p>
      )}
      <div className="mt-auto flex gap-2">
        <Button
          variant="outline"
          size="sm"
          onClick={() => deleteEvent(selectedEvent.id)}
        >
          Delete
        </Button>
        <Button variant="ghost" size="sm" onClick={clearSelection}>
          Close
        </Button>
      </div>
    </aside>
  );
}
```

### A week strip

Pick the day for Day View from a strip of your own: `currentDate` is the day on screen and `goToDate()` shows another.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/day-view-week-strip-demo.tsx"
"use client";

import * as React from "react";
import { addDays, format, isSameDay, startOfWeek } from "date-fns";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import { DayView } from "@/components/day-view";
import { Button } from "@/components/ui/button";
import { createSampleEvents } from "@/lib/sample-events";

/** Days in the strip above the view */
const DAYS_PER_WEEK = 7;

export function DayViewWeekStripDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <div className="flex h-[600px] flex-col">
        <WeekStrip />
        <div className="min-h-0 flex-1">
          <DayView scrollToHour={8} />
        </div>
      </div>
    </CalendarProvider>
  );
}

/** The week of the day on screen: click a day to show it */
function WeekStrip() {
  // In day view, `currentDate` is the day shown. It follows sideways scrolling too
  const { currentDate, goToDate } = useCalendar();
  const weekStart = startOfWeek(currentDate);
  const days = Array.from({ length: DAYS_PER_WEEK }, (_, index) =>
    addDays(weekStart, index),
  );

  return (
    <div className="grid shrink-0 grid-cols-7 gap-1 border-b p-2">
      {days.map((day) => (
        <Button
          key={day.getTime()}
          variant={isSameDay(day, currentDate) ? "default" : "ghost"}
          className="h-auto flex-col gap-0 py-1.5"
          onClick={() => goToDate(day)}
        >
          <span className="text-[11px] font-normal opacity-70">
            {format(day, "EEE")}
          </span>
          <span className="text-sm tabular-nums">{format(day, "d")}</span>
        </Button>
      ))}
    </div>
  );
}
```

### 5-minute steps

`snapMinutes` sets the step that drag, resize and new events snap to, and `defaultEventDuration` the length of a double-clicked event.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/day-view-snap-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { DayView } from "@/components/day-view";
import { createSampleEvents } from "@/lib/sample-events";

export function DayViewSnapDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider
      defaultEvents={initialEvents}
      // Drag, resize and new events move in 5-minute steps (15 by default)
      snapMinutes={5}
      // A double-click on an empty slot starts a 20-minute event (30 by default)
      defaultEventDuration={20}
    >
      <div className="h-[600px]">
        <DayView scrollToHour={8} />
      </div>
    </CalendarProvider>
  );
}
```

### All-day events

All-day events sit in a row above the hours, and one that spans several days runs past the edges of the day.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/day-view-all-day-demo.tsx"
"use client";

import * as React from "react";
import { addDays, startOfDay } from "date-fns";

import { CalendarProvider } from "@/components/calendar-provider";
import { DayView } from "@/components/day-view";
import type { CalendarEvent } from "@/components/calendar-types";

/** Today's events: two in the all-day row, two on the hour grid */
function createTodayEvents(): CalendarEvent[] {
  const today = startOfDay(new Date());
  const at = (hour: number, minute = 0) =>
    new Date(
      today.getFullYear(),
      today.getMonth(),
      today.getDate(),
      hour,
      minute,
    );

  return [
    // An all-day event ends on its last day: one day has `start` equal to `end`
    {
      id: "holiday",
      title: "Public holiday",
      start: today,
      end: today,
      isAllDay: true,
      color: "green",
    },
    // Yesterday to tomorrow: the bar runs past both edges of the day
    {
      id: "conference",
      title: "Design conference",
      start: addDays(today, -1),
      end: addDays(today, 1),
      isAllDay: true,
      color: "purple",
    },
    {
      id: "keynote",
      title: "Keynote",
      start: at(9),
      end: at(10),
      color: "blue",
    },
    {
      id: "workshop",
      title: "Workshop",
      start: at(10, 30),
      end: at(12),
      color: "orange",
    },
  ];
}

export function DayViewAllDayDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(createTodayEvents);

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <div className="h-[600px]">
        <DayView scrollToHour={8} />
      </div>
    </CalendarProvider>
  );
}
```

### Day and week in one grid

Use one `TimeGrid` under a header of your own and switch its `view`: the grid lays out again instead of remounting, so it keeps its scroll position.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/time-grid-day-week-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import { TimeGrid } from "@/components/time-grid";
import { Button } from "@/components/ui/button";
import { createSampleEvents } from "@/lib/sample-events";

export function TimeGridDayWeekDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents}>
      <div className="flex h-[600px] flex-col">
        <DayWeekGrid />
      </div>
    </CalendarProvider>
  );
}

/** Your own header over one grid that shows a day or a week */
function DayWeekGrid() {
  const { view, switchView, monthName, year } = useCalendar();
  // The provider's view can be any of five: the grid draws two of them
  const gridView = view === "day" ? "day" : "week";

  return (
    <>
      <header className="flex h-12 shrink-0 items-center gap-1 border-b px-3">
        <h2 className="flex-1 truncate text-sm font-semibold">
          {monthName} {year}
        </h2>
        <Button
          variant={gridView === "day" ? "secondary" : "ghost"}
          size="sm"
          onClick={() => switchView("day")}
        >
          Day
        </Button>
        <Button
          variant={gridView === "week" ? "secondary" : "ghost"}
          size="sm"
          onClick={() => switchView("week")}
        >
          Week
        </Button>
      </header>
      <div className="min-h-0 flex-1">
        {/* One grid for both, so switching keeps the scroll position */}
        <TimeGrid view={gridView} scrollToHour={8} />
      </div>
    </>
  );
}
```

### Working hours only

`dayStartHour` and `dayEndHour` on the provider set the hours the grid shows.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/time-grid-visible-hours-demo.tsx"
"use client";

import * as React from "react";

import { CalendarProvider } from "@/components/calendar-provider";
import { TimeGrid } from "@/components/time-grid";
import { createSampleEvents } from "@/lib/sample-events";

export function TimeGridVisibleHoursDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider
      defaultEvents={initialEvents}
      // The grid runs from 8 AM to 6 PM. Events outside it are clipped at the
      // edge, or hidden, and drag, resize and new events stay inside
      dayStartHour={8}
      dayEndHour={18}
    >
      <div className="h-[600px]">
        <TimeGrid view="week" />
      </div>
    </CalendarProvider>
  );
}
```

### Zoom the hours

The [hour size](/docs/components/calendar-core#hour-size) lives in the provider: `zoomHoursIn()`, `zoomHoursOut()` and `resetHourHeight()` change it from your own buttons.

Live example, interactive at https://calendarcn.xyz/docs/components/day-week-view. Its source:

```tsx title="src/examples/time-grid-zoom-demo.tsx"
"use client";

import * as React from "react";
import { ZoomInIcon, ZoomOutIcon } from "lucide-react";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import { TimeGrid } from "@/components/time-grid";
import { Button } from "@/components/ui/button";
import { createSampleEvents } from "@/lib/sample-events";

export function TimeGridZoomDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents} defaultNumberOfDays={5}>
      <div className="flex h-[600px] flex-col">
        <ZoomControls />
        <div className="min-h-0 flex-1">
          <TimeGrid view="week" scrollToHour={8} />
        </div>
      </div>
    </CalendarProvider>
  );
}

/** The hour size lives in the provider, so any control can change it */
function ZoomControls() {
  // `hourHeight` is `null` while the hours fill the grid, the default
  const { hourHeight, zoomHoursIn, zoomHoursOut, resetHourHeight } =
    useCalendar();

  return (
    <div className="flex h-12 shrink-0 items-center gap-1 border-b px-3">
      <p className="min-w-0 flex-1 truncate text-sm text-muted-foreground tabular-nums">
        {hourHeight === null
          ? "Hours fill the grid"
          : `${hourHeight}px an hour`}
      </p>
      <Button
        variant="ghost"
        size="icon"
        className="size-8"
        onClick={zoomHoursOut}
      >
        <ZoomOutIcon />
        <span className="sr-only">Zoom hours out</span>
      </Button>
      <Button
        variant="ghost"
        size="icon"
        className="size-8"
        onClick={zoomHoursIn}
      >
        <ZoomInIcon />
        <span className="sr-only">Zoom hours in</span>
      </Button>
      <Button
        variant="outline"
        size="sm"
        disabled={hourHeight === null}
        onClick={resetHourHeight}
      >
        Reset
      </Button>
    </div>
  );
}
```

## API Reference

### WeekView

Everything else (date, events, number of days, hours, clock, locale) is set on [`CalendarProvider`](/docs/components/calendar-core#calendarprovider).

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `numberOfDays` | `number` | – | Number 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. |
| `showEventPopover` | `boolean` | `true` | Whether the selected event opens a details popover beside it. Turn it off when the details are shown elsewhere, such as a side panel. |
| `onEventPopoverExpand` | `() => void` | – | Called 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. |
| `scrollToHour` | `number` | – | Hour 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. |
| `className` | `string` | – | Classes for the root element. |

### DayView

Everything else (date, events, hours, clock, locale) is set on [`CalendarProvider`](/docs/components/calendar-core#calendarprovider).

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `showEventPopover` | `boolean` | `true` | Whether the selected event opens a details popover beside it. Turn it off when the details are shown elsewhere, such as a side panel. |
| `onEventPopoverExpand` | `() => void` | – | Called 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. |
| `scrollToHour` | `number` | – | Hour 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. |
| `className` | `string` | – | Classes for the root element. |

### TimeGrid

Use it directly when you switch between day and week yourself and want to keep the scroll position, as the [demo](/) does. Everything else is set on [`CalendarProvider`](/docs/components/calendar-core#calendarprovider).

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `view` (required) | `"day" \| "week"` | – | "day" shows one column, "week" shows `numberOfDays` columns. While the provider's `view` is uncontrolled, the provider adopts it, so navigation and header info follow it. |
| `numberOfDays` | `number` | – | Number 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. |
| `showEventPopover` | `boolean` | `true` | Whether the selected event opens a details popover beside it. Turn it off when the details are shown elsewhere, such as a side panel. |
| `onEventPopoverExpand` | `() => void` | – | Called 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. |
| `scrollToHour` | `number` | – | Hour 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. |
| `className` | `string` | – | Classes for the root element. |
