Views

Overview

How views work, how to register and switch them, the registry's week and day, month, year and agenda, their scrolling versions, the resource columns and the resource timeline, and the engine's layouts a view draws.

A view decides which dates are visible and how to draw them. A calendar can have several views, for example an agenda and a month grid. The view state names the active one, and <Calendar.ActiveView /> renders it.

A view is a strategy and a Renderer. The strategy picks the dates and lays out the events, and the Renderer is a Solid component that draws that layout. The registry has styled views for the week, the day, the month, the year and the agenda, each but the year also as a scrolling view, the resource columns and the resource timeline, with a toolbar, a mini month and the controls they're built from. You add them to your app as source, every one at once with calendar-full, and you write any other view.

The engine's layouts

You rarely compute a layout yourself. @moltenship/calendar-solid exports the range, the title, the navigation step and the projection of each common layout, and your Renderer draws the projection.

LayoutFunctions
AgendagetListRange, navigateList, getListTitle, projectList, listSpatialNavigation
Month gridgetMonthRange, navigateMonth, getMonthTitle, projectMonth, monthSpatialNavigation
YeargetYearRange, navigateYear, getYearTitle, projectYear, yearSpatialNavigation
Week and daytimeGridStrategy({ kind }), a whole strategy, and timeGridSpatialNavigation
Resource columnsresourceColumnsStrategy, and resourceColumnsSpatialNavigation
Resource timelineresourceTimelineStrategy, and resourceTimelineSpatialNavigation
ScrollingscrollingTimeGridStrategy, scrollingMonthStrategy, scrollingListStrategy

The Quick start draws the agenda's projection, and Keyboard in your own views the month grid's.

Registering views

Pass views to createCalendar. The first one is active by default unless you set defaultView or view on Root. TypeScript learns the view names from this list, so setView and defaultView only accept names you registered.

team-calendar.ts
import { createCalendar } from "@moltenship/calendar-solid";

import { eventAdapter, listView, type Meeting } from "./calendar";
import { monthView } from "./month";

// The first view is the one a calendar opens in.
export const TeamCalendar = createCalendar<Meeting>()({
  eventAdapter,
  views: [listView, monthView],
});

export type TeamView = (typeof TeamCalendar.views)[number]["name"]; // "list" | "month"

Each name must be unique. createCalendar throws calendar-duplicate-view-name if two views share one.

View options

A view can declare defaultOptions. Override them per calendar with viewOptions on Root, keyed by view name. Each entry is typed from that view's defaultOptions, and you only pass the fields you want to change. For example, viewOptions={{ list: { weeks: 4 } }} makes the Quick start's agenda show four weeks instead of two.

Switching views

Calendar.ViewSwitcher renders a plain <select> with one option per registered view, labelled by getViewLabel, and the registry's ViewSwitcher is a styled one. To build your own control, call setView from useCalendarActions():

view-buttons.tsx
// Render it inside <Calendar.Root>, in place of Calendar.ViewSwitcher.
export function ViewButtons() {
  const actions = Calendar.useCalendarActions();
  const active = Calendar.useCalendarSelector((state) => state.view);

  return (
    <For each={Calendar.views}>
      {(view) => (
        <button
          type="button"
          aria-pressed={active() === view.name ? "true" : "false"}
          onClick={() => actions.setView(view.name)}
        >
          {viewLabels[view.name]}
        </button>
      )}
    </For>
  );
}

Inside a view's Renderer, use the actions prop instead.

The active view also drives Title, PreviousTrigger, and NextTrigger. The title comes from the view's getTitle, and the buttons move by the view's own step: two weeks in this agenda, a month in the month grid.

If the active name doesn't match a registered view, ActiveView renders its fallback prop, the previous and next buttons are disabled, and meta().diagnostics includes an unregistered-active-view error.

On this page