Theming

Calendar color tokens, dark mode, the event color palette, and controls of your own.

The packages don't ship any CSS. The styled parts in the registry read their colors and sizes from CSS variables defined in calendar-theme.css. The calendar-theme item, which every view brings, adds its tokens and rules to your global CSS, as described in UI source. Override the variables in your own CSS to restyle the calendar, as Changing tokens shows: each shadcn add writes the theme's own block again. To try changes live and copy the CSS, use the Theme builder.

This page covers the Tailwind baseline. The stylex-* items keep the same token names, as StyleX variables you override with stylex.createTheme; see StyleX.

Tokens

calendar-theme.css defines the standard shadcn/ui tokens (--background, --primary, --border, and so on) plus these calendar tokens. shadcn add adds only the calendar tokens, since your app has its own shadcn theme:

VariableUsed forTailwind class
--calendar-surfaceBehind sticky headers, between eventsbg-calendar-surface
--calendar-gridLines between days and hoursborder-calendar-grid
--calendar-axisHour and weekday labelstext-calendar-axis
--calendar-todayToday's date markerbg-calendar-today
--calendar-today-foregroundText on today's markertext-calendar-today-foreground
--calendar-nowThe current-time linebg-calendar-now
--calendar-selectionSelected days and time rangesbg-calendar-selection
--calendar-weekendWeekend backgroundbg-calendar-weekend
--calendar-unavailableClosed time in time grids and timelinesbg-calendar-unavailable
--calendar-closedClosed days in the month and year viewsbg-calendar-closed
--calendar-busyA resource status's busy dotbg-calendar-busy
--calendar-freeA resource status's free dotbg-calendar-free
--calendar-invalidA preview the policies would rejectoutline-calendar-invalid
--calendar-warningA preview the policies would flagoutline-calendar-warning
--calendar-eventEvent backgroundbg-calendar-event
--calendar-event-foregroundEvent texttext-calendar-event-foreground
--calendar-event-borderEvent accent edgeborder-calendar-event-border
--calendar-hour-heightHeight of one hour in time grids (3rem)h-(--calendar-hour-height)
--calendar-event-padding-xPadding at the sides of time-grid events (0.375rem)px-(--calendar-event-padding-x)
--calendar-event-padding-yPadding above and below time-grid events (0.25rem)py-(--calendar-event-padding-y)

The color tokens work with any Tailwind color utility, so text-calendar-today and ring-calendar-now work too. Most calendar tokens derive from the shadcn tokens: --calendar-grid is your --border, and the default event colors mix your --primary into --background.

The event padding tokens set how roomy events are in the week, day and resource columns views, along with --calendar-hour-height. The views fall back to the default padding where they read them, so a copy of calendar-theme.css from before these tokens keeps working.

Changing tokens

Every token is declared inside @layer base, so a plain rule in your own CSS wins without !important. Set the light values on :root and the dark values on .dark:

globals.css
:root {
  --calendar-today: oklch(0.55 0.17 150);
  --calendar-hour-height: 4rem;
}

.dark {
  --calendar-today: oklch(0.72 0.15 150);
}

If your app already defines the shadcn tokens, the calendar follows them automatically.

--calendar-surface is unset by default and falls back to --background. Set it on the calendar's container when that container has its own background, such as a card, so sticky headers and gutters match it:

<main className="bg-card [--calendar-surface:var(--card)]">

Dark mode

The theme switches when an ancestor of the calendar has the dark class, which is how shadcn/ui and next-themes work. shadcn apps already define the matching Tailwind dark variant. If yours doesn't, add @custom-variant dark (&:is(.dark *)); below the imports in your global CSS.

Event colors

The theme has a palette of nine event colors: blue, green, red, orange, yellow, purple, pink, teal, and gray. Put one in a data-color attribute and that element's three event tokens switch to the color, in both light and dark mode:

<div data-color="green" class="bg-calendar-event text-calendar-event-foreground">Standup</div>

EventChip, the event button in registry/calendar, sets data-color from its color prop. The names are exported from event-colors.ts as calendarEventColors, with the type CalendarEventColor.

Choosing a color per event

Every built-in view takes an optional getEventColor option: a function from your event record to a color name. Pass it when you create the view, as the Quick start does, or per calendar with the viewOptions prop on Root:

const getEventColor = (meeting: Meeting) => (meeting.title === "Standup" ? "green" : "blue");

// On Root:
viewOptions={{ month: { getEventColor }, agenda: { getEventColor } }}

Define the function outside your component, so it keeps its identity between renders. See Performance. Without getEventColor, events use the theme's default event tokens.

To support it in your own view, add it to the view's options and pass the result to EventChip:

upcoming-view.tsx
import {
  defineCalendarView,
  plainDateInterval,
  type CalendarViewProjectionInput,
} from "@moltenship/calendar";

import { EventChip } from "@/components/calendar/event-chip";
import type { CalendarEventColor } from "@/components/calendar/event-colors";

import type { Meeting } from "./quick-start";

interface UpcomingOptions {
  readonly getEventColor?: (meeting: Meeting) => CalendarEventColor;
}

export const upcomingView = defineCalendarView({
  name: "upcoming",
  defaultOptions: {},
  strategy: {
    getRange: (anchor) => plainDateInterval(anchor, anchor.add({ days: 7 })),
    navigate: (anchor, delta) => anchor.add({ weeks: delta }),
    getTitle: (range, { locale }) => range.start.toLocaleString(locale, { dateStyle: "medium" }),
    project: ({ snapshot, instantRange }: CalendarViewProjectionInput<UpcomingOptions, Meeting>) =>
      snapshot.queryTimed(instantRange),
  },
  Renderer: ({ projection, options }) => (
    <ul>
      {projection.map(({ event }) => (
        <li key={event.id}>
          <EventChip color={options.getEventColor?.(event)}>{event.title}</EventChip>
        </li>
      ))}
    </ul>
  ),
});

Adding a color

Each palette entry only sets a hue and a chroma; the [data-color] rule turns them into the three event tokens for light and dark mode. To add a color, add its name to calendarEventColors in event-colors.ts and give it a hue and chroma in your CSS:

globals.css
[data-color="brand"] {
  --calendar-event-hue: 285;
  --calendar-event-chroma: 0.2;
}

Use your own controls

The kit's files are your app's code once you add them: a default to edit or replace. Swapping a control is one of four ways to change the calendar's UI, and Customization sets it beside the other three.

The Tailwind views take their buttons, badges, tooltips, the view select, popovers, dialogs and toasts from the files calendar-ui adds to components/calendar/ui/. They don't import ui-sdk themselves, and they don't reach into a control's parts or attributes. To use a control of your own, replace the body of its file: keep the file's name, the names it exports and the props below, and render your component. The views stay as they are.

With shadcn's button, from a Base UI style, the button file is a few lines:

components/calendar/ui/button.tsx
import type { ComponentProps } from "react";

import { Button as AppButton, buttonVariants } from "@/components/ui/button";

export type ButtonProps = ComponentProps<typeof AppButton>;

export function Button(props: ButtonProps) {
  return <AppButton {...props} />;
}

export { buttonVariants };

Pass on every other prop, aria-* and data-* included, to the element your control renders, around its children. The views set them, and their CSS and tests read some of them. What the views import from each file, and what they pass:

FileThe views importWhat the views pass
button.tsxButtonvariant (outline, ghost), size (default, lg, icon, icon-sm, icon-xs), className, onClick, disabled, tabIndex, ref, aria-*, data-scope, and render
badge.tsxBadgevariant="outline", className, title, and data-slot="resource-status" with data-state, which colours the status dot inside it
tooltip.tsxTooltip, TooltipTrigger, TooltipContent, createTooltipHandle, TooltipHandleTooltip: delay, and for one tooltip many triggers share, handle, trackCursorAxis="y", onOpenChange with details.cancel() and details.payload, and children as a function of { payload }. TooltipTrigger: render, the element it shows on, and handle and payload. TooltipContent: the text, and side, align, sideOffset, className and aria-label
select.tsxSelect, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectItemSelect: items ({ label, value }), value and onValueChange, which gets the new value. SelectTrigger: aria-label and className. SelectContent: align and alignItemWithTrigger. SelectItem: value, label, and the label with its shortcut as children
popover.tsxPopover, PopoverTrigger, PopoverContent, PopoverTitle, PopoverClose, createPopoverHandle, PopoverHandlecreatePopoverHandle(): one popover for many triggers, with open(triggerId), close() and getPayload(). Popover: handle, modal, onOpenChange, and children as a function of { payload }. PopoverTrigger: handle, payload, id, render, aria-label, className, style, tabIndex and onMouseDown. PopoverContent: aria-label, side (inline-start and inline-end too), align, sideOffset, className, ref, initialFocus (a ref) and finalFocus (false, or a function that returns the element). PopoverClose: render
dialog.tsxDialog, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, DialogCloseDialog: open, onOpenChange and onOpenChangeComplete; it's modal. DialogContent: className and initialFocus (a ref). DialogClose: render, the button. The rest: children and className
toast.tsxToastViewport, Toast, ToastTitle, ToastDescription, ToastAction, ToastClose, createToastManager, ToastManagercreateToastManager(): add({ id, title, description, timeout, actionProps, onRemove }), where timeout: 0 keeps a toast and actionProps.onClick gets { input }, and close(id). ToastViewport: manager, aria-label and one toast's parts as children. ToastClose: aria-label. The parts render the toast's own text

The kit's files also export buttonVariants, badgeVariants, SelectGroupLabel and SelectSeparator for your own code. Keep them, or remove what you don't use. Beside them, tooltip-handle.ts, popover-handle.ts and toast-manager.ts hold the kit's tooltip, popover and toast state, and popup-side.ts maps inline-start and inline-end for the tooltip and the popover. A control you replace can stop importing them; keep each one another kit file still imports.

render is an element to render in place of the <button>. The toolbar passes the calendar's TodayTrigger, PreviousTrigger and NextTrigger this way: the trigger keeps its own props and runs the command, and your button adds its look and passes on disabled. If your button takes asChild instead, as a Radix style's does, render the render element as its child with asChild. Typing on the view select matches each item's label, so pass it on to your select's items.

The year's day popover and the annotations each open one popover from many triggers, so a view never mounts hundreds of roots. With shadcn's popover, build the handle on Base UI's Popover.createHandle(): it opens a trigger by its id and closes, and your getPayload() returns the payload of the trigger that opened it last. The views move focus themselves where finalFocus says, so map false to Base UI's finalFocus={false}. The calendar's own tests swap in shadcn's popover and dialog this way, and the views keep working by pointer and by keyboard.

A control that isn't built on ui-sdk gives up two things:

  • What an agent sees. An agent bridge lists ui-sdk's components. It reads your control only as far as your component tells it, and a stock shadcn control tells it nothing. The calendar stays on the bridge, so an agent can still change the view with its setView action.
  • The same control in React and Solid. ui-sdk has the same components in both frameworks, so a control built on it behaves alike in both. Yours behaves as your component does, so a Solid app needs its own version of it. The Solid registry's controls are in its calendar-ui item.

In the StyleX items

The stylex- views take the same controls from stylex-calendar-ui, in components/calendar-stylex/ui/: the same files, exports and props as in the table, with StyleX styles in place of class names. Where the table says className, the StyleX views pass xstyle, a value of stylex.create, and a control applies it after its own styles:

components/calendar-stylex/ui/button.tsx
import type { ComponentProps, CSSProperties } from "react";

import { Button as AppButton } from "@/components/ui/button";
import { buttonVariants } from "@/components/calendar-stylex/ui/button.styles";
import { type XStyle, xprops } from "@/components/calendar-stylex/xprops";

// Base UI's className and style can be functions of state; the views pass plain values.
export interface ButtonProps extends Omit<ComponentProps<typeof AppButton>, "className" | "style"> {
  readonly className?: string;
  readonly style?: CSSProperties;
  readonly xstyle?: XStyle;
}

export function Button({ className, style, xstyle, ...props }: ButtonProps) {
  return <AppButton {...props} {...xprops({ className, style }, xstyle)} />;
}

export { buttonVariants };

xprops, from the StyleX theme item, merges the styles with a className and style the element also gets. A control from a StyleX design system that takes xstyle itself can take it as it comes.

On this page