Birch UI v0.1
Pricing

Event Calendar API and eventsCalendar

Every option, method, event and exported function of the Event Calendar, with defaults, payloads and links to the guides.

Open .md

This page is the complete reference for @birchui/calendar. The generated type reference is on the package API page.

TypeScript
import {
  createCalendar,
  calendarDefinition,
  CALENDAR_EVENTS,
  calendarStyles,
  parseICS,
  toICS,
  parseRRule,
  formatRRule,
  expandRRule,
  RRuleError,
} from '@birchui/calendar';
Export Description
createCalendar(container, options?) Renders a calendar into container and returns a CalendarApi. Throws a TypeError when container is not an element.
calendarDefinition The widget definition (name BirchCalendar, tag birchui-calendar, factory and event list) for the framework adapters' generic factories. See Use it in your framework.
CALENDAR_EVENTS The list of event names.
calendarStyles The stylesheet as a string, for shadow roots or custom injection.
parseICS, toICS iCalendar import and export. See iCalendar.
parseRRule, formatRRule, expandRRule, RRuleError The recurrence engine. See Recurrence.

createCalendar<TEvent> is generic: pass your own event interface (extending CalendarEvent) and every payload, renderer argument and API return value is typed with it.

Options#

Pass options to createCalendar, or change them later with update(partial). Every option is optional. An invalid value logs one console warning and the default is used instead.

Data#

Option Default Description
events [] Events to show. See the event shape.
eventSource none (request) => Promise<TEvent[]>, called for each visible range. See Event sources.
defaultTimedDuration 60 Minutes, for timed events without end and all-day events dropped on the time grid.

Views and navigation#

Option Default Description
view first of views 'month', 'week', 'day', 'days', 'agenda' or 'year'.
views all but 'days' Views in the toolbar's switcher.
date today The date the calendar opens on.
dayCount 4 Length of the 'days' view, 1 to 31.
agendaDays the current month Length of the agenda in days.
firstDay from locale First day of the week, 0 (Sunday) to 6.
weekends true false hides Saturday and Sunday.
hiddenDays [] Weekdays to hide.
navLinks true Day numbers open the day view; month names in the year view open the month.
headerToolbar { start: 'prev,next today', center: 'title', end: 'views' } Toolbar layout, or false for no toolbar. See The toolbar.
viewSwitcher true Show the view switcher where the views token is.

Time grid#

Option Default Description
slotMinutes 30 Slot length, 5 to 120 minutes, dividing a day evenly.
snapMinutes 15 (or slotMinutes if smaller) Step for moving, resizing, selecting and keyboard edits.
slotHeight 24 Slot height in pixels, at least 8.
dayStartHour, dayEndHour 0, 24 Hours shown in the time grid.
scrollToHour 8 Hour scrolled into view when the grid opens.
businessHours none true, { daysOfWeek, startTime, endTime } or a list. See Business hours.
nowIndicator true Line at the current time.
maxEventsPerDay 4 Events per day in the month view and all-day row before "+N more".

Time and locale#

Option Default Description
timeZone browser zone IANA display zone. See Time zones.
locale browser locale Locale for dates, weekday names and times.
hour12 from locale Force a 12-hour or 24-hour clock.
now the real clock () => Date | number | string, a fixed "now" for tests and screenshots.
labels English Partial CalendarLabels: today, previous, next, allDay, noEvents, recurring, close, loading, views, more(count), eventCount(count).

Editing#

Option Default Description
readOnly false Turn off moving, resizing, selecting and removing.
selectable true Allow drag-to-select on empty time.
validateDrop none (info: DropInfo) => boolean; return false to refuse a move.
validateResize none (info: ResizeInfo) => boolean; return false to refuse a resize.

Rendering and appearance#

Option Default Description
eventRenderer none (occurrence, context) => string | Node | null. Strings are inserted as text; null keeps the default.
dayCellRenderer none (context) => string | Node | null, extra content for day cells.
height 'auto' 'auto' grows with the content; a number gives a fixed height in pixels.
theme 'light' 'light', 'dark' or 'auto' (follows prefers-color-scheme).
injectStyles true false skips injecting the stylesheet; import @birchui/calendar/styles.css yourself.
licenseKey none License key for this calendar. Or call setLicenseKey once. See Licensing.
CalendarOptionsinterface@birchui/calendarFull reference
PropertyTypeDescription
eventsoptionalTEvent[]—
eventSourceoptional(request: EventSourceRequest) => Promise<TEvent[]>—
viewoptionalViewType—
viewsoptionalViewType[]—
dateoptionalDateInput—
firstDayoptionalnumber—
localeoptionalstring—
timeZoneoptionalstring—
hour12optionalboolean—
slotMinutesoptionalnumber—
snapMinutesoptionalnumber—
slotHeightoptionalnumber—
dayStartHouroptionalnumber—
dayEndHouroptionalnumber—
scrollToHouroptionalnumber—
businessHoursoptionalboolean | BusinessHours | BusinessHours[]—
weekendsoptionalboolean—
hiddenDaysoptionalnumber[]—
dayCountoptionalnumber—
agendaDaysoptionalnumber—
defaultTimedDurationoptionalnumber—
maxEventsPerDayoptionalnumber—
nowIndicatoroptionalboolean—
navLinksoptionalboolean—
readOnlyoptionalboolean—
selectableoptionalboolean—
headerToolbaroptionalfalse | ToolbarOptions—
viewSwitcheroptionalboolean—
heightoptional'auto' | number—
themeoptionalThemeName—
injectStylesoptionalboolean—
licenseKeyoptionalstring—
labelsoptionalPartial<CalendarLabels>—
localeTextoptionalLocaleTextInput—
rtloptionalboolean—
nowoptional() => DateInput—
eventRendereroptional(occurrence: EventOccurrence<TEvent>, context: EventRenderContext) => RenderResult—
dayCellRendereroptional(context: DayCellContext) => RenderResult—
validateDropoptional(info: DropInfo<TEvent>) => boolean—
validateResizeoptional(info: ResizeInfo<TEvent>) => boolean—

The event shape#

Field Type Description
id string | number Unique identifier.
title string Shown on the event and used as its accessible name.
start Date | string | number Start. A date-only string makes the event all-day.
end Date | string | number End, exclusive. Optional.
allDay boolean Force all-day or timed. Defaults to all-day when start (and end, if given) are date-only strings.
color string Any CSS color.
rrule string RFC 5545 recurrence rule.
exdates (Date | string | number)[] Excluded occurrences.
timeZone string IANA zone for this event's wall-clock times and recurrence.
editable boolean false locks the event.
any other key unknown Kept and passed back to you. location is also read by screen readers and written by toICS, as are description, url, status and categories.

Methods#

CalendarApi includes the widget contract (element, update(partial), on(event, listener) returning an unsubscribe function, and destroy()) plus:

Method Returns Description
setView(view, date?) void Switch view, optionally to a date.
getView() ViewType The current view.
gotoDate(date) void Show the period containing date.
getDate() Date The date the view is anchored on.
today(), next(), prev() void Jump to today, or move one period.
getRange() { start: Date; end: Date } The visible range, end exclusive.
getTitle() string The current title, as shown in the toolbar.

Data#

Method Returns Description
setEvents(events) void Replace the local events. Events from eventSource are kept.
addEvent(event) void Add an event.
updateEvent(id, changes) TEvent | undefined Merge changes into an event and return the new object.
removeEvent(id) TEvent | undefined Remove an event and return it.
getEvent(id) TEvent | undefined One event, by id. Detached occurrences are found by their occurrenceId.
getEvents() TEvent[] Local and loaded events.
getOccurrences(start, end) EventOccurrence[] Every occurrence overlapping the range, with series expanded.
updateOccurrence(occurrenceId, changes, scope = 'this') TEvent | undefined Move or resize one occurrence or a whole series.
removeOccurrence(occurrenceId, scope = 'this') void Skip one occurrence or remove a series.
refetch() Promise<void> Reload the current range from eventSource.
isLoading() boolean Whether an eventSource request is pending.

The data methods update the calendar immediately and do not emit change events; only user actions do.

CalendarApiinterface@birchui/calendarFull reference
MemberTypeDescription
setView()(view: ViewType, date?: DateInput) => void—
getView()() => ViewType—
gotoDate()(date: DateInput) => void—
getDate()() => Date—
today()() => void—
next()() => void—
prev()() => void—
getRange()() => DateRange—
getTitle()() => string—
setEvents()(events: TEvent[]) => void—
addEvent()(event: TEvent) => void—
updateEvent()(id: string | number, changes: Partial<TEvent>) => TEvent | undefined—
removeEvent()(id: string | number) => TEvent | undefined—
getEvent()(id: string | number) => TEvent | undefined—
getEvents()() => TEvent[]—
getOccurrences()(start: DateInput, end: DateInput) => EventOccurrence<TEvent>[]—
updateOccurrence()(occurrenceId: string, changes: OccurrenceChanges, scope?: EditScope) => TEvent | undefined—
removeOccurrence()(occurrenceId: string, scope?: EditScope) => void—
refetch()() => Promise<void>—
isLoading()() => boolean—
elementreadonlyHTMLElementInherited from Widget.
update()(options: Partial<CalendarOptions<TEvent>>) => voidInherited from Widget.
on()<K extends keyof TEvents & string>(event: K, listener: Listener<TEvents[K]>) => () => voidInherited from Widget.
destroy()() => voidInherited from Widget.

Events#

Subscribe with on(event, listener). A listener that throws is caught and reported with console.error, so it never breaks the calendar. In framework adapters the same events are on… props (React, Solid), kebab-case listeners (Vue), outputs (Angular), on handlers of the Svelte action, or kebab-case CustomEvents on a custom element.

Event Payload When
ready { start, end, view } Once, in a microtask after createCalendar returns, with the initial range.
eventClick { event, occurrence, element, nativeEvent } An event is clicked, or activated with Enter or Space.
eventDoubleClick { event, occurrence, element, nativeEvent } An event is double-clicked.
eventDrop EventDropPayload An event is moved, before the change is applied. Includes delta.
eventResize EventResizePayload An event is resized, before the change is applied. Includes edge.
eventRemove EventRemovePayload An event is removed from the keyboard, before it is removed.
select { start, end, allDay, view } A span of empty time or days is selected.
dateClick { date, allDay, view, nativeEvent } Empty space or a day is clicked or activated.
viewChange { view, previousView } The view type changed.
rangeChange { start, end, view } The visible range changed (not fired for the initial range).
moreClick { date, occurrences, hiddenCount, preventDefault } A "+N more" button is activated. preventDefault() suppresses the built-in popover.
loading { isLoading } An eventSource request started or settled.

The change payloads (eventDrop, eventResize, eventRemove) share event, occurrence, isRecurring, a writable scope ('this' or 'all'), source ('pointer' or 'keyboard') and revert(). eventDrop and eventResize add start, end, allDay, oldStart, oldEnd and oldAllDay. See The change payload.

Types#

Type Description
CalendarOptions<TEvent>, CalendarApi<TEvent>, CalendarEventMap<TEvent> Options, API and event payload map.
CalendarEvent The base event shape.
EventOccurrence<TEvent> One displayed occurrence: id, occurrenceId, title, start, end, allDay, color, recurring, recurrenceId, editable, event.
EventChangePayload, EventDropPayload, EventResizePayload, EventRemovePayload Change payloads.
EventPointerPayload, SelectPayload, DateClickPayload, MoreClickPayload, ViewChangePayload, RangeChangePayload Other payloads.
DropInfo, ResizeInfo Validator arguments.
EventRenderContext, DayCellContext, RenderResult Renderer arguments and return type.
EventSourceRequest, DateRange Event source request and ranges.
BusinessHours, ToolbarOptions, CalendarLabels Option shapes.
OccurrenceChanges, EditScope, InteractionSource Editing.
ViewType, ThemeName, DateInput String unions and date input.
IcsEvent, ToIcsOptions iCalendar.
RRule, RRuleUntil, Frequency, WeekdaySpec, ExpandOptions Recurrence engine.

Styling hooks#

The root element has the class lq-cal, plus lq-theme-light or lq-theme-dark, lq-cal--auto-height with height: 'auto', lq-cal--loading while loading and lq-cal--dragging during a drag. Events have lq-cal-event with modifiers such as --all-day, --recurring, --editable, --invalid and --continues-before/--continues-after, and days have lq-cal-day with --today, --past, --weekend, --non-business and --other-month. Theme through the shared --lq-* tokens and the calendar tokens such as --lq-cal-now, --lq-cal-nonbusiness, --lq-cal-today-bg and --lq-cal-shadow; see the theming guide.

↑ ↓ to move, Enter to open, Esc to close