refract v0.1 · beta
Cookbook / Theming a component library

Theming a component library

refract contributes two things — CSS variables (tokens) and classes (recipes). How you theme a third-party library depends on which one it consumes.

Libraries driven by CSS variables

Most modern libraries expose their design tokens as CSS custom properties (--lib-primary, …). Point them at refract's tokens with a thin bridge — refract owns the values, the library keeps its API:

bridge.css
/* map the library's variable names → refract's tokens */
:root {
  --lib-primary: var(--dt-colors-brand);
  --lib-on-primary: var(--dt-colors-brand-text);
  --lib-radius: var(--dt-borders-radius-base);
}

Because these are var() references, the library re-themes automatically when refract's tokens change — including dark mode and override(). If the library lets you set its variable prefix, you can even set refract's adapter prefix to match and skip the bridge.

Libraries driven by their own classes

If a component ships fixed styles under its own classes, refract's classes can't restyle it from outside (its own CSS wins). Two options: feed the library's theme API with resolved values via theme.resolveToken("colors.brand"), or wrap the component and apply a refract class to your element around it.

Prefer the variable bridge when you can — it stays reactive. resolveToken returns a frozen literal (see the React inline-styles note), so a value you pass to a library's JS theme API won't auto-flip; re-read it when the theme changes.
Technical documentation for @theme-registry/refract · all output is compiled client-side by the real library (CSS adapter). The chrome is theme-aware; the render panes carry each preset's own world. · MIT licensed.