Themvora + Bootstrap
@themvora/bootstrap
Compile Bootstrap 5 with Themvora semantic tokens through a CSS-variable adapter that refreshes variables as themes change.
Pick your framework
The adapter writes Bootstrap's own CSS custom properties from Themvora semantic tokens, so Bootstrap'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 Bootstrap'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 bootstrappnpm add @themvora/core @themvora/react @themvora/bootstrapHow it works
Themvora writes Bootstrap's own CSS custom properties from its tokens, and Bootstrap'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
Bootstrap wired up for React. Switch the picker above and everything below changes with it.
import { useThemeRuntime } from "@themvora/react";
import { useBootstrapTheme } from "@themvora/bootstrap/react";
export function InstallAdapter() {
useBootstrapTheme(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/bootstrap/bootstrap.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 Bootstrap components
import "@themvora/bootstrap/bootstrap.css";
export function Example() {
return (
<div className="card">
<div className="card-body">
<h5 className="card-title">Themvora + Bootstrap</h5>
<button type="button" className="btn btn-primary">Primary action</button>
</div>
</div>
);
}These are ordinary Bootstrap components. No Themvora-specific props are required — the theme reaches them through Bootstrap'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 Bootstrap.
Themvora owns the theme. The adapter derives the Bootstraptheme 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 Bootstrap 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 { useBootstrapTheme } from "@themvora/bootstrap/react";
import "@themvora/bootstrap/bootstrap.css";
import { Example } from "./Example";
// No provider to mount: the hook registers the adapter, which writes
// Bootstrap's own CSS variables. The stylesheet import above applies them.
function ThemeZone() {
useBootstrapTheme(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 | Bootstrap |
|---|---|
| primary | --bs-primary |
| secondary | --bs-secondary |
| destructive | --bs-danger |
| background | --bs-body-bg |
| foreground | --bs-body-color |
| border | --bs-border-color |
| radius | --bs-border-radius |
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/bootstrap/bootstrap.css";What's Available
@themvora/bootstrap 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
The adapter generates --bs-* variables from the active theme.
import { createThemeRuntime } from "@themvora/core";
import { createBootstrapAdapter } from "@themvora/bootstrap";
const runtime = createThemeRuntime();
runtime.adapters.use(createBootstrapAdapter());Toggle Bootstrap dark mode
Variables update automatically when the active mode flips.
// The adapter is already registered — switching the mode
// repaints every --bs-* variable on the runtime:
runtime.selection.setMode("dark");
runtime.selection.setMode("light");More Examples
Static variable maps for build-time CSS, and manual adapter lifecycle control.
import { createBootstrapVariables } from "@themvora/bootstrap";
import { getBuiltInThemes } from "@themvora/core";
// Pass the token set — a `{ family, mode }` pair is not a ThemeTokens and
// silently yields empty values ("--bs-body-bg": "").
const [theme] = getBuiltInThemes();
const css = createBootstrapVariables(theme.tokens!);
// css -> { "--bs-body-bg": "#f8fafc", "--bs-body-color": "#0f172a", … }API Reference
Adapter
| Export | Description |
|---|---|
createBootstrapAdapter(options) | Maintains a tagged :root style element with concrete Bootstrap variables, including derived color pairs, kept in sync at runtime. |
createBootstrapVariables(tokens) | Produces the concrete Bootstrap CSS custom-property map from a token set (theme.tokens) — no DOM required. A theme definition leaves the derived color pairs empty. |
useBootstrapTheme(runtime, options?) | React hook (from @themvora/bootstrap/react) that installs and disposes the adapter on the current runtime. |
injectBootstrapCSS() | SSR-safe, idempotent helper that injects Bootstrap compatibility CSS on first use. |
Options
| Export | Description |
|---|---|
CreateBootstrapAdapterOptions | Accepts strategy to customize how tokens become Bootstrap variables. |
BootstrapAdapterOptions | Options covering derived-color handling (e.g. primary/tint pairs) and defaults. |