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.
Week and day
The registry's time grids, with an all-day row, a current-time line and secondary time zones.
Month
The registry's month grid, with multi-day bars and a "+N more" popover.
Year
The registry's twelve months at a glance, with a dot for each event color on a day.
Agenda
The registry's list of events grouped by day, added with the shadcn CLI.
Scrolling views
The week, day, month and agenda as views that scroll without end.
Resource columns
Rooms and people side by side, grouped by team, with hundreds of columns.
Resource timeline
The registry's rooms or people as rows and time as columns, for a day, a week or a month.
Toolbar and mini month
The registry's toolbar, view switcher and mini month.
Controls
The buttons, badges, tooltips and selects the registry's views are built from.
Custom views
Write a view with a strategy and a Renderer.
Keyboard in your own views
Roving focus, arrow keys, and keyboard move, resize and create.
Dragging in your own views
Drag, resize and create with a mouse, a pen or touch.
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.
| Layout | Functions |
|---|---|
| Agenda | getListRange, navigateList, getListTitle, projectList, listSpatialNavigation |
| Month grid | getMonthRange, navigateMonth, getMonthTitle, projectMonth, monthSpatialNavigation |
| Year | getYearRange, navigateYear, getYearTitle, projectYear, yearSpatialNavigation |
| Week and day | timeGridStrategy({ kind }), a whole strategy, and timeGridSpatialNavigation |
| Resource columns | resourceColumnsStrategy, and resourceColumnsSpatialNavigation |
| Resource timeline | resourceTimelineStrategy, and resourceTimelineSpatialNavigation |
| Scrolling | scrollingTimeGridStrategy, 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.
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():
// 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.