tech-debt: Pluggable themes: design tokens as a contract, components use tokens only
Back to our planType
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, 6black, 1red. Most are text and overlays on photos (text-whiteon heroes,bg-white/10glass panels,from-black/70scrims) - 8 hex or
rgba()values - 2 inline
style={{}}props
These ignore the theme and break in dark mode or under another theme.
- 39 Tailwind palette classes: 32
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.mdandskill-frontend-patterns.mdtell authors to usetext-white,bg-white/10andblack/…scrims, so they must change with the code.
Proposed fix
src/platform/theme/.tokens.ts: the contract, anas constlist of semantic token names (background, foreground, primary, primary-foreground, accent, surface, muted, muted-foreground, border, ring, destructive, pluson-imagefor text on photos andscrimfor overlays on photos) with a one-line meaning for each.tailwind.css: the@theme inlinemapping from tokens to Tailwind utilities. It doesn't change between themes.
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).- A contract test (
themes.test.ts). It parses everysrc/themes/*/theme.cssand fails if a token fromtokens.tsis missing in light or dark. It also checks text and background pairs against WCAG AA contrast (4.5:1). - Replace the 39 palette classes, 8 hex values and 2 inline styles with tokens:
text-whiteon photos →text-on-image,black/…andwhite/…overlays →scrimandon-imagewith opacity, the onered→destructive. Update the two design rule files to match. - Guardrail. A lint check (ESLint
no-restricted-syntaxon class strings, or the doc/agent checker from #145) rejects raw palette classes and hex colors in components. - Variants in one place. Button and card variants stay in the
platform/uiprimitives (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.cssonly imports the platform theme mapping, the active theme and base styles. - Not done:
src/themes/default/theme.cssholds 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.mdandskill-frontend-patterns.mduse 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