Skip to content

feat(elements): light and dark color schemes - #287

Merged
seanrcollings merged 31 commits into
mainfrom
feat/color-schemes
Nov 20, 2026
Merged

seanrcollings merged 31 commits into
mainfrom
feat/color-schemes

Conversation

@seanrcollings

Copy link
Copy Markdown
Contributor

Stacked on #286 (semantic color tokens). Review and merge that first; this PR's base is feat/semantic-color-tokens, so the diff only shows the color-scheme work.

Adds named color schemes to atomic-elements and ships a dark scheme alongside today's light look. Apps stay light unless they opt in. Ships as a minor release.

Using it

<ElementsProvider colorScheme="dark">…</ElementsProvider>       // or "system" to follow the OS
const { resolvedColorScheme, setColorScheme } = useColorScheme(); // toggle from anywhere

The provider sets data-color-scheme on <html>, and the theme's CSS variables switch. The library doesn't store the user's choice; apps pass colorScheme + onColorSchemeChange (or defaultColorScheme). Docs: packages/atomic-elements/docs/Theme/ColorSchemes.mdx.

What changed

  • createTheme takes colorSchemes.
    • Each scheme has a mode and only the tokens it overrides.
    • light (or the first scheme) is the base. Other schemes emit [data-color-scheme="x"] blocks on top of it.
    • Values in a theme's shared variables win over a base theme's scheme values, so existing themes keep working in dark.
    • New Theme fields: baseColorScheme, colorSchemes.
  • defaultTheme: semantic tokens move into a light scheme (values unchanged), and a new dark scheme overrides them.
  • ElementsProvider gains colorScheme, defaultColorScheme and onColorSchemeChange.
    • "system" follows the OS setting live.
    • One provider per page: nested providers follow the outer one, and a second top-level provider logs a warning.
    • With applyDefaultStyles, the page background follows non-light schemes. Light pages are unchanged.
  • New useColorScheme() hook.
  • New tokens.
    • Fill tokens for solid backgrounds behind white text: accent-clr-fill, {error,warning,success}-clr-fill and their -hover variants. Buttons, selected items and checked controls use them. Same shades in light.
    • info-clr-icon for the info banner icon.
    • background-clr-disabled for disabled tabs.
  • Storybook.
    • A toolbar switch (Light / Dark / System).
    • On overview pages, only the story boxes follow the scheme.
    • The @ljcl/storybook-addon-cssprops addon is replaced by a read-only CSS Variables table. The addon wrote saved values onto the page <body>, which pinned them over the dark scheme.
  • Docs site: one ElementsProvider at the Docusaurus root (docs/src/theme/Root.tsx), replacing one per example.

Tests

  • theme.spec.ts:
    • CSS output for :root, a custom selector and selector lists;
    • the merge rule, and themes built without the new fields;
    • errors for a scheme with no mode and for unknown token references.
  • contrast.spec.ts: WCAG AA in every scheme for the text/background pairs components render, including chips, checkboxes, calendar, tooltip and banner icons.
  • semantic.spec.ts:
    • dark key values, and that dark overrides the deprecated source names;
    • consumer overrides still reach components in dark;
    • hover and active colors differ from their surfaces in every scheme.
  • ElementsProvider.spec.tsx / colorScheme.spec.ts:
    • controlled and uncontrolled modes;
    • live "system" switching;
    • the nested and duplicate-provider rules;
    • adding and removing the attribute;
    • body rules only for non-light schemes.

Please check in Storybook (toolbar → Dark)

Chip (selected), Banner (all variants), Calendar (selected and invalid dates), Menu and Select (hover, section titles), Tabs (disabled), Table, Tooltip, Modal, ScrollArea. The dark values and a light/dark contrast table for every pair are in docs/superpowers/plans/2026-11-19-color-schemes-visual-changes.md.

Light-mode changes

  • Invalid floating-label text: error600 (was error800).
  • Invalid calendar date: error700 with white text (was error600 with dark text). Contrast goes from 3.05:1 to 6.41:1.
  • Menu section titles: small bold uppercase headings, matching ListBox section titles. They were light-grey regular text.

Known limitations

  • A brand theme that overrides accent-clr only in shared variables keeps the library's dark fill on buttons in dark. The docs say to set accent colors per scheme.
  • With "system" on server-rendered pages, the first paint can briefly be light.
  • Autodocs pages log "only one ElementsProvider" warnings, because each inline story gets its own provider.
  • The warning and success banner icons are slightly below 3:1 contrast in light (2.79 and 2.87). That's today's look and isn't changed here.

🤖 Generated with Claude Code

@seanrcollings
seanrcollings added this pull request to stack #288 November 19, 2026 23:14
Base automatically changed from feat/semantic-color-tokens to main November 20, 2026 17:34
seanrcollings and others added 27 commits November 20, 2026 10:34
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also fix non-base schemes resolving without the base scheme's values:
scheme blocks layer on top of the base block in CSS, so their resolved
maps now do too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Selected chip text uses text-clr-on-accent (was dark on dark in dark)
- Info banner icon gets an info-clr-icon token readable in both schemes
- Invalid calendar cell uses error-clr-fill with on-accent text
- Scope every part of a cssVarsSelector list to the scheme, so dark
  values are never applied unconditionally
- Accept base themes without sharedVariables/colorSchemes
- Contrast tests cover component token pairs and banner icons

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces the docs-theme switch: the overview page keeps Storybook's own
theme and only the .docs-story preview boxes take the scheme's
background and text color.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dark background-clr-hover matched background-clr-raised (neutral800), so
menu and listbox items showed no hover. Use neutral700 and test that
hover/active surfaces differ from what they sit on in every scheme.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Section titles were an inline span (vertical margins ignored) in light
grey regular text, so they read like disabled items. Make them small
bold uppercase headings in text-clr-secondary, matching ListBox, and
drop the now-unused text-clr-tertiary token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The addon wrote every documented variable onto the docs page <body> as
inline styles (and restored saved values from local storage), which
pinned them over the active color scheme on overview pages. Show the
same data with Storybook's ArgsTable instead, read-only, and remove the
addon.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Matches the old addon, which rendered the table without a heading.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also keeps the "CSS Variables" subheading and drops unused imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Like the semantic token baseline it only guarded the migration; the
contrast tests cover the values that matter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ElementsProvider keeps the same props and renders ColorSchemeProvider,
which owns scheme resolution, the <html> attribute, the nested and
duplicate-provider rules and useColorScheme.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
onColorSchemeChange now fires only when the scheme actually changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every theme comes from createTheme, which always sets sharedVariables
and colorSchemes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…heme helpers

Variables always live on :root. The prefix never worked because
components read unprefixed variable names. Also drop Theme.getVarName
and per-scheme resolvedVariables, which only tests used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
seanrcollings and others added 3 commits November 20, 2026 10:34
…r shared variables

light always exists and applies when no scheme is selected, so the
first-scheme fallback and Theme.baseColorScheme go. A theme's shared
variables no longer override its base theme's scheme values: color
overrides belong under colorSchemes.light / .dark. Docs and changeset
call out the change for custom themes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Share one alias pattern between toCssValue and the alias check
- Rename ResolvedColorScheme to ColorScheme and reuse it internally
- Document what each Theme variable map is for
- The :root block is always color-scheme: light
- Fix the 'default-valu' typo; Prettier formatting

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and isToken

Theme.variables now holds the shared tokens (was sharedVariables).
isToken() replaces the every-token map for the $color/$bg props.
getVar, getVarValue and resolvedVariables are gone: callers write
var(--name) directly and the Storybook generator resolves defaults
itself (output unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@seanrcollings
seanrcollings merged commit 155a0d0 into main Nov 20, 2026
1 check passed
@seanrcollings
seanrcollings deleted the feat/color-schemes branch November 20, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants