# Day View

One day on the time grid.

Live example, interactive at https://calendarcn.xyz/docs/components/day-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](/docs/components/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.

## Installation

```bash
npx shadcn 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 { DayView } from "@/components/day-view";

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

## API Reference

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