# Calendar View

> A full calendar: day, week, month and agenda, for several calendars at once.

Component · Data · Pro kit · [Live page](https://ui.twentyfirst.media/pro/components/CalendarView/)

A full calendar: day, week, month and agenda, for several calendars at once.

- **Calendars**: each with a tint and a visibility toggle (`hidden`/`onHiddenChange`); `readOnly` calendars such as public holidays show without reply or actions.
- **Day and week**: an all-day row, hours from `hours` (widened to fit the events), overlapping events side by side and a line at the current time.
- **Creating**: click an empty slot (an hour), drag over a range (snapped to 15 minutes) or press Enter on a focused slot; `onCreate` gets `{ start, end, allDay }`. Arrow keys move between slots and days, Home/End to the first and last hour.
- **Details**: a popover next to the event on desktop and a sheet from the bottom on phones, with place, calendar, description, guests and their replies, "Going?" (`onRsvp`) and your own buttons (`eventActions`).
- **Phones**: under 640 px a week or month shows as a list of days (the agenda).
- **Controlled**: `view`, `date`, `selected`, `hidden`; `onRangeChange` reports the visible range (also on mount) so you can load its events.
- Weekday and month names, times and ranges come from `Intl` in the provider's locale; `weekStartsOn={0}` starts weeks on Sunday.

## Example

```tsx
import * as React from "react";
import { Button, CalendarView, toast } from "@twentyfirstmedia/pro";
import type { CalendarEvent } from "@twentyfirstmedia/pro";
import { CALENDARS, EVENTS, NOW } from "./_calendar";

export default function Preview() {
  const [events, setEvents] = React.useState<CalendarEvent[]>(EVENTS);
  return (
    <div className="tf-panel" style={{ gap: 0 }}>
      <CalendarView
        events={events}
        calendars={CALENDARS}
        now={NOW}
        defaultDate={NOW}
        onCreate={(slot) =>
          setEvents((list) =>
            list.concat([
              {
                id: "new-" + list.length,
                title: "New event",
                start: slot.start,
                end: slot.end,
                calendar: "work",
              },
            ]),
          )
        }
        onRsvp={(ev, rsvp) =>
          setEvents((list) => list.map((e) => (e.id === ev.id ? { ...e, rsvp } : e)))
        }
        eventActions={(ev) => (
          <>
            <Button
              size="sm"
              variant="secondary"
              icon="edit"
              onClick={() => toast("Opened " + ev.title)}
            >
              Edit
            </Button>
            <Button
              size="sm"
              variant="ghost"
              icon="trash"
              onClick={() => setEvents((list) => list.filter((e) => e.id !== ev.id))}
            >
              Delete
            </Button>
          </>
        )}
        toolbar={
          <Button size="sm" icon="plus">
            New event
          </Button>
        }
      />
    </div>
  );
}
```

## Props

### CalendarView

| Prop | Type | Notes |
| --- | --- | --- |
| `events` | `CalendarEvent[]` | Required |
| `calendars?` | `CalendarDef[]` | Calendars with colour and a visibility toggle each. |
| `hidden?` | `string[]` | Ids of hidden calendars (controlled) / initially hidden / on toggle. |
| `defaultHidden?` | `string[]` |  |
| `onHiddenChange?` | `(ids: string[]) => void` |  |
| `view?` | `CalendarViewMode` | Day, week, month or agenda (default week). On phones a week or month shows as a list. |
| `defaultView?` | `CalendarViewMode` |  |
| `onViewChange?` | `(view: CalendarViewMode) => void` |  |
| `date?` | `Date` | The day the view shows (controlled) / initially (default today). |
| `defaultDate?` | `Date` |  |
| `onDateChange?` | `(date: Date) => void` |  |
| `onRangeChange?` | `(range: { start: Date; end: Date; view: CalendarViewMode }) => void` | The visible range changed (also on mount): load its events. `end` is exclusive. |
| `views?` | `CalendarViewMode[]` | The views offered in the switcher (default all four). |
| `onCreate?` | `(slot: { start: Date; end: Date; allDay: boolean }) => void` | Click or drag on an empty slot (or Enter on a focused slot): the new event's time. |
| `selected?` | `string \| null` | The event whose details are open (controlled) / initially / on open and close. |
| `defaultSelected?` | `string \| null` |  |
| `onSelectedChange?` | `(id: string \| null) => void` |  |
| `onOpenEvent?` | `(event: CalendarEvent) => void` | Called when an event's details open. |
| `onRsvp?` | `(event: CalendarEvent, rsvp: CalendarRsvp) => void` | Your answer from the details (Yes, Maybe, No) for events with `rsvp`. |
| `eventActions?` | `(event: CalendarEvent) => ReactNode` | Buttons at the bottom of the details (Edit, Delete, Open). |
| `hours?` | `[number, number]` | First and last hour of the day and week grid (default 7 to 21; widened to fit events). |
| `weekStartsOn?` | `0 \| 1` | 1 = Monday (default), 0 = Sunday. |
| `maxPerDay?` | `number` | Most events per day in the month (default 3, then "+2 more"). |
| `title?` | `string` | Heading instead of the date range. |
| `toolbar?` | `ReactNode` | More controls at the end of the toolbar (a "New event" button). |
| `now?` | `Date \| string \| number` | What counts as now (default the clock), for stable tests and server rendering. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
