Skip to content

refactor(atoms): replace theme props with inherited surface tokens - #188

Merged
Ardnived merged 2 commits into
mainfrom
claude/refactor-focus-ring-utility
Oct 13, 2026
Merged

Ardnived merged 2 commits into
mainfrom
claude/refactor-focus-ring-utility

Conversation

@Ardnived

@Ardnived Ardnived commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • theme meant "what surface am I on" in all 11 components that took it, and each component kept its own light and dark colour maps. Those maps had drifted apart. Colours now come from the surface instead. surface-light (also :root) and surface-dark each set 13 tokens, and @theme inline exposes them as ordinary Tailwind colours: text-fg, text-fg-muted, text-primary, text-secondary, border-line, bg-tint, focus-ring, and so on. A component uses those classes and gets whichever surface it sits on. The nearest surface ancestor wins.
  • Atoms and molecules take no theme prop at all. Link, Button, Icon, Spinner, Breadcrumbs, Countdown, Header, HeaderNavDropdown and Logo lose it.
  • Only a component that paints a background sets a surface. OrnateTextBox is always dark, and the sticky nav turns light once it sticks. Splash, ContentOverlay and Ladle's StorySection keep a prop, renamed surface, because only SahajCloud's textColor knows whether their image is dark.

This started as the follow-up #134 deferred: moving the focus ring into a CSS @utility. The ring is the first token. The second commit moves the rest of the colours.

Changes

  • layouts/tailwind.css: the two surface utilities, the :root default, the @theme inline colour aliases, and @utility focus-ring.
  • components/atoms/surface.ts replaces focusRing.ts. It exports a Surface type and surface(), used only by the components that paint one.
  • Link, Icon, Spinner: each pair of light/dark colour maps becomes one map of tokens. Spinner's color now applies to the logo variant too.
  • Button: filled variants are the same on every surface, and outline and ghost use tokens. Its four maps become two. Its spinner draws in border-current, which replaces the getSpinnerColor and getSpinnerTheme helpers.
  • Breadcrumbs, Countdown, Header: text and borders use tokens. Header no longer passes theme={isSticky ? 'light' : theme} to every child. The nav sets surface-light once it sticks.
  • LayoutChrome puts the lead splash's surface on the header wrapper. lib/content-blocks.ts renames textColorToTheme to textColorToSurface and splashTheme to splashSurface, and { theme } becomes { surface }.
  • SocialIcon and the Splash call to action adopt focus-ring. SocialIcon's old teal-500 ring measured 2.70:1.
  • Stories: atoms drop theme. Dark wrappers get surface-dark (StorySection surface="dark", and the ad-hoc bg-gray-900 and bg-teal-600 boxes). Two dark-splash Header overlays in the Splash story never passed theme; they now render white.
  • Docs: a new Surfaces table in DESIGN_SYSTEM.md, and a Surfaces section in docs/rules/design-system.md. STORYBOOK.md, docs/rules/tailwind.md and the atoms README are updated.

Visual changes, deliberate

  • Neutral on dark is white everywhere. Link neutral was gray-300. Icon, Spinner, Button and Header were already white.
  • Secondary on light is coral-600 everywhere. Icon and Spinner used coral-500 (2.53:1). Neutral icons and spinners on light move from gray-600 to gray-700.
  • Dark text buttons no longer swap their hover fill. Primary and secondary are 500 to 600 on every surface. It used to be 600 to 500 on dark.
  • Spinners follow the button's own text colour. On a light background, the outline button's spinner is gray-700 instead of teal-600.
  • The breadcrumb separator uses border-line. On light that is gray-500 instead of gray-400. It is decorative and aria-hidden.

Test results

  • Lean gate: ✓ lint (0 errors, and no warnings in any changed file), tsc --noEmit, vitest run (87 files, 867 tests).
  • pnpm build ✓. The built CSS contains every token utility, both surfaces, and the :root defaults.
  • layouts/tailwind.test.ts compiles the real stylesheet and checks four things:
    • Tokens resolve at the element. It fails if @theme inline loses inline; mutation-checked.
    • All three surface blocks define the same tokens. It fails if one surface omits a token; mutation-checked.
    • focus-ring writes a box-shadow only on :focus-visible.
    • Every ring clears 3:1 against its band. It fails at 2.70 if light goes back to teal-500.
  • Specs check that Link and Button colour outline and ghost from tokens only, and never set a surface. They also check that the sticky Header nav sets surface-light.
  • I rendered the Button, Link, Spinner and Header stories in headless Chrome against a local Ladle. Dark sections draw white outline and ghost buttons, teal-300/coral-300/white links, and a white header with teal-300 breadcrumbs. Light sections are unchanged apart from the shifts listed above.

Manual verification

The screenshots don't cover keyboard focus or hover:

  1. In Ladle, Tab through the dark sections of Button and Link. You should see a white ring over a teal-900 band.
  2. Hover the dark outline buttons (expect a white fill with gray-800 text) and the ghost buttons (expect a 20% white tint).
  3. On a page with a dark lead splash, check that the header is white over the image, then turns gray on white once it sticks.
  4. Check OrnateTextBox and a dark ContentOverlay CTA on desktop. On mobile, the stacked ContentOverlay should stay light.

Notes for reviewer

  • Why not a React context. This "theme" only describes the surface behind an element, and CSS inheritance already resolves that. A provider would need the same container edits, plus a runtime read in every atom.
  • Why not a dark:-style custom variant. A descendant selector like "inside .surface-dark" still matches a light panel nested in a dark one. Inherited custom properties always pick the nearest surface.
  • Never put a surface on an interactive element. Its ring sits outside it, on the surface around it. That is why a filled Button uses border-current for its spinner instead of declaring itself dark.
  • fix(components): text and button colour pairings fail the 4.5:1 AA bar #179, which moves the light link and body text to steps that clear 4.5:1, now means changing one surface-light token each, rather than editing every component.
  • Not converted: the form fields, EmbedButton's textarea and Alert's dismiss button. Fields show focus on their border, so changing them is a design call.
  • /simplify, /pr-review-toolkit:review-pr and /security-review were not run. No path here matches the security trigger pattern.

Follows #134.

🤖 Generated with Claude Code

…prop

`focusRing(theme)` returned a class string per theme, so every component
that sat on a dark surface had to be told so, and `Logo` grew a `theme`
prop it used for nothing else. The ring now lives in `layouts/tailwind.css`
as `@utility focus-ring`, reading two inherited custom properties. `:root`
is light, and a container that paints a dark surface sets `surface-dark`
once.

- `Link` and `Button` claim a surface only when given a `theme`, so an
  unthemed atom inherits its container's instead of overriding it.
- `Header`, `Splash`, `OrnateTextBox` and Ladle's dark `StorySection` set
  their surface. `Logo` loses its `theme` prop, and `Button` no longer
  threads `theme` into its inner `Link`.
- `SocialIcon` and the `Splash` call to action adopt `focus-ring`.
  `SocialIcon`'s `teal-500` ring measured 2.70:1.
- `layouts/tailwind.test.ts` compiles the real stylesheet and fails if a
  ring drops under 3:1 against its offset band.

Follows #134.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: e9b826f
Status: ✅  Deploy successful!
Preview URL: https://710c93fe.wm-design.pages.dev
Branch Preview URL: https://claude-refactor-focus-ring-u.wm-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web e9b826f Commit Preview URL

Branch Preview URL
Oct 13 2026, 03:20 PM

The focus ring was the first colour to move into the surface. This moves
the rest. `surface-light` and `surface-dark` now set thirteen tokens, and
`@theme inline` exposes them as colours (`text-fg`, `text-fg-muted`,
`text-primary`, `text-secondary`, `border-line`, `bg-tint`, ...), so a
component resolves them against whatever surface it sits on.

- `Link`, `Button`, `Icon`, `Spinner`, `Breadcrumbs`, `Countdown`,
  `Header` and `HeaderNavDropdown` lose their `theme` prop, and their
  paired light/dark colour maps become one map.
- `Splash`, `ContentOverlay` and Ladle's `StorySection` keep a prop,
  renamed `surface`: only SahajCloud's `textColor` knows whether their
  image is dark. `lib/content-blocks.ts` inverts it once
  (`textColorToSurface`), and `LayoutChrome` sets the lead splash's
  surface on the header wrapper.
- Two drifts resolved: neutral is white on every dark surface (`Link`
  was `gray-300`), and secondary is `coral-600` on light (`Icon` and
  `Spinner` were `coral-500`, 2.53:1). Dark text buttons no longer swap
  their primary/secondary hover fill.
- `Button`'s spinner takes `border-current`, replacing two helpers that
  guessed a spinner colour per variant and theme.
- `layouts/tailwind.test.ts` now also fails if a token resolves at
  `:root` (dropping `inline`) or if one surface omits a token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Ardnived Ardnived changed the title refactor(atoms): colour the focus ring from the surface, not a theme prop refactor(atoms): replace theme props with inherited surface tokens Oct 13, 2026
@Ardnived
Ardnived merged commit 689f8b1 into main Oct 13, 2026
12 checks passed
@Ardnived
Ardnived deleted the claude/refactor-focus-ring-utility branch October 13, 2026 15:31
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Oct 13, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 13, 2026
#188 landed the surface-token refactor, which rewrote the one line this
branch also changed: `Splash`'s `<h1>`.

Both sides are kept. This branch replaced the dead `font-raleway` with
`font-sans`; `main` replaced the `${textColor}` prop with the `text-fg`
surface token and deleted the prop, so taking either side alone would
drop a fix or leave an undefined variable. The className is now a plain
string, since nothing is interpolated into it any more.

Every other file auto-merged. `@theme inline`, which #188 adds for the
surface tokens, needs no change to the new utility guard: it declares no
token on a numeric scale, and the guard already reads the whole
stylesheet rather than one `@theme` block.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D5B9zSNF2QsmUZVE9oT5Wx
sydevs-bot pushed a commit that referenced this pull request Oct 13, 2026
main's surface-token refactor (#188) and this branch's touch-target work both
rewrote `Button.test.tsx` and the custom-utility section of
`docs/rules/tailwind.md`.

- `Button.test.tsx`: both icon imports are kept, since both sides' cases need
  one. `focusClasses` goes with the per-variant ring tests main deleted — it
  had no other caller once `focus-ring` replaced the per-variant axis.
- `docs/rules/tailwind.md`: one utility list covering both sides —
  `focus-ring` and the `surface-*` pair from main, the touch-target pair from
  here. The emission-order ⚠ and main's closing rule both stay.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013W5aYCeine4RigrTLH6nYj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant