Repository navigation
feat(core): theme component overrides take @light and @dark blocks that apply in one color mode - #11679
Conversation
…at apply only in their color mode A style key's @light or @dark block (properties and pseudo-class overrides) compiles to rules that match only where the element's color mode is that mode: the theme root's data-theme, the system preference when the root sets none, and a media surface of that mode, the nearest deciding. The rules add no specificity and follow the style key's own, so in the other mode the block writes nothing and every other rule, the rules Core gives a component in context included, applies as without it. Mode blocks get the style key's derived variables and container padding, merge per property through extends, and on a media surface only the surface's own mode is written. Themes without blocks compile to the same CSS.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This pull request needs an engineering owner's decision on its new theme-record claims, and it has blocking defects to fix.
It adds new normative claims to architecture:theme-authoring-contract (INV16 and a sentence in INV6) and architecture:theme-compilation (INV18), so approval waits on an engineering owner approving or amending them by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. That decision also covers the widened public StyleOverrides type.
- Numeric declaration values such as
fontWeight: 600oropacity: 0.9are now dropped silently becausesplitStyleBlockaccepts only strings (generateThemeRules.ts:1486-1490), so existing JavaScript themes lose declarations and CI'sbuild-theme.variants.test.mjs:232fails; keep the previous string coercion for non-object values. :activeand pseudo-element overrides inside a@light/@darkblock compile to selectors that match nothing, because the regular expression incolorModeRulesFor(generateThemeRules.ts:1617-1621) rewrites the@medialine of a press rule and wraps pseudo-elements in:is(), so build the mode conditions on the base selector before the pseudo is added and test both cases.- With a
Thememodeother thanlight,darkorsystem, neither block applies even though Core follows the platform's mode there, contradictingarchitecture:theme-applicationINV7, so key the system condition on:not([data-theme="light"], [data-theme="dark"])(generateThemeRules.ts:1627-1630). - Every page that renders
Themegains 457 B gzip of first-load JavaScript (theThemeentry goes from 25,861 B to 26,318 B with no blocks in use), over the 0.3 KB thatarchitecture:component-import-boundariesINV10 allows an unused optional feature, and the description reports no delta. - The new Chromium spec fails CI:
typecheckreports TS2769 at lines 90, 173, 177 and 182 because children are passed as spread arguments toThemeandMediaTheme, andComponent accessibility contractscannot load the spec because it imports Core's built package, which that job does not build. - The description announces a new
StyleBlocktype, but neither@astryxdesign/corenor@astryxdesign/core/themeexports it, so export it or reword the description.
Approval also needs the evidence the theme records' change-coupling rules ask for: a runtime-mounting and a CLI-built test of a theme with blocks, and merge cases for generated and onDark/onLight composition.
Claims and files checked
- Claim: blocks hold properties and pseudo-class overrides that apply only in their mode. Partly false:
:activeand pseudo-element overrides never match (generateThemeRules.ts:1617-1621, compiled output and Chromium's parsed selectors). - Claim: the mode follows Theme's own mode, the system preference or a MediaTheme surface. Partly false: an unknown
modeturns both blocks off (generateThemeRules.ts:1627-1630, Chromium probe). - Claim: in the other mode a block writes nothing and can carry any value. Verified (the pull request's Chromium spec passes 4/4 after a local build; Storybook frames).
- Claim: themes without blocks compile to the same CSS. False for numeric values:
opacity: 0.9vanishes from built CSS and a numeric-only Heading type fails to build; the seven shipped themes, which use only strings, are byte-identical. - Claim:
light-dark()writes both modes and overrides Core's contextual rules. Verified (rebuilt in Chromium: Pagination's light current page and the dark error border both change). - Claim: new
StyleBlockandStyleOverridestypes. Partly false:StyleBlockis not exported (theme/index.ts:45) andStyleOverridesis changed, not new. - Claim: merging handles blocks per property. Verified (
colorModeBlocks.test.ts:79-88,mergeComponents.ts:54-63). - Claim: blocks follow their style key's rules with no added specificity. Verified (
colorModeBlocks.test.ts:24-44). - Claim: pseudo-class and press rules in a block get the same conditions. False for press (
:active) rules. - Claim: on a surface only that surface's own block is written. Verified (
colorModeBlocks.test.ts:60-77). - Claim: blocks share derived-variable and container expansion. Verified (
colorModeBlocks.test.ts:46-58). - Claim: the unit and Chromium suites, knowledge check, eslint, prettier and changesets pass. The named suites pass locally (666 Vitest tests), as do the knowledge check, eslint and prettier; CI
typecheckandComponent accessibility contractsfail on the new spec andtest-nodefails the CLI variants test. - Claim: the records contain no narration, references or project status. Verified (INV16, INV18 and the verification rows read in the present tense).
- File
.changeset/theme-color-mode-blocks.md: overstates as above. - File
docs/architecture/theme-authoring-contract.md: new INV16 and INV6 sentence await an engineering owner. - File
docs/architecture/theme-compilation.md: new INV18 awaits an engineering owner. - File
packages/core/src/theme/__tests__/colorModeBlocks.a11y.chromium.spec.ts: fails CI typecheck and the accessibility contracts job. - File
packages/core/src/theme/colorModeBlocks.test.ts: clear; no:active, pseudo-element or unknown-mode case. - File
packages/core/src/theme/defineTheme.ts:StyleBlocknot exported. - File
packages/core/src/theme/generateThemeRules.ts: the numeric-value,:active/pseudo-element, unknown-mode and first-load findings. - File
packages/core/src/theme/mergeComponents.ts: clear.
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Markdown | 201.2 kB (+4 B) · 21.7 kB CSS (0) | — | — · — · — |
| CodeBlock | 79.9 kB (0) · 12.1 kB CSS (0) | — | — · — · — |
| Lightbox | 145.2 kB (0) · 11.9 kB CSS (0) | — | — · — · — |
13 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Overlay | 23.0 kB (0) · 3.9 kB CSS (0) | — | — · — · — |
| Toast | 103.3 kB (0) · 11.1 kB CSS (0) | — | — · — · — |
| lab/CodeEditor | 14.5 kB (0) · 743 B CSS (0) | — | — · — · — |
| lab/CommentComposer | 161.8 kB (0) · 1.9 kB CSS (0) | — | — · — · — |
| lab/DiffViewer | 92.8 kB (0) · 2.1 kB CSS (0) | — | — · — · — |
| lab/ListInput | 93.4 kB (0) · 922 B CSS (0) | — | — · — · — |
| richtext/RichTextEditor | 305.3 kB (0) · 2.6 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 298.5 kB (0) · 454 B CSS (0) | — | — · — · — |
| richtext/RichTextView | 281.9 kB (0) · 2.3 kB CSS (0) | — | — · — · — |
| lab/Comments | 367.6 kB (−4 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 360.3 kB (−4 B) · 2.4 kB CSS (0) | — | — · — · — |
| lab/DialogHeroHeader | 88.4 kB (−4 B) · 372 B CSS (0) | — | — · — · — |
| charts/Chart | 237.2 kB (−13 B) · 516 B CSS (0) | — | — · — · — |
Package size:
- @astryxdesign/cli 4.37 MB packed (+128 B); no new dependencies
- @astryxdesign/core 7.56 MB packed (+3.6 kB); no new dependencies
API changes: core +2 · ~1 · −0
3 API changes (advisory)
| Package | Where | Signature | Usage | |
|---|---|---|---|---|
| + | core |
. · Types · type StyleBlock |
type StyleBlock = Record<string, string | Record<string, string>> |
import type {StyleBlock} from '@astryxdesign/core' |
| + | core |
./theme · Also exported from an earlier entry point · StyleBlock |
StyleBlock (.) |
import {StyleBlock} from '@astryxdesign/core/theme' |
| ~ | core |
. · Types · type StyleOverrides |
type StyleOverrides = Record<string, string | Record<string, string>> → type StyleOverrides = Record<string, string | Record<string, string> | StyleBlock> |
import type {StyleOverrides} from '@astryxdesign/core' |
Wide change (shared styles: packages/core/src/theme/defineTheme.ts, packages/core/src/theme/generateThemeRules.ts, packages/core/src/theme/index.ts, and 1 more): add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
|
/approve-spec 84cad8b |
…ders through Storybook A style key's declarations are written as text again whatever their JavaScript type, so a theme that gives a number (fontWeight: 600) keeps it, in a mode block too. The browser spec renders the ColorModeBlocks story from the built Storybook, as the other Core accessibility specs do, instead of importing Core's build.
|
/approve-spec 0823e3a |
There was a problem hiding this comment.
Changes are needed before approval: an engineering owner has approved the @light/@dark theme contract, but the compiler has five defects and two required tests are missing.
:activeand pseudo-element overrides inside a block never apply, because the regular expression incolorModeRulesFor(generateThemeRules.ts:1619) takes a press rule's@medialine as its selector and puts pseudo-elements inside:is(), so add the mode conditions to the base selector beforepseudoRulesappends the pseudo, and test both cases.- A
Thememode other thanlight,darkorsystemturns both blocks off although Core renders it from the system preference, which contradictsarchitecture:theme-applicationINV7, so key the system condition on:scope:not([data-theme="light"], [data-theme="dark"])(generateThemeRules.ts:1628). - Miss: inside a third alternating surface (a light
Theme, then dark, light and dark surfaces) neither block applies, because the exclusions atgenerateThemeRules.ts:1623-1631cannot express the "nearest deciding" rule that INV18 states, so scope the surface condition by proximity (for example a nested@scope ([data-astryx-media="dark"]) to ([data-astryx-media="light"])) and test it. - Every page that renders
Themegains 459 B gzip of first-load JavaScript without using blocks (theThemeentry goes from 29,996 B to 30,455 B), over the 0.3 KB thatarchitecture:component-import-boundariesINV10 allows an unused optional feature, and the description reports no delta. - The description calls
StyleBlocka new type and the publicStyleOverridesrefers to it, but neither@astryxdesign/corenor@astryxdesign/core/themeexports it, so export it or reword the description. architecture:theme-compilationrequires a CLI-built test for any change to how a theme becomes CSS, and the pull request has none for a theme with blocks.architecture:theme-authoring-contractrequires a merge change to verify generated and on-media composition, and the merge test covers only anextendsoverride.
The numeric-value, typecheck and accessibility-job problems from the last review are fixed at this head.
Claims and files checked
- Claim: blocks hold properties and pseudo-class overrides that apply only in their mode. Partly false:
:activeand pseudo-element overrides never apply (Chromium probe of the compiled rules). - Claim: blocks follow the Theme's mode, the system preference, a nested Theme or a MediaTheme surface. Partly false: an unknown mode and a third alternating surface lose the block; the covered cases pass (the pull request's Chromium spec, 4 of 4).
- Claim: in the other mode a block writes nothing and leaves Core's contextual looks. Verified (story probe: the light current-page fill and the dark error border are unchanged).
- Claim: a block can carry any value, not only a color. Verified (padding, radius and numeric values in the tests and a probe).
- Claim: themes without blocks compile to the same CSS. Verified (the seven shipped theme stylesheets are byte-identical before and after).
- Claim:
light-dark()writes both modes and overrides Core's contextual looks. Verified (story probe: the light current-page fill and the dark error border both change). - Claim: new
StyleBlockandStyleOverridestypes with docs. Partly false:StyleBlockis not exported, andStyleOverridesis changed, not new. - Claim: merging handles blocks per property. Verified (
mergeComponents.ts:54-61and the merge test). - Claim: blocks follow their style key's rules with no added specificity. Verified (compiled output and the unit test).
- Claim: pseudo-class and press rules in a block get the same conditions. False for press (
:active) rules. - Claim: on a surface only that surface's own block is written. Verified (unit test and a probe).
- Claim: blocks share the derived-variable and container expansion. Verified (unit test and a card padding probe).
- Claim: the unit and Chromium suites, knowledge check, lint, formatting and changesets pass. Verified (theme and CLI theme suites, the Chromium spec, the knowledge and changeset checks, and CI lint pass).
- Claim: the same spec written with
light-dark()fails both cases. Verified with an equivalent story probe. - Claim: the records carry no narration, research, references or project status. Verified.
- Claim: a patch
[feat]changeset. Confirmed by an engineering owner. - File
.changeset/theme-color-mode-blocks.md: overstates pseudo-class and mode coverage until the defects are fixed. - File
apps/storybook/stories/ThemeColorModeBlocks.stories.tsx: clear. - File
docs/architecture/theme-authoring-contract.md: clear (approved). - File
docs/architecture/theme-compilation.md: clear (approved). - File
packages/core/src/theme/__tests__/colorModeBlocks.a11y.chromium.spec.ts: clear (passes and type-checks). - File
packages/core/src/theme/colorModeBlocks.test.ts: no:active, pseudo-element, unknown-mode, nested-surface, generated or on-media case. - File
packages/core/src/theme/defineTheme.ts:StyleBlockis not exported. - File
packages/core/src/theme/generateThemeRules.ts: the pseudo, unknown-mode, nested-surface and first-load findings. - File
packages/core/src/theme/mergeComponents.ts: clear.
…e its pseudo, follow the system for any other mode, and let the nearest surface decide A block is emitted through the same path as its style key, with the mode conditions on the base selector, so pseudo-classes, the press model's :active and pseudo-elements follow them. A root mode other than light or dark follows the system preference. Surfaces decide by proximity: a nested @scope from a surface of the mode to the nearest surface of the other mode, and the root's conditions apply only outside surfaces. StyleBlock is exported. Adds a CLI theme build test and merge tests through generated type-scale rules and inherited media surfaces.
|
/approve-spec b52c8c4 |
There was a problem hiding this comment.
Changes requested. An engineering owner approved the new theme-record claims at this head, so the direction is settled; five fixes remain.
- On a
MediaThemesurface of the block's mode, the nested@scopeatgenerateThemeRules.ts:1454-1458gives the block scope proximity, so it overrides explicit Textsize/color, HeadingweightandonDark/onLightrules that win at aThemeroot and thatcomponent:TextFR2,component:HeadingFR2 andarchitecture:theme-authoring-contractINV7 require to win. - A
nullstyle value now throwsTypeError: Cannot convert undefined or null to object(generateThemeRules.ts:1384) and stops the whole theme from compiling, where the base kept the rest of the theme asarchitecture:theme-compilationINV13 requires. - Nested keys that are neither pseudos nor
@light/@dark, such as a mistyped'@Dark', are now dropped without the warning the base gave, againstarchitecture:theme-compilationINV14. - The new press test (
colorModeBlocks.a11y.chromium.spec.ts:117-122) failsComponent accessibility contractsbecause it reads the background at the start of Button's 125 ms transition, so emulate reduced motion or wait withtoHaveCSS. - The new ColorModeBlocks story fails the touched-components accessibility gate with 12 contrast nodes (dark-mode text on the story's white page) and a duplicate Pagination landmark, so give each case its theme's background and each Pagination a unique
label.
The earlier findings on :active and pseudo-elements, unknown modes, alternating surfaces, the StyleBlock export, the CLI build test, the merge cases and the size budget are fixed at this head.
Claims and files checked
Claims:
- A block holds properties, pseudo-classes and pseudo-elements that apply only in its mode, as Theme resolves it from its own mode, the system preference or a MediaTheme surface: verified (Chromium story cases in both preferences; unit and CLI tests).
- In the other mode a block writes nothing, so Core's contextual styling stays: verified (current page and error border equal the theme with nothing set).
- Themes without blocks compile to the same CSS: verified (all eight theme stylesheets byte-identical).
- Theme merging merges blocks per property: verified (merge tests through extends, generated type rules and an inherited dark surface).
- Blocks follow the style key's rules with no added specificity: specificity verified; false on a matching surface, where the block also outranks later rules (first finding).
- Pseudo-class and press rules in a block take the same conditions, placed before the pseudo: verified (compiled output; the press paints under reduced motion at a root and on a surface).
- On a light or dark surface only that surface's block is written: verified (unit test).
- Derived-variable and container expansion is shared with plain values: verified (one shared helper; derived-variable test).
- The nearest surface decides at any depth, and a root mode other than light or dark follows the system: verified (alternating-surface and other-mode cases).
- Theme's first-load JavaScript grows by about 269 B gzip, within 0.3 KB: verified (268 B measured on the built package).
StyleBlockis exported from the theme entry and the package root: verified (API surface).- The Chromium spec covers each mode source and passes: false for the press test (fourth finding); the other six pass.
- The same spec written with
light-dark()values fails both contextual cases: verified (the light current page turns transparent and the dark error border turns grey). - The theme and CLI suites pass, and knowledge, lint and changeset checks are clean: verified (1,783 and 3,124 tests pass; knowledge check and CI lint pass).
Files:
.changeset/theme-color-mode-blocks.md: clear.apps/storybook/stories/ThemeColorModeBlocks.stories.tsx: fifth finding.docs/architecture/theme-authoring-contract.md: clear (owner-approved).docs/architecture/theme-compilation.md: clear (owner-approved); the code misses its surface wording (first finding).packages/cli/clients/cli/commands/build-theme.color-mode-blocks.test.mjs: clear (passes).packages/core/src/theme/__tests__/colorModeBlocks.a11y.chromium.spec.ts: fourth finding.packages/core/src/theme/colorModeBlocks.test.ts: clear (passes).packages/core/src/theme/defineTheme.ts: clear (owner-approved widening).packages/core/src/theme/generateThemeRules.ts: first, second and third findings, and one comment suggestion.packages/core/src/theme/index.ts: clear.packages/core/src/theme/mergeComponents.ts: clear.
…ot, and keep the declaration reporting A block on a media surface uses the ancestor condition the onDark and onLight overrides use, at the root's weight and with no scope proximity, so explicit Text and Heading props and the surface overrides win as they do at the root. Dark blocks come before light ones, as the surface overrides do. A null value or a nested key that is neither a pseudo-class nor a mode block is a declaration again, compiled or reported as before. The press test waits for the pressed background; the story gives each case its theme's background and each Pagination its own label.
|
/approve-spec 7f76433 |
There was a problem hiding this comment.
Changes requested: an engineering owner approved the theme-record claims at this head, so the direction is settled, and three fixes remain.
- The new press test (
colorModeBlocks.a11y.chromium.spec.ts:112-119) moves the mouse to a ghost button at y≈899 in the 1280×720 viewport without scrolling, so the press never reaches it and the test fails on every run until it callsscrollIntoViewIfNeeded()orhover()on the button first. - Regression: the changeset (
.changeset/theme-color-mode-blocks.md:5) and theStyleOverridesJSDoc (defineTheme.ts:191-196) say a block writes nothing in the other mode, but with theonDark/onLightsurface model now in INV18 and in this PR's own surface test, a dark block also applies inside a lightMediaThemenested in a dark one, so both need to say that. - Miss:
packages/cli/assets/theme.template.tslists the style-key forms thatastryx theme templatehands to theme authors but has no'@light'/'@dark'entry, whicharchitecture:theme-authoring-contractrequires the template to stay aligned with.
The earlier findings on surface precedence, null values, unreported nested keys and the story's accessibility are fixed at this head. CI has not run at this head because the run found no capacity, so it needs a re-run after the fixes.
Claims and files checked
Claims:
- A block holds properties and pseudo-class overrides for one mode and leaves Core's contextual styling in the other mode: verified (the light current page and the dark error border match a theme with nothing set).
- New block and override types with docs, per-property merging, optional and additive: verified (API surface; merge tests).
- Blocks follow their style key with no added specificity, under the Theme's mode, the system preference, a nested Theme or a surface. Pseudo-class and press rules take the same conditions, a surface writes only its own block, and a theme without blocks gets no mode rules: verified (compiled output; unit and CLI tests; story probes; the eight shipped theme stylesheets are byte-identical).
- Derived-variable and container expansion is shared, and pseudo-classes come after the mode conditions: verified (one shared helper; compiled output).
- The root decides outside surfaces, and any other mode follows the system. Surfaces follow the onDark/onLight model, where both blocks apply in nested surfaces and light wins. Explicit Text and Heading props win alike: verified (story probes; explicit props are equal at a root and on a surface).
- Theme's first-load JavaScript grows by 295 B gzip, within 0.3 KB: verified (25,854 to 26,149 B).
- The block type is exported from the theme entry and the package root: verified.
- The unit test file covers output, pseudo-classes, derived variables, surfaces, merging and unchanged output: verified (passes).
- The Chromium spec covers each mode source and passes: false for the press test (first finding); the other seven pass.
- The same spec written with
light-dark()fails both contextual cases: verified by the cascade (a theme-layer value in both modes replaces the base-layer rule). - The CLI build test covers root, system and surface rules, pseudo-classes after the conditions, and nothing without blocks: verified (passes).
- Merge tests cover generated type-scale rules and an inherited dark surface through extends: verified.
- Theme suites pass, and the knowledge, lint, formatting and changeset checks are clean: verified (1,799 tests; knowledge and changeset checks; CI lint).
- Changeset: blocks hold properties, pseudo-class overrides and pseudo-elements: verified.
- Changeset: a block applies only in its mode and writes nothing in the other: false on nested surfaces of both modes (second finding).
- Changeset: a block can hold any value, not only a color: verified (a font size applies in dark only).
- Changeset: themes without blocks compile to the same CSS: verified.
Files:
.changeset/theme-color-mode-blocks.md: second finding.apps/storybook/stories/ThemeColorModeBlocks.stories.tsx: clear (accessibility audit passes; Pagination labels are unique).docs/architecture/theme-authoring-contract.md: clear (owner-approved).docs/architecture/theme-compilation.md: clear (owner-approved).packages/cli/clients/cli/commands/build-theme.color-mode-blocks.test.mjs: clear (passes).packages/core/src/theme/__tests__/colorModeBlocks.a11y.chromium.spec.ts: first finding.packages/core/src/theme/colorModeBlocks.test.ts: clear (passes; one stale test name).packages/core/src/theme/defineTheme.ts: second finding (JSDoc).packages/core/src/theme/generateThemeRules.ts: clear, with one comment suggestion.packages/core/src/theme/index.ts: clear.packages/core/src/theme/mergeComponents.ts: clear.
| if (!withModes) { | ||
| return; | ||
| } | ||
| // Color-mode blocks follow the rules they refine at the same weight, |
There was a problem hiding this comment.
Non-blocking (source comments, architecture:knowledge-contracts INV29): the first sentence is still 31 words and covers three topics. Suggested: "Mode rules follow the rules they refine, at the same weight. In its mode a block wins. In the other mode it writes nothing. Dark comes before light, as the surface overrides do."
|
/approve-spec 47501e2 |
|
/approve-spec 83935a3 |
There was a problem hiding this comment.
Approved pending CI: CI is still running on this head. An engineering owner approved the theme-record claims at this head, and the three earlier findings (the press test, the release-note wording on nested surfaces, and the missing theme template entry) are fixed.
Optional follow-ups:
- The new theme template line (
packages/cli/assets/theme.template.ts:284-287) says the other mode "is left as written"; consider adding that both blocks apply where light and darkMediaThemesurfaces nest, as the changeset and JSDoc now say. - The comment at
generateThemeRules.ts:1435-1438still runs long, and the spec header and one unit test name still mention the "nearest surface" model the pull request dropped.
Claims and files checked
Claims:
- A block holds properties and pseudo-class overrides for one mode and leaves Core's contextual styling in the other: verified (the light current page and the dark error border match a theme with nothing set).
- New block and override types with docs, per-property merging, optional and additive: verified (type exports; merge tests).
- Blocks follow their style key with no added specificity, under the Theme's mode, the system preference, a nested Theme or a surface; pseudo-class and press rules take the same conditions; a surface writes only its own block; a theme without blocks gets no mode rules: verified (unit and CLI build tests; story probes).
- The derived-variable and container expansion is shared, and pseudo-classes, press rules and pseudo-elements come after the mode conditions: verified (one shared helper; compiled-output tests).
- The root decides outside surfaces, any other mode follows the system, surfaces follow the onDark/onLight model where both blocks apply and light wins, and explicit Text and Heading props win alike: verified (browser tests and probes).
- The Theme entry's first-load JavaScript grows by 295 B gzip, within 0.3 KB: verified (25,854 to 26,149 B; the latest push ships no JavaScript).
- The block type is exported from the theme entry and the package root: verified.
- No component changes, and the two theme records gain the stated claims: verified.
- The unit test file covers output, pseudo-classes, derived variables, surfaces, merging and unchanged output: verified (11 tests pass).
- The browser spec covers each mode source: verified (8 tests pass on three repeats; CI accessibility contracts pass).
- The same spec written with
light-dark()fails both contextual cases: verified by the cascade (a theme-layer value in both modes replaces the base-layer rule). - The CLI build test covers root, system and surface rules, pseudo-classes after the conditions, and nothing without blocks: verified (2 tests pass).
- Merge tests cover generated type-scale rules and an inherited dark surface through
extends: verified. - The theme suites pass and the knowledge, lint, formatting and changeset checks are clean: verified (1,935 tests; knowledge and changeset checks; CI lint).
- Core changeset: blocks hold properties, pseudo-class overrides and pseudo-elements: verified.
- Core changeset: a block applies where the element's mode is its mode, from the Theme's mode, the system preference or a surface: verified.
- Core changeset: inside surfaces a block applies as onDark/onLight do, both apply where both modes nest, and light wins: verified (alternating-surface probe and test).
- Core changeset: where no enclosing mode matches the block writes nothing, and it can hold any value: verified (a font size applies in dark only).
- Core changeset: themes without blocks compile to the same CSS: verified.
- CLI changeset: the theme template lists the block form among the style keys with a commented example: verified.
Files:
.changeset/theme-color-mode-blocks.md: clear..changeset/theme-template-color-mode-blocks.md: clear.apps/storybook/stories/ThemeColorModeBlocks.stories.tsx: clear.docs/architecture/theme-authoring-contract.md: clear (owner-approved).docs/architecture/theme-compilation.md: clear (owner-approved).packages/cli/assets/theme.template.ts: clear, with one wording suggestion.packages/cli/clients/cli/commands/build-theme.color-mode-blocks.test.mjs: clear (passes).packages/core/src/theme/__tests__/colorModeBlocks.a11y.chromium.spec.ts: clear (passes), with one stale header phrase.packages/core/src/theme/colorModeBlocks.test.ts: clear (passes), with one stale test name.packages/core/src/theme/defineTheme.ts: clear.packages/core/src/theme/generateThemeRules.ts: clear, with one comment suggestion.packages/core/src/theme/index.ts: clear.packages/core/src/theme/mergeComponents.ts: clear.
| // '@light' / '@dark' a block inside any of the above that applies | ||
| // only in that color mode (properties and | ||
| // ':hover' etc. as above); the other mode is | ||
| // left as written |
There was a problem hiding this comment.
Non-blocking: "the other mode is left as written" leaves out the nested-surface case that the changeset and the StyleOverrides JSDoc now state. Inside a light MediaTheme nested in a dark one, the dark block still applies to properties the light block does not set. Suggested ending: "…the other mode is left as written, except where light and dark surfaces nest (both blocks apply there, as onDark/onLight do)."
Summary
A theme's component overrides can now hold
@lightand@darkblocks: properties, and pseudo-class overrides, that apply only in that color mode.Why: today a theme can make a component value differ by mode only with
light-dark(). That always writes a value for BOTH modes in the theme layer. So a theme that wants, say, a dark-only button background also overrides the light-mode look Core gives that button in context, such as Pagination's current page or an input's error border. Insidelight-dark()there is no way to say "leave the base cascade alone in light mode". A mode block writes nothing in the other mode, so Core's own contextual rules stay intact there.'@light'/'@dark'blocks. NewStyleBlock/StyleOverridestypes, with docs. Theme merging (deepMergeComponents) merges mode blocks per property. Optional and additive: a style key without a block applies in both modes, as written.data-theme, the system preference when no theme mode is set, a nestedTheme, or aMediaThemesurface. Pseudo-class and press rules inside a block get the same conditions. On a light or dark surface, only that surface's own mode block is written. A theme without mode blocks has no mode rules in its CSS (byte-identical output).Themedecides, and a root mode other than light or dark follows the system preference. On media surfaces blocks follow the onDark/onLight surface model, including its behavior where surfaces of both modes nest (both apply; light wins a shared property). This is parity with the existing model, not a new gap. Block conditions add no specificity and no scope proximity, so explicit Text and Heading props and onDark/onLight rules win as they do at a root.Themeentry's first-load JS is 25,854 → 26,149 B gzip (+295 B), within the 0.3 KB an optional feature may add. A zero-cost route would need an explicit capability import, which would change the authoring contract.StyleBlockis exported from@astryxdesign/core/themeand@astryxdesign/core.Scope
Components: none changed. Theme system: new optional contract feature (Core theme types + compiler); records
theme-authoring-contract(INV16, INV6) andtheme-compilation(INV18).Tests
colorModeBlocks.test.ts: compiled output, pseudo-classes and derived variables in blocks, surfaces, merging, and unchanged output without blocks.colorModeBlocks.a11y.chromium.spec.ts: Core's real built stylesheet plus reset, with realPaginationandTextInputrendered underThemeandMediaTheme. Coversdata-themedark and light, the system preference both ways, a nested lightThemeinside dark, and a lightMediaThemesurface. A dark block keeps the light current page exactly as Core draws it; a light block keeps the dark error border. The same spec written withlight-dark()values fails both of those cases.build-theme.color-mode-blocks.test.mjs:astryx theme buildof a theme with blocks (explicit, system and surface rules, pseudo-classes after the conditions, no output for a theme without blocks).extends.generateThemeRules,defineTheme,onMediaTokensandthemeAdaptationssuites pass;pnpm check:knowledge, eslint, prettier and changesets are clean.Writing rubric results
Records changed:
architecture:theme-authoring-contract(System model line, INV6 merge sentence, new INV16, one verification row) andarchitecture:theme-compilation(new INV18, one verification row, twoverified_byentries).R1 narration: two found while drafting. INV16 ("means what it meant before") and INV18 ("compiles to the same CSS as before") read as change history; rewritten as present-tense statements: "a style key without one applies in both modes, as written" and "a theme without color-mode blocks has no mode rules in its CSS". No other sentence describes a change.
R2 research: none in either record. The selector analysis (why
light-dark()cannot leave a base-layer rule alone in the other mode) lives in the pull request description, not in the records.R3 evidence: the new verification rows name test files and the situations they exercise (data-theme, system preference, nested Theme, media surface, a base-layer rule in context), with no pull requests or commits.
R4 rejected alternatives: none recorded.
R5 change references: none (no
#numbers,/pull/or/issues/).R6 open questions: none added.
R7 project status: none. "optional and additive" in INV16 describes the contract, not rollout state.