Skip to content
SprecherEast
Issue 146

tech-debt: Pluggable themes: design tokens as a contract, components use tokens only

Back to our plan
Done
frontendstylingtech-debtpriority: high

Type

tech-debt

Summary

Separate the site's look (colors, fonts, corner rounding, shadows) from its code, so a different theme can be dropped in by swapping one file. All components will use named design tokens such as "primary" or "muted text" instead of specific colors. An automated check will make sure every theme defines every token in light and dark mode, and lint will keep raw colors from creeping back.

Problem

Measured on main at 190cb3d:

  • One file does too much. src/app/(frontend)/globals.css (237 lines) mixes three things: Tailwind setup, the token values for light and dark (:root / [data-theme='dark']), and base styles. A theme can't be swapped without editing it.

  • Components bypass the tokens:

    • 39 Tailwind palette classes: 32 white, 6 black, 1 red. Most are text and overlays on photos (text-white on heroes, bg-white/10 glass panels, from-black/70 scrims)
    • 8 hex or rgba() values
    • 2 inline style={{}} props

    These ignore the theme and break in dark mode or under another theme.

  • No written contract. Nothing lists which tokens a theme must define, so a new theme can silently miss one.

  • The design rules prescribe raw colors. .claude/rules/skill-ui-ux-design.md and skill-frontend-patterns.md tell authors to use text-white, bg-white/10 and black/… scrims, so they must change with the code.

Proposed fix

  1. src/platform/theme/.
    • tokens.ts: the contract, an as const list of semantic token names (background, foreground, primary, primary-foreground, accent, surface, muted, muted-foreground, border, ring, destructive, plus on-image for text on photos and scrim for overlays on photos) with a one-line meaning for each.
    • tailwind.css: the @theme inline mapping from tokens to Tailwind utilities. It doesn't change between themes.
  2. src/themes/default/theme.css. Today's values for light and dark, moved unchanged. Only this one folder is created; a second theme would be a second folder defining the same variables, chosen in one place (the frontend layout's CSS import).
  3. A contract test (themes.test.ts). It parses every src/themes/*/theme.css and fails if a token from tokens.ts is missing in light or dark. It also checks text and background pairs against WCAG AA contrast (4.5:1).
  4. Replace the 39 palette classes, 8 hex values and 2 inline styles with tokens: text-white on photos → text-on-image, black/… and white/… overlays → scrim and on-image with opacity, the one red → destructive. Update the two design rule files to match.
  5. Guardrail. A lint check (ESLint no-restricted-syntax on class strings, or the doc/agent checker from #145) rejects raw palette classes and hex colors in components.
  6. Variants in one place. Button and card variants stay in the platform/ui primitives (cva). Feature components compose primitives, so a theme changes how they look without editing them.

Out of scope: switching themes at runtime beyond light and dark, and theming the Payload admin.

Acceptance criteria

  • Not done: globals.css only imports the platform theme mapping, the active theme and base styles.
  • Not done: src/themes/default/theme.css holds all token values; the site looks the same in both modes (screenshots at the 6 test widths, light and dark, in the PR).
  • Not done: The contract test passes, and fails when a token is removed from the theme (shown in the PR).
  • Not done: No raw palette classes, hex colors or inline styles in components; lint fails on a new one.
  • Not done: skill-ui-ux-design.md and skill-frontend-patterns.md use the tokens in their rules and snippets (policy files: owner sign-off).
  • Not done: A second, throwaway theme folder swapped in locally changes the look with no component edits (screenshot in the PR, not committed).

Depends on

#142 (architecture docs, decision 0006), #130 (lint guardrails). Part of #127; can run in parallel with the module moves.

Area

frontend, styling

Priority

medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab