theming

Use when an app uses @pierre/theming to list, resolve, select, switch, persist, or apply themes, including color modes, theme controllers, React state, UI colors, and bundled Pierre or Shiki collections.

Install
npx skills add 'https://github.com/pierrecomputer/pierre/tree/main/skills/theming'
Download bundle ↓
main · 1831817Scanned 2026-09-15

Contributors

GitHub-linked commit authors for this SKILL.md at the saved revision. Co-authors and history before file renames are not included.

File history ↗
View on GitHub
← Back to SKILL.md

Recipe: use a theme controller in vanilla JavaScript

Create a controller with the one-controller or multiple-controller recipe. Apply each state change to the document:

import { normalizeThemeColors } from '@pierre/theming/color';
import { themeController } from './theme-controller';

function applyTheme() {
  const state = themeController.getState();
  document.documentElement.dataset.colorScheme = state.resolvedColorScheme;

  if (state.resolvedTheme == null) return;
  const { colors } = normalizeThemeColors(state.resolvedTheme);
  document.documentElement.style.setProperty(
    '--app-background',
    colors?.['editor.background'] ?? state.resolvedTheme.bg ?? ''
  );
  document.documentElement.style.setProperty(
    '--app-foreground',
    colors?.['editor.foreground'] ?? state.resolvedTheme.fg ?? ''
  );
}

applyTheme();
const unsubscribe = themeController.subscribe(applyTheme);

Call themeController.setColorMode(mode) from a mode control. Call setThemeNameForScheme(scheme, name) from a theme selector. Call unsubscribe() when the host no longer needs updates.

Referenced from SKILL.md