StyleX
The calendar's views styled with StyleX, for apps without Tailwind.
The registry's baseline is Tailwind. The stylex-* items look the same as the Tailwind ones and
exist for apps that style with StyleX: the same sizes, colours, type, hover
and focus states and motion, control by control and view by view, in light and dark. They hold the
same components with the same behaviour, every view included: same file names, exports,
data-slot attributes, roles and labels. Only the styles differ, stylex.create rather than
Tailwind classes. Buttons, tooltips, the view select, popovers, dialogs and toasts come from
stylex-calendar-ui, the StyleX twin of the calendar's kit: the same parts on
ui-sdk. As with the baseline, you own the source you add.
One detail differs: in dark, a hovered event dims a little where the Tailwind one brightens.
StyleX's dark colours follow the page's color-scheme through light-dark(), which takes only
colours, so a filter can't change with it.
See it running on the demo's StyleX page.
Install
npm install @stylexjs/stylex
npm install --save-dev @stylexjs/unplugin@moltenship/calendar, @ui-sdk/react and lucide-react come with the items, as UI source
describes, and Temporal needs the same setup as in any app.
Configure Vite
import { fileURLToPath } from "node:url";
import stylex from "@stylexjs/unplugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
const fromHere = (path: string) => fileURLToPath(new URL(path, import.meta.url));
export default defineConfig(({ command }) => ({
plugins: [
// Before React.
stylex.vite({
aliases: { "@/*": [fromHere("src/*")] },
dev: command === "serve",
lightningcssOptions: {
targets: { chrome: 123 << 16, firefox: 120 << 16, safari: (17 << 16) | (5 << 8) },
},
runtimeInjection: false,
unstable_moduleResolution: { rootDir: fromHere("."), type: "commonJS" },
}),
react(),
],
build: { cssTarget: ["chrome123", "firefox120", "safari17.5"] },
resolve: { alias: { "@": fromHere("src") } },
}));aliasesandunstable_moduleResolutionlet StyleX find the tokens file. The items import it as@/components/calendar-stylex/calendar-tokens.stylex, and StyleX reads it at compile time. Vite's own alias doesn't reach the StyleX compiler, so it needs both.lightningcssOptions.targetsandbuild.cssTargetname browsers that havelight-dark(). The calendar's tokens rely on it for dark mode. With older targets it's lowered to a polyfill that needscolor-schemein the same stylesheet, and dark colors break without an error.
Add the global CSS
Declare ui-sdk's layer first, then import the calendar's stylesheet. calendar-global.css holds the
few rules StyleX can't write, such as those for drag previews, and arrives with the items. The
tokens follow the page's color-scheme through light-dark(), so set it too, or let your app's
mode toggle set it on the root:
@layer ui-sdk;
@import "@/components/calendar-stylex/calendar-global.css";
:root {
color-scheme: light dark;
}The calendar needs no other theme: its tokens hold their own colors, those of the Tailwind theme. To use your design system's, map them.
Add the items
shadcn add needs a components.json to know your aliases, even in an app without Tailwind, and
your tsconfig.json needs the @/* path. The schema requires the tailwind block, but these items
don't read it or style, and adding them leaves your CSS as it is:
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": { "css": "src/styles.css", "baseColor": "neutral", "cssVariables": true },
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}stylex-calendar-full installs every view, the tokens, the controls and the parts they share:
npx shadcn@latest add https://time.molten.sh/r/stylex-calendar-full.jsonOr add one view, which brings what it builds on. Every item in the
table on Installation has a stylex- version:
npx shadcn@latest add https://time.molten.sh/r/stylex-month-view.jsonThe files land in calendar-stylex/ under your components alias, and the controls in
calendar-stylex/ui/, so they never overwrite the Tailwind ones.
Use the views
The API is the Quick start's, with imports from calendar-stylex:
import { createCalendar, defineEventAdapter } from "@moltenship/calendar";
import * as stylex from "@stylexjs/stylex";
import { CalendarToolbar } from "@/components/calendar-stylex/calendar-toolbar";
import { createMonthView } from "@/components/calendar-stylex/month-view/month-view";
import { createWeekView } from "@/components/calendar-stylex/time-grid-view/time-grid-view";
const eventAdapter = defineEventAdapter<Meeting>()({
getId: (meeting) => meeting.id,
getTitle: (meeting) => meeting.title,
getInterval: (meeting) => ({ kind: "timed", start: meeting.start, end: meeting.end }),
getResourceIds: () => [],
});
const Calendar = createCalendar<Meeting>()({
eventAdapter,
views: [createWeekView<Meeting>(), createMonthView<Meeting>()],
});
const styles = stylex.create({
frame: { display: "flex", flexDirection: "column", height: 640 },
viewport: { flexGrow: 1, minHeight: 0 },
});
export function TeamCalendar({ meetings }: { readonly meetings: readonly Meeting[] }) {
return (
<Calendar.Root
events={meetings}
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
defaultTimeZone="Europe/Berlin"
locale="en-US"
weekRules={{ firstDay: 1, minimalDays: 4, weekend: [6, 7] }}
>
<Calendar.Frame {...stylex.props(styles.frame)}>
<CalendarToolbar calendar={Calendar} />
<Calendar.Viewport {...stylex.props(styles.viewport)}>
<Calendar.ActiveView />
</Calendar.Viewport>
</Calendar.Frame>
</Calendar.Root>
);
}Change the tokens
The tokens have the names in Theming, as keys of calendarVars:
calendarVars["--calendar-today"] is var(--calendar-today). Override them on a part of the page
with stylex.createTheme, and apply the theme on a wrapper. One value covers both modes through
light-dark(), which takes only colors:
import * as stylex from "@stylexjs/stylex";
import { calendarVars } from "@/components/calendar-stylex/calendar-tokens.stylex";
const calendarTheme = stylex.createTheme(calendarVars, {
"--calendar-today": "light-dark(oklch(0.55 0.17 150), oklch(0.72 0.15 150))",
"--calendar-hour-height": "4rem",
});
<div {...stylex.props(calendarTheme)}>
<TeamCalendar meetings={meetings} />
</div>;Tokens are resolved where they're declared, on :root. So a wrapper that overrides --primary
doesn't change --calendar-event-border, which reads var(--primary): restate it in the same
theme. The Theme builder does this for you, and lets you
try a theme and copy it.
Popovers, tooltips, dialogs and toasts render inside the calendar, in the browser's top layer, so a theme on a wrapper reaches them too.
--calendar-surface is no token. It's unset, and the views read it through a constant, for a
container with its own background to set in an inline style, as on
Theming.
Use your design system's colors
The base colors, such as --background, --primary and --border, hold the values of the
Tailwind theme. To have the calendar follow your design system, point them at its variables. For
a design system whose root theme puts its variables on <html>, that's:
const appCalendarTheme = stylex.createTheme(calendarVars, {
"--radius": "var(--app-radius)",
"--background": "var(--app-surface)",
"--foreground": "var(--app-text)",
"--popover": "var(--app-surface-raised)",
"--primary": "var(--app-accent)",
"--muted-foreground": "var(--app-text-muted)",
"--border": "var(--app-border)",
"--ring": "var(--app-focus)",
// …and the rest of the base colors in the list on Theming, in the same way.
});
// On `<html>` too, so the tokens that read a base color, such as `--calendar-event-border`, follow.
document.documentElement.classList.add(
...(stylex.props(appCalendarTheme).className ?? "").split(" "),
);Tokens lists the base colors.
Override a component's styles
The components take xstyle beside className and style, for styles of your own. They win over
the component's:
const styles = stylex.create({
toolbar: { paddingBlock: "1rem" },
});
<CalendarToolbar calendar={Calendar} xstyle={styles.toolbar} />;The controls in calendar-stylex/ui/ take xstyle too. To change a control everywhere, edit its
styles in its .styles.ts file, or replace the control, as
Use your own controls describes.
Event colors
Views take getEventColor, and the names are the same nine, as in
Choosing a color per event. Each color has three tokens
of its own, in place of the baseline's hue and chroma: --calendar-event-blue,
--calendar-event-blue-foreground and --calendar-event-blue-border. Override them with
createTheme like any other:
const calendarTheme = stylex.createTheme(calendarVars, {
"--calendar-event-blue": "light-dark(oklch(0.92 0.06 240), oklch(0.35 0.08 240))",
});eventColorStyles in event-color-styles.ts points an element's --calendar-event tokens at one
color, and data-color stays on the element as a hook for your own CSS. To add a color, add its
name to event-colors.ts, its tokens to calendar-tokens.stylex.ts, and an entry to
eventColorStyles.
Next.js
The demo and CI exercise this flavour under Vite, and not under Next.js. With Next.js, StyleX
compiles through @stylexjs/babel-plugin in babel.config.js, with the @/* alias, and
@stylexjs/postcss-plugin, with @stylex; in the global CSS; see StyleX's
installation guide.
What's different from the baseline
- The controls come from
stylex-calendar-ui, incalendar-stylex/ui/, notcalendar-ui. They have the same parts, props anddata-slotattributes, built on ui-sdk as well. Their look isstylex.createin the.styles.tsfile beside each. - StyleX's classes have the same specificity as a global
[data-slot]rule, and come after your CSS. So a rule of yours that sets a property a view's styles also set, such as an Availability recipe's background color, needs a stronger selector:[data-slot="time-grid-unavailable"][data-slot]. Or usexstyleor the tokens. - A fix to a view goes to both flavours. You get it the way you do for the baseline, by running
shadcn addfor the item again, which asks before it replaces a file you changed.