# Views

> The month, week, day, N-day, agenda and year views, the toolbar, navigation from code, the time grid settings and business hours.

The calendar has six views. They share the same events, toolbar and keyboard model, and you can switch between them at any time without recreating the calendar.

**Live demo: Team calendar with recurring meetings** (runs on the HTML version of this page). Source of `demos/calendar-basic.ts`. Imports from `./_shared` and `./_scheduler-data` are sample data and small UI helpers used only by the docs.

```ts
import { createCalendar, type CalendarEvent, type ViewType } from '@birchui/calendar';
import { docsTheme, field, layout, onDocsThemeChange } from './_shared';

export const meta = { title: 'Team calendar with recurring meetings', height: 560 };

interface TeamEvent extends CalendarEvent {
  location?: string;
}

const VIEWS: ViewType[] = ['month', 'week', 'day', 'agenda', 'year'];

function at(day: number, hour: number, minute = 0): Date {
  return new Date(2026, 10, day, hour, minute);
}

function teamEvents(): TeamEvent[] {
  return [
    {
      id: 'standup',
      title: 'Service desk stand-up',
      start: at(2, 9),
      end: at(2, 9, 15),
      rrule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
      exdates: [at(26, 9)],
      color: '#2563eb',
      location: 'Room 2B',
    },
    {
      id: 'planning',
      title: 'Sprint planning',
      start: at(3, 14),
      end: at(3, 15, 30),
      rrule: 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU',
      color: '#7c3aed',
    },
    {
      id: 'maintenance',
      title: 'Database maintenance window',
      start: at(28, 22),
      end: at(29, 2),
      color: '#b45309',
    },
    { id: 'visit-1', title: 'Site visit: Kestrel Logistics', start: at(10, 10), end: at(10, 12, 30), color: '#0f766e' },
    { id: 'visit-2', title: 'Site visit: Oakridge Clinics', start: at(18, 13), end: at(18, 16), color: '#0f766e' },
    { id: 'review', title: 'Quarterly business review', start: at(20, 11), end: at(20, 12), color: '#be123c' },
    {
      id: 'holiday',
      title: 'Thanksgiving (office closed)',
      start: at(26, 0),
      end: at(28, 0),
      allDay: true,
      color: '#475569',
    },
  ];
}

export default function mount(el: HTMLElement): () => void {
  const { toolbar, body, status } = layout(el);
  const view = document.createElement('select');
  for (const name of VIEWS) view.add(new Option(name, name, name === 'month', name === 'month'));
  toolbar.append(
    field('View', view),
    'Drag or resize an event. Recurring meetings move one occurrence unless you hold Shift.',
  );

  const calendar = createCalendar<TeamEvent>(body, {
    events: teamEvents(),
    view: 'month',
    date: at(17, 9),
    firstDay: 1,
    selectable: true,
    businessHours: { daysOfWeek: [1, 2, 3, 4, 5], startTime: '08:00', endTime: '18:00' },
    theme: docsTheme(),
  });

  const onView = () => calendar.setView(view.value as ViewType);
  view.addEventListener('change', onView);
  let shiftHeld = false;
  const trackShift = (event: KeyboardEvent) => {
    shiftHeld = event.shiftKey;
  };
  document.addEventListener('keydown', trackShift);
  document.addEventListener('keyup', trackShift);

  const time = (d: Date) =>
    d.toLocaleString('en-US', { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
  const offs = [
    calendar.on('eventClick', ({ event, occurrence }) => {
      status.textContent = `${event.title}, ${time(occurrence.start)}${event.location ? ` in ${event.location}` : ''}`;
    }),
    calendar.on('eventDrop', (change) => {
      if (change.isRecurring && shiftHeld) change.scope = 'all';
      status.textContent = `${change.event.title} moved to ${time(change.start)} (${change.isRecurring ? `scope: ${change.scope}` : 'single event'})`;
    }),
    calendar.on('eventResize', (change) => {
      status.textContent = `${change.event.title} now ends ${time(change.end)}`;
    }),
    calendar.on('viewChange', ({ view: next }) => {
      view.value = next;
    }),
  ];
  status.textContent = 'Click an event for details.';
  const stopTheme = onDocsThemeChange((theme) => calendar.update({ theme }));
  return () => {
    view.removeEventListener('change', onView);
    document.removeEventListener('keydown', trackShift);
    document.removeEventListener('keyup', trackShift);
    for (const off of offs) off();
    stopTheme();
    calendar.destroy();
  };
}
```

## The six views

| View | Shows | Range |
| --- | --- | --- |
| `'month'` | A grid of whole weeks with all-day and timed events as bars and dots, and "+N more" for busy days. | The weeks that contain the current month. |
| `'week'` | A time grid with one column per day and an all-day row above it. | One week, starting on `firstDay`. |
| `'day'` | The same time grid for a single day. | One day. |
| `'days'` | A time grid for `dayCount` days (default 4, up to 31). | `dayCount` visible days from the current date. |
| `'agenda'` | A list of events grouped by day. | `agendaDays` days from the current date, or the current month when `agendaDays` is not set. |
| `'year'` | Twelve mini months with a dot per day that has events. | The calendar year. |

Pick the initial view with `view`, and the views offered by the toolbar's switcher with `views`. By default the switcher shows `'month'`, `'week'`, `'day'`, `'agenda'` and `'year'`; add `'days'` yourself:

```ts
import { createCalendar } from '@birchui/calendar';

const calendar = createCalendar(container, {
  view: 'week',
  views: ['month', 'week', 'days', 'agenda'],
  dayCount: 3,
  date: '2026-12-07',
  events,
});
```

`view` does not have to be one of `views`; the switcher simply shows no active button then. A misspelled view name logs a warning and falls back to the first entry of `views`.

### Month

Each day lists up to `maxEventsPerDay` events (default 4). All-day and multi-day events are drawn as bars across cells, packed into lanes so they do not overlap; single-day timed events are drawn as a dot with their start time. The rest go behind a "+N more" button that opens a popover with every event of that day.

To show your own list instead of the built-in popover, call `preventDefault()` in `moreClick`:

```ts
calendar.on('moreClick', ({ date, occurrences, hiddenCount, preventDefault }) => {
  preventDefault();
  dayDrawer.open({ date, items: occurrences, hiddenCount });
});
```

Clicking a day number opens that day in the `'day'` view. Set `navLinks: false` to turn that off.

### Week, day and N days

The time grid has an all-day row on top and a scrolling grid of time slots below. Overlapping timed events are laid out side by side. Timed events of 24 hours or more appear in the all-day row, and an event that runs past midnight is split into one piece per day column.

| Option | Default | Description |
| --- | --- | --- |
| `slotMinutes` | `30` | Length of one grid slot, from 5 to 120 minutes. It must divide a day evenly. |
| `slotHeight` | `24` | Height of one slot in pixels (at least 8). |
| `snapMinutes` | `15` | Step for dragging, resizing and selecting, never more than `slotMinutes` by default. |
| `dayStartHour`, `dayEndHour` | `0`, `24` | The hours the grid shows. Events are clipped to this window. |
| `scrollToHour` | `8` | The hour scrolled into view when the grid opens. |
| `nowIndicator` | `true` | A line at the current time in today's column. |
| `hour12` | from `locale` | Force a 12-hour or 24-hour clock in the time axis and event times. |

A clinic day view in 15-minute slots from 07:00 to 20:00:

```ts
createCalendar(container, {
  view: 'day',
  timeZone: 'Europe/London',
  locale: 'en-GB',
  height: 720,
  slotMinutes: 15,
  dayStartHour: 7,
  dayEndHour: 20,
  scrollToHour: 8,
  events: appointments,
});
```

### Agenda

The agenda lists events day by day, which works well on narrow screens and for screen-reader users. It covers the current month by default; set `agendaDays` for a rolling window, for example the next 14 days:

```ts
calendar.update({ view: 'agenda', agendaDays: 14 });
```

When there is nothing to show, the agenda displays the `noEvents` label. Long lists are virtualized, so a year of events scrolls smoothly.

### Year

The year view shows twelve months with a dot per busy day, colored by the day's events. Clicking a day emits `dateClick` and, while `navLinks` is on, opens that day in the day view. Clicking a month name opens the month view, also only with `navLinks`.

## Weeks, weekends and hidden days

| Option | Default | Description |
| --- | --- | --- |
| `firstDay` | from `locale` | First day of the week, `0` for Sunday through `6` for Saturday. Without it the calendar uses the locale's week information, so `en-US` starts on Sunday and `en-GB` on Monday. |
| `weekends` | `true` | `false` hides Saturday and Sunday in every view. |
| `hiddenDays` | `[]` | Weekdays to hide, such as `[0]` for a six-day week. |

```ts
createCalendar(container, { view: 'week', weekends: false, events: officeEvents });
```

Hiding every day is not possible: the calendar warns and shows all days instead.

## Business hours

`businessHours` shades the time outside working hours in the time grid, and days with no business window get the `--non-business` modifier class (for example `lq-cal-day--non-business`) in the month, week and year views. It accepts:

- `true`, for Monday to Friday, 09:00 to 17:00;
- one window, `{ daysOfWeek, startTime, endTime }`, where `daysOfWeek` defaults to Monday to Friday and the times are `'HH:mm'` strings defaulting to `'09:00'` and `'17:00'`;
- a list of windows, for days with different hours.

```ts
createCalendar(container, {
  view: 'week',
  businessHours: [
    { daysOfWeek: [1, 2, 3, 4, 5], startTime: '08:00', endTime: '18:30' },
    { daysOfWeek: [6], startTime: '09:00', endTime: '12:00' },
  ],
  events: appointments,
});
```

Business hours are visual only. To stop people booking outside them, check the times in [`validateDrop`](https://docs.birchui.com/calendar/interactions.md#validation).

## The toolbar

The default toolbar has previous and next buttons with a "Today" button on the left, the title in the middle and the view switcher on the right. The "Today" button is disabled while today is already visible, and the title doubles as a live region that announces the new period.

Rearrange it with `headerToolbar`. Each of `start`, `center` and `end` is a list of tokens: a space separates groups, a comma joins buttons into one group.

| Token | Renders |
| --- | --- |
| `prev`, `next` | Arrow buttons for the previous and next period. |
| `today` | A button that jumps to today. |
| `title` | The period title, such as "December 2026", plus the loading indicator. |
| `views` | The view switcher, when `viewSwitcher` is on and `views` has more than one entry. |

```ts
createCalendar(container, {
  headerToolbar: { start: 'title', center: '', end: 'today prev,next views' },
  events,
});
```

Turn the toolbar off with `headerToolbar: false` and drive the calendar from your own controls, or keep the toolbar and hide only the switcher with `viewSwitcher: false`.

Every visible string can be translated or reworded through `labels`:

```ts
createCalendar(container, {
  locale: 'de-DE',
  labels: {
    today: 'Heute',
    previous: 'Zurück',
    next: 'Weiter',
    allDay: 'Ganztägig',
    noEvents: 'Keine Termine',
    recurring: 'Wiederholt sich',
    close: 'Schließen',
    loading: 'Termine werden geladen',
    views: { month: 'Monat', week: 'Woche', day: 'Tag', days: 'Mehrere Tage', agenda: 'Liste', year: 'Jahr' },
    more: (count) => `+${count} weitere`,
    eventCount: (count) => (count === 1 ? '1 Termin' : `${count} Termine`),
  },
  events,
});
```

Dates, weekday names and times come from `Intl` in the chosen `locale`, so only these labels need translating.

## Navigating from code

| Method | Description |
| --- | --- |
| `setView(view, date?)` | Switch view, optionally jumping to a date. |
| `getView()` | The current view. |
| `gotoDate(date)` | Show the period that contains `date`. |
| `getDate()` | The current date the view is anchored on. |
| `next()`, `prev()` | Move by one period: a month, a week, a day, `dayCount` days, `agendaDays` (or a month) or a year. |
| `today()` | Jump to today. |
| `getRange()` | `{ start, end }` of the visible range as `Date`s, `end` exclusive. |
| `getTitle()` | The title the toolbar shows, for your own header. |

```ts
document.querySelector('#jump-to-quarter')!.addEventListener('click', () => {
  calendar.setView('month', '2027-01-01');
});

calendar.on('viewChange', ({ view, previousView }) => {
  localStorage.setItem('calendar-view', view);
});

calendar.on('rangeChange', ({ start, end, view }) => {
  pageHeading.textContent = calendar.getTitle();
});
```

`viewChange` fires when the view type changes and `rangeChange` whenever the visible range changes, including after `next()`, `prev()`, `today()` and `gotoDate()`. The initial range is reported once by `ready`, not by `rangeChange`.

## Customizing cells and events

`eventRenderer(occurrence, context)` and `dayCellRenderer(context)` return the content for event elements and day cells. Return a DOM `Node` for structured content, a string for plain text (strings are inserted as text, never as HTML), or `null` to keep the default. If a renderer throws, the error is logged and the default content is used.

```ts
createCalendar(container, {
  events,
  eventRenderer: (occurrence, { view, timeText }) => {
    if (view === 'month') return null;
    const wrapper = document.createElement('div');
    const title = document.createElement('strong');
    title.textContent = occurrence.title;
    const meta = document.createElement('span');
    meta.textContent = [timeText, occurrence.event.location].filter(Boolean).join(', ');
    wrapper.append(title, meta);
    return wrapper;
  },
  dayCellRenderer: ({ dateKey, isOtherMonth }) => (holidayNames[dateKey] && !isOtherMonth ? holidayNames[dateKey] : null),
});
```

`EventRenderContext` has `view`, `timeText`, `isStart` and `isEnd` (false on the continuation of a multi-day bar) and `isMirror` (true for the drag preview). `DayCellContext` has `date`, `dateKey` (`'2026-12-25'`), `view`, `isToday`, `isOtherMonth` and `eventCount`. Use `dateKey` to look up per-day data.

## Theming

`theme` is `'light'` (default), `'dark'` or `'auto'`, which follows `prefers-color-scheme` and switches live. Colors, fonts and radii come from the shared `--lq-*` custom properties, with calendar-specific tokens such as `--lq-cal-now`, `--lq-cal-nonbusiness`, `--lq-cal-today-bg` and `--lq-cal-shadow`. An event's `color` sets `--lq-cal-event-color` on its element, and the text color is chosen automatically for contrast. See the shared [theming guide](https://docs.birchui.com/grid/theming.md).

## Next steps

- [Recurrence](https://docs.birchui.com/calendar/recurrence.md) for repeating events.
- [Interactions](https://docs.birchui.com/calendar/interactions.md) for drag, resize and select.
- [API and events](https://docs.birchui.com/calendar/api.md) for every option.
