Fragiola

API: primitives (@fragiola/calendar-react)

Vue primitives

The same primitives and hooks for Vue 3.5, from @fragiola/calendar-vue, and how each React prop maps onto Vue props, slots, events and attributes.

@fragiola/calendar-vue has every primitive of the React package, as a Vue 3.5 component, and every hook as a composable, over the same core (re-exported whole, so a Vue app installs and imports one package). The behaviour, the ARIA, the roles, the data-* attributes and data-calendar-part of every element are the same: the React pages of this reference describe each part, and this page says how its React API is written in Vue.

import {
    Calendar,
    createCalendarModel,
    typedCalendar,
    useCalendar,
    useCalendarView,
    type CalendarEventJson,
} from "@fragiola/calendar-vue";
// each feature from its own entry, with its parts and composables
import { DragPreview, dragAndDrop, useDragPreview } from "@fragiola/calendar-vue/drag-and-drop";
import { Selection, selection, useSelection } from "@fragiola/calendar-vue/selection";

Typing by your registry

A React part takes the registry and the features as type arguments (<Calendar.Root<Types, typeof features>>); a Vue template cannot pass them. typedCalendar<Types, typeof features>() returns the same components, typed by both: the root takes a CalendarModel<Types, typeof features>, v-model:events holds your events, and a feature's event (@select with selection(), @event-drop with dragAndDrop() or resize(), @external-drop with externalDrop()) compiles only when the feature is installed: without it, the listener is a never prop (RootMissingEvents<F>) and vue-tsc refuses it (Features).

calendar.ts
import { typedCalendar } from "@fragiola/calendar-vue";
import { selection } from "@fragiola/calendar-vue/selection";

export type Types = { events: { meeting: { room: string } }; calendar: undefined };
export const features = [selection()] as const;
export const Calendar = typedCalendar<Types, typeof features>();
exportdescription
typedCalendar<T, F>()the Calendar components typed by the registry T and the features F, as a TypedCalendar<T, F> (the same objects as Calendar); its Calendar.Root takes RootProps<T, F> (RootBaseProps<T, F> and RootMissingEvents<F>) and emits RootEmits<T, F>
Calendarthe components, untyped: its Calendar.Root takes any model and every event

How React's props map

ReactVue
render={<section />}as="section" (a tag or a component)
render={(props, state) => …}the render scoped slot, #render="{ props, state, children }": bind v-bind="props" on your element and render <component :is="children" /> inside it
className, stylethe class and style attributes, merged under the structural style (structural keys win: a segment's place, a timed event's position)
className={(state) => …}, style={(state) => …}no function form: a data-* selector ([data-today], [data-selected]), or the render slot's state
onClick, onKeyDown, …listeners (@click, @keydown), run after the primitive's own
refa template ref on a part is its component instance; the element is its $el
children functions (Calendar.Weeks, Calendar.Days, Calendar.DayEvents, …)the default scoped slot: v-slot="{ week }", v-slot="{ day, week }", v-slot="{ segment }"
a function per day (Calendar.Week, Calendar.AllDayRow) or per column (Calendar.SlotRow)the named slot #day="{ day, week }" or #column="{ column }"; elements go in the default slot
the state given to children (Calendar.More, Calendar.WeekNumber, the buttons, …)the default slot's scope: v-slot="{ hiddenCount }", v-slot="{ weekNumber }", v-slot="{ disabled }"
events + onEventsChangev-model:events (or :events with @update:events); @events-change beside it
view + onViewChangev-model:view (the type), @view-change with { type, days }
date + onDateChangev-model:date (the anchor date, YYYY-MM-DD), @date-change
onEventClick, onSelect, onEventDrop, … (ENGINE_EVENT_CALLBACKS)listeners in kebab-case: @event-click, @date-click, @more-click, @select, @event-drop, @external-drop, @today-change, @announce
calendarRef={calendar}:calendar-ref="calendar"; the handle is calendar.value, in the template too (React: calendar.current)
defaultEvents, defaultView, longPressDelay, …the same props in kebab-case (default-events, default-view, long-press-delay)
<Calendar.Root<Types, typeof features>> and the other type argumentstypedCalendar<Types, typeof features>().Root
useCalendar<Types, typeof features>() and the other hooksthe composables of the same names, returning computed refs (below)

The controlled values are sent, not enforced, as in React: a new value runs its command with meta: { source: "controlled" }, and update:* reports every other change.

Components

Every part is Calendar.<Part>, with the props of its React page except render, className, style, ref and children (see the table above). Each part that renders an element accepts as and the render slot; Calendar.Weeks, Calendar.Days, Calendar.SlotRows, Calendar.Slots and Calendar.ListDays render none, only their slot per entity.

partVue propsslotsevents
Calendar.Rootmodel, events, defaultEvents, defaultCalendars, settings, view, defaultView, days, date, defaultDate, features, now, createId, calendarRef, weekNumberColumn (week-number-column), and the engine options host, longPressDelay, dragThreshold, autoScrolldefaultupdate:events, events-change, update:view, view-change, update:date, date-change, and the engine events event-click, date-click, more-click, select, event-drop, external-drop, today-change, announce
Calendar.Previousnonedefault { disabled }none
Calendar.Nextnonedefault { disabled }none
Calendar.Todaynonedefault { disabled }none
Calendar.ViewButtonview, daysdefault { disabled, pressed }none
Calendar.DayGridnonedefaultnone
Calendar.ColumnHeadersnonedefault { date }, per columnnone
Calendar.ColumnHeaderdatedefault { date, today, weekend, past }none
Calendar.Weeksnonedefault { week }, per weeknone
Calendar.Weekweekday { day, week }, per day; default { week }none
Calendar.WeekNumbernonedefault { weekNumber }none
Calendar.Daysnonedefault { day, week }, per daynone
Calendar.Daydaydefault { day, focused, selected, disabled, businessHours, segments } (DaySlotScope)none
Calendar.DayEventsnonedefault { segment }, per segmentnone
Calendar.Segmentsegmentdefault SegmentStatenone
Calendar.Morenonedefault { hiddenCount, hiddenOccurrenceIds, date }none
Calendar.TimeGridnonedefaultnone
Calendar.AllDayRownoneday { day, week }, per day; default { week }none
Calendar.Scrollernonedefaultnone
Calendar.SlotRowsnonedefault { slot }, per slotnone
Calendar.SlotRowslotcolumn { column }, per column; default { slot }none
Calendar.SlotLabelnonedefault { time }none
Calendar.Slotsnonedefault { column }, per columnnone
Calendar.Slotdatedefault SlotStatenone
Calendar.Columnsnonedefault { column }, per columnnone
Calendar.Columncolumndefault { column, selected }none
Calendar.ColumnEventsnonedefault { segment }, per segmentnone
Calendar.TimeEventsegmentdefault TimeEventStatenone
Calendar.Listnonedefault { empty }none
Calendar.ListDaysnonedefault { day }, per daynone
Calendar.ListDaydaydefault { item }, per occurrencenone
Calendar.ListEventitemdefault ListEventStatenone

The feature parts come from their entries, and take the render slot like the others:

partentryVue propsslots
Selection@fragiola/calendar-vue/selectionnonedefault { segment, pending }
DragPreview@fragiola/calendar-vue/drag-and-drop, /resizenonedefault { preview, segment }
ResizeHandle@fragiola/calendar-vue/resizeedgedefault { edge }
NowIndicator@fragiola/calendar-vue/now-indicatornonedefault { position }
BusinessHours@fragiola/calendar-vue/constraintsnonedefault { range }

@fragiola/calendar-vue/recurrence, @fragiola/calendar-vue/external-drop and @fragiola/calendar-vue/event-sources re-export the core's entry and add no part: an external drop previews through DragPreview and reaches the root's @external-drop.

Another model remounts the calendar (a new engine), as a new model creates a new engine in React. Keep the model out of Vue's reactivity: create it once (const model = createCalendarModel(json) in setup), never in ref() or reactive(). The model's state is frozen data, which Vue never proxies, so a ref of the events update:events reports holds the model's own list.

A slot that reads only its scope and reactive state is stable: a row renders again only when its layout object changed, as a stable function in React. A slot under v-for or v-if, or one a render function writes, is new on every render, and every row renders again with it ($stable: true on a render function's slots keeps them).

Composables

The hooks of the React reference, as composables, with the same names. Call them in setup, inside a Calendar.Root (the calendar refs also outside it). A value composable returns a computed ref, which changes only when its value changes (records and arrays compared entry by entry); a part composable returns { state, props } of computed refs: bind v-bind="props" on your element (it holds the template ref that registers it and the structural style). Their arguments take a value, a ref or a getter (() => props.day).

composablereturns
useCalendar<T, F>(){ model, engine }, a UseCalendarResult<T, F> (plain values, not reactive: read what you show through the composables below)
useCalendarRef<T, F>()a CalendarRef<T, F>, whose reactive value is the root's CalendarHandle (model, engine) while it is mounted, null otherwise. It is not a Vue ref, so a template does not unwrap it: :calendar-ref="calendar" passes it, and the template reads calendar.value
createCalendarRef<T, F>()the same calendar ref, anywhere (a module, a test)
useCalendarView()a computed ref of the CalendarView: type, anchorDate, days, visibleRange, currentRange
useCalendarTitle(format?)a computed ref of the title's Intl range parts
useDayHeader(date, format?)a computed ref of a column header's Intl parts
useSlotLabel(time, format?)a computed ref of a slot time's Intl parts
useDayGrid()a computed ref of the DayGrid shown, null in a list view
useTimeGrid()a computed ref of the TimeGrid shown, null outside the time grid views
useListLayout()a computed ref of the ListLayout (the visible days with their occurrences)
useDay(day){ state, props } (PartComposableResult<DayState>) of a day
useSlot({ date, time }){ state, props } of a slot, its state a SlotState
useSegment(segment){ state, props } of a day-grid segment, its state a SegmentState
useTimeEvent(segment){ state, props } of a timed segment, its state a TimeEventState
useListEvent(item){ state, props } of a list view's occurrence, its state a ListEventState
useSelection() (from @fragiola/calendar-vue/selection)a computed ref of the CalendarSelection: range and preview
useDragPreview() (from @fragiola/calendar-vue/drag-and-drop or /resize)a computed ref of the drag's DragPreview, null for none
useNowPosition() (from @fragiola/calendar-vue/now-indicator)a computed ref of the NowPosition, null when not in view and before the engine
useBusinessHours(date?) (from @fragiola/calendar-vue/constraints)a computed ref of the visible days' BusinessHoursRange list, only date's when given

A server render (Nuxt, renderToString) outputs the calendar's markup from the model's state, with no timer and no listener: the engine, the controlled props and the composables' subscriptions start once the root mounts in the browser, and hydration finds the same elements.

Types

Each part exports its props and its slots, named as in React, and its state where it has one: RootProps, RootBaseProps, RootEngineProps, RootSlots, RootState, RootEmits, RootEngineEmits, RootMissingEvents, RootView, PreviousProps, PreviousSlots, PreviousState, NextProps, NextSlots, NextState, TodayProps, TodaySlots, TodayState, ViewButtonProps, ViewButtonSlots, ViewButtonState, DayGridProps, DayGridSlots, DayGridState, ColumnHeadersProps, ColumnHeadersSlots, ColumnHeadersState, ColumnHeaderProps, ColumnHeaderSlots, ColumnHeaderState, WeeksProps, WeeksSlots, WeekProps, WeekSlots, WeekState, WeekNumberProps, WeekNumberSlots, WeekNumberState, DaysProps, DaysSlots, DayProps, DaySlots, DaySlotScope, DayEventsProps, DayEventsSlots, DayEventsState, SegmentProps, SegmentSlots, MoreProps, MoreSlots, MoreState, TimeGridProps, TimeGridSlots, TimeGridState, AllDayRowProps, AllDayRowSlots, AllDayRowState, ScrollerProps, ScrollerSlots, ScrollerState, SlotRowsProps, SlotRowsSlots, SlotRowProps, SlotRowSlots, SlotRowState, SlotLabelProps, SlotLabelSlots, SlotLabelState, SlotsProps, SlotsSlots, SlotProps, SlotSlots, ColumnsProps, ColumnsSlots, ColumnsState, ColumnProps, ColumnSlots, ColumnState, ColumnEventsProps, ColumnEventsSlots, ColumnEventsState, TimeEventProps, TimeEventSlots, ListProps, ListSlots, ListState, ListDaysProps, ListDaysSlots, ListDayProps, ListDaySlots, ListDayState, ListEventProps, ListEventSlots; the feature parts' SelectionProps, SelectionSlots, SelectionState, DragPreviewProps, DragPreviewSlots, DragPreviewState, ResizeHandleProps, ResizeHandleSlots, ResizeHandleState, NowIndicatorProps, NowIndicatorSlots, NowIndicatorState, BusinessHoursProps, BusinessHoursSlots, BusinessHoursState; and the composables' DayState, SlotState, SegmentState, TimeEventState, ListEventState, EventState, CommandButtonState, CalendarView, UseCalendarResult, CalendarSelection, CalendarHandle, CalendarRef.

typedescription
CalendarComponent<Props, Slots, Emits>a part's component type: its props, plus any fallthrough attribute, its scoped slots and its events
TypedCalendar<T, F>what typedCalendar<T, F>() returns: every part, the root typed by T and F
PartComposableResult<S>what a part composable returns: state and props, computed refs
PartElementPropsits props: the ARIA, data-*, listeners, the template ref and the structural style
PrimitivePropswhat every part that renders an element accepts: as
AsPropa tag name or a component
RenderSlot<State>the render slot every such part accepts
RenderSlotProps<State>what it receives: props, state, children
SlotFunction<Scope>a scoped slot: its scope in, the nodes it renders out
ElementRefa function template ref, as a part composable's props.ref

Examples

Every example of the gallery exists in Vue, with the same behaviour: pick Vue in the framework switch to see its code. The month and week examples assemble the grids from the slots, select to create and the team planner use typedCalendar with the features' events, and undo and redo and save and restore keep the model's state in the app.