Themvora + Open Props
@themvora/open-props
Expose Themvora semantic tokens as Open Props style variables for any design that uses CSS custom properties.
Pick your framework
The adapter writes Open Props's own CSS custom properties from Themvora semantic tokens, so Open Props's classes and components follow the active theme. Pick the framework you are building in — every snippet below follows that choice.
Installation
Two installs. The first is Open Props's own — see its installation guide if you need more than this. The second is Themvora, and it names the runtime package for React.
pnpm add open-propspnpm add @themvora/core @themvora/react @themvora/open-propsHow it works
Themvora writes Open Props's own CSS custom properties from its tokens, and Open Props's stylesheet consumes them. Nothing is rebuilt on a theme change — the variables change and the styles follow. That is why this adapter is a hook that registers a writer rather than a provider component, and why it also needs its stylesheet imported.
Quick Start
Open Props wired up for React. Switch the picker above and everything below changes with it.
import { useThemeRuntime } from "@themvora/react";
import { useOpenPropsTheme } from "@themvora/open-props/react";
export function InstallAdapter() {
useOpenPropsTheme(useThemeRuntime());
return null;
}Mount the provider
Themvora's provider owns the active theme. Drop this at your app root — everything below it can read and change the theme, and the bridge above picks up each change automatically.
import { ThemeProvider } from "@themvora/react";
import "@themvora/open-props/open-props.css";
import { App as Page } from "./Page";
import { InstallAdapter } from "./components/InstallAdapter";
export default function App() {
return (
<ThemeProvider defaultTheme="plum-light" initialMode="system">
<InstallAdapter />
<Page />
</ThemeProvider>
);
}Use Open Props components
import "@themvora/open-props/open-props.css";
export function Example() {
return (
<div className="surface">
<h2>Themvora + Open Props</h2>
<button className="primary">Primary action</button>
</div>
);
}These are ordinary Open Props components. No Themvora-specific props are required — the theme reaches them through Open Props's own mechanism.
Theme switching
The point of an adapter is that this is the only code that changes — the components stay exactly as they are.
import { useTheme } from "@themvora/react";
export function ThemeControls() {
const { setMode, toggleTheme } = useTheme();
return (
<>
<button type="button" onClick={() => toggleTheme()}>Toggle</button>
<button type="button" onClick={() => setMode("light")}>Light</button>
<button type="button" onClick={() => setMode("dark")}>Dark</button>
</>
);
}Before and after
You own the theme object. You choose the colours, keep them in step with your design tokens by hand, write the dark variant yourself, and rebuild the object whenever anything changes. Every new token has to be added twice — once to your design system and once to Open Props.
Themvora owns the theme. The adapter derives the Open Propstheme from Themvora's tokens and rebuilds it whenever the active theme changes — switching family or mode, or a persisted preference resolving on load. There is no second place to update, because there is no second theme.
Your components stay Open Props components. Themvora becomes the source of the active theme.
A complete example
Everything together for React. Paste it in and it runs.
import { ThemeProvider, useThemeRuntime } from "@themvora/react";
import { useOpenPropsTheme } from "@themvora/open-props/react";
import "@themvora/open-props/open-props.css";
import { Example } from "./Example";
// No provider to mount: the hook registers the adapter, which writes
// Open Props's own CSS variables. The stylesheet import above applies them.
function ThemeZone() {
useOpenPropsTheme(useThemeRuntime());
return <Example />;
}
export default function App() {
return (
<ThemeProvider defaultTheme="plum-light" initialMode="system">
<ThemeZone />
</ThemeProvider>
);
}What gets mapped
Themvora owns the meaning; the adapter owns the vocabulary.
| Themvora | Open Props |
|---|---|
| background | --color-background |
| foreground | --color-foreground |
| card | --color-canvas |
| muted | --color-muted |
| mutedForeground | --color-muted-foreground |
| primary | --color-primary |
| secondary | --color-secondary |
| accent | --color-accent |
| destructive | --color-danger |
| border | --color-border |
Include the CSS
The adapter ships a stylesheet that maps its component variables (e.g. --primary for shadcn/ui, --bs-primary for Bootstrap) to the themvora --theme-color-* tokens. Import it once — anywhere — and the library's components will respond to every theme change automatically.
import "@themvora/open-props/open-props.css";What's Available
@themvora/open-props ships 6 exports in 2 categories. Click any export to reveal what it does and how to use it.
Adapter
Options
Use Cases
The important features in practice — copy any of these straight into your app.
Mount the adapter on the runtime
Register the Open Props adapter on an existing runtime.
import { createThemeRuntime } from "@themvora/core";
import { createOpenPropsAdapter } from "@themvora/open-props";
const runtime = createThemeRuntime();
runtime.adapters.use(createOpenPropsAdapter());Reference Open Props variables in CSS
Use --op-* tokens that update as the theme changes.
.banner {
background: var(--op-primary);
color: var(--op-on-primary);
border-radius: var(--op-radius-md);
}More Examples
Static variable maps for build-time CSS, and manual adapter lifecycle control.
import { createOpenPropsVariables } from "@themvora/open-props";
import { getBuiltInThemes } from "@themvora/core";
const [theme] = getBuiltInThemes();
const css = createOpenPropsVariables(theme.tokens!);
// css -> { "--color-canvas": "#f8fafc", "--color-text": "#0f172a", … }API Reference
Adapter
| Export | Description |
|---|---|
createOpenPropsAdapter(options) | Installs a tagged :root style element with concrete --op-* variables updated as the theme changes. |
createOpenPropsVariables(tokens) | Builds the Open Props variable map from a token set (theme.tokens). A theme definition leaves the color entries empty. |
useOpenPropsTheme(runtime, options?) | React hook (from @themvora/open-props/react) that installs the Open Props adapter onto an explicit runtime. |
injectOpenPropsCSS() | Idempotent, SSR-safe helper for injecting Open Props compatibility CSS. |
Options
| Export | Description |
|---|---|
CreateOpenPropsAdapterOptions | Accepts strategy to customize token→variable mapping. |
OpenPropsAdapterOptions | Options for Open Props variable derivation and defaults. |