Fragiola

API: primitives (@fragiola/calendar-react)

Calendar.Root

The calendar's root element. It creates or takes a model, starts the engine, maps the controlled props onto commands and hears the engine's events.

Calendar.Root is the element every other part lives in. It holds the calendar's model (the events, the calendars, the settings and the view) and the engine that turns pointers and keys into commands on it. It renders one div and the children you give it: the toolbar, the grid, a live region. What it shows, and how it looks, stays yours.

Behaviour

  • A model, given or created. Give it a model from createCalendarModel, or let it create one from defaultEvents, defaultCalendars, settings, defaultView, defaultDate, features, now and createId. These are read once, at mount; a new model identity starts a new engine.
  • The engine, after the first commit. The engine (keyboard, gestures, measurement, focus) is created in a layout effect, so a server render and the first client render show the model's layout and attributes with no timer and no listener. The parts read the model until then.
  • Controlled props are sent, not enforced. events runs event.set-all, settings runs settings.set, view (with days) runs view.set and date runs view.go-to, each when its value changes, with meta: { source: "controlled" }. onEventsChange, onViewChange and onDateChange hear every other change: echo it into your state to keep it, as with any controlled React input. A refused value warns once and the model keeps its own.
  • Engine events become callbacks. Each engine event has a callback on the root (onEventClick, onSelect, …); a feature's callback compiles only with that feature installed.
  • One tab stop. The grid inside it has one tab stop and a roving focus over its days or slots (the APG grid pattern, https://www.w3.org/WAI/ARIA/apg/patterns/grid/; see accessible names and the keyboard).

It renders data-calendar-part="root" and data-view (the view shown), plus what the features add.

Usage

import {
    Calendar,
    type CalendarEventJson,
    useCalendarTitle,
} from "@fragiola/calendar-react";
import { dragAndDrop } from "@fragiola/calendar-react/drag-and-drop";

type Types = { events: { meeting: { room: string } }; calendar: undefined };

const features = [dragAndDrop()] as const;

const events: CalendarEventJson<Types>[] = [
    {
        id: "standup",
        title: "Standup",
        start: "2026-11-26T09:00:00-03:00",
        end: "2026-11-26T09:15:00-03:00",
        allDay: false,
        kind: "meeting",
        data: { room: "Blue" },
    },
];

function Title() {
    const parts = useCalendarTitle();
    return <h2>{parts.map((part) => part.value).join("")}</h2>;
}

export function TeamWeek() {
    return (
        <Calendar.Root<Types, typeof features>
            aria-label="Team calendar"
            defaultEvents={events}
            settings={{ timeZone: "America/Sao_Paulo", locale: "en-US" }}
            defaultView="week"
            features={features}
            onEventClick={(event) => console.log("open", event.eventId)}
            onEventDrop={(event) => console.log("moved to", event.start)}
            className={(state) => (state.gestureActive ? "cal dragging" : "cal")}
        >
            <Title />
            <Calendar.Previous>Previous</Calendar.Previous>
            <Calendar.Today>Today</Calendar.Today>
            <Calendar.Next>Next</Calendar.Next>
            {/* a Calendar.TimeGrid, a Calendar.DayGrid or a Calendar.List */}
        </Calendar.Root>
    );
}

The root's type arguments are the registry and the features (RootProps<T, F>): with them, a feature's callback such as onEventDrop is typed, and without its feature it is a type error. A model carries its own, so <Calendar.Root model={model}> needs none. A Vue template passes no type argument: typedCalendar<Types, typeof features>() gives the namespace typed by both, and @event-drop without its feature is a vue-tsc error (Vue primitives). An Angular root is typed by the model it is given (Angular primitives).

Props

The root's own props (RootBaseProps<T, F>); it also takes the common props, the engine props and the event props below, and every div attribute.

In Vue, the same props in kebab-case, v-model:events, v-model:view and v-model:date for the controlled ones, and listeners for the callbacks (@events-change, @event-click, …): see Vue primitives.

In Angular, the same props as inputs of [calendarRoot] (the model its own input), [(events)], [(view)] and [(date)] for the controlled ones, and outputs for the callbacks ((eventsChange), (eventClick), …; a feature's from its directive on the root): see Angular primitives.

proptypedefaultdescription
modelCalendarModel<T, F>created by the rootthe calendar model; a new identity creates a new engine
events(CalendarEventJson<T> | CalendarEventOf<T>)[]controlled events: a new list replaces the model's (event.set-all, each with its id)
defaultEventsCalendarEventJson<T>[][]the events of the model the root creates (read once)
onEventsChange(events) => voidthe model's events after every command that changes them, a drop included
defaultCalendarsCalendarInfoJson<T>[][]the calendars (categories) of the model the root creates (read once)
settingsCalendarSettingsJsonthe settings: the created model starts with them, and a change runs settings.set
viewViewTypecontrolled view type (view.set)
defaultViewViewType"month"the view of the model the root creates (read once)
daysnumbera days view's number of days, with view or defaultView
onViewChange(view: RootView) => voidthe view type (and a days view's count) changed
dateDateInputcontrolled date: a new value runs view.go-to
defaultDateDateInputtodaythe date the created model opens on (read once)
onDateChange(date: string) => voidthe view's anchor date (YYYY-MM-DD) changed
featuresF[]the opt-in features of the created model, each from its entry (read once)
now() => numberDate.nowthe clock of the created model, epoch milliseconds (read once)
createIdCreateIdthe id generator of the created model (read once)
calendarRefCalendarRef<T, F>access to the model and the engine from outside the root (hooks)
weekNumberColumnbooleanfalsea month's rows render a Calendar.WeekNumber before their days: the grid counts that column (aria-colcount, aria-colindex)
childrenReactNodethe toolbar, the grid, anything of yours

Engine props

Read once, when the root creates its engine (RootEngineProps, the engine's CalendarEngineOptions; see the engine).

proptypedefaultdescription
hostPartial<EngineHost>the root's windowtimers, frames, ResizeObserver and computed styles (tests inject them)
longPressDelaynumber500how long a touch is held before it drags or selects, ms
dragThresholdnumber5the pixels a mouse or pen press moves before a drag starts
autoScroll{ edge?, speed? } | false{ edge: 40, speed: 12 }the time grid's autoscroll near the scroller's edges

Event props

One callback per engine event (RootEventProps<F>, named by ENGINE_EVENT_CALLBACKS). Each gets the event as data, CalendarEngineEventOf<"event-click"> and so on.

propfeaturecalled when
onEventClickan event is tapped, or Enter is pressed on a focused one (eventId, occurrenceId, keyboard)
onDateClicka day or a slot is tapped (date, allDay, a slot's time and at)
onMoreClicka day's "+N more" is pressed, or Enter on it (date, occurrenceIds): open your popover
onSelectselection()a range is selected by a pointer's release or Enter (range, keyboard)
onEventDropdragAndDrop(), resize()a move or a resize ran its one command (kind, eventId, start, end, allDay)
onExternalDropexternalDrop()something from outside was dropped (eventId, point, types, dataTransfer)
onTodayChangethe day changed at midnight in the display zone (today)
onAnnouncethe engine has something to announce (announcement, data): word it in your live region

The root's DOM onSelect is not a prop: onSelect is the selection's.

Common props

Every part that renders an element takes these, on top of its element's attributes (PrimitiveProps<State>, and DivPrimitiveProps<State>, ButtonPrimitiveProps<State> or SpanPrimitiveProps<State> with them).

proptypedescription
renderRenderProp<State>replaces the element: an element whose props are merged (render={<section />}), or a function (props, state) => element (never asChild)
classNamestring | (state) => stringa class, or a function of the part's state
styleCSSProperties | (state) => CSSPropertiesa style, or a function of the state; the structural keys the part sets win
refRef<HTMLElement>a plain prop, merged with the part's own

A render function receives RenderedProps: spread them on the element it returns (their ref is a callback ref).

<Calendar.Day
    day={day}
    render={(props, state) => (
        <section {...props} aria-current={state.day.today ? "date" : undefined} />
    )}
/>

State

RootState, given to className, style and render:

fieldtypedescription
viewViewTypethe view shown (data-view)
gestureActivebooleana pointer gesture or a keyboard grab is under way

RootView, what onViewChange receives:

fieldtypedescription
typeViewTypethe view type
daysnumber | undefineda days view's count