Skip to content

Apply built-in tone colours to data-driven and partial tones - #35

Merged
sabind merged 1 commit into
masterfrom
fix-data-driven-tones
Oct 20, 2026
Merged

sabind merged 1 commit into
masterfrom
fix-data-driven-tones

Conversation

@sabind

@sabind sabind commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Why

There is no ticket: this was caught while writing the newcomer docs, whose README section on tones says a tone set from data works "with only data". We caught this issue so we patched it like the rest.

What

A <panel> or <alert> whose tone comes from data now gets the built-in colours for that tone without a style object, and a style.tones entry that sets only some colours keeps the built-in values for the rest. Ships in 4.0.1.

Changes

  • Data-driven tones get the built-in palette at render, and partial style.tones entries fill in from it. The layout picks tone colours at compile time from the attribute's literal text, which for tone="{{tone}}" is an unknown name, so it wrote the neutral grey; the render-time style step recoloured only from the caller's style.tones. The five built-in tones now live in one exported table in src/layout.ts, and src/style.ts layers the caller's entry over the built-in tone field by field. Literal tones and full style.tones entries render byte-identical to before; an unknown tone stays grey. We caught this issue so we patched it like the rest; these are minor fixes, fully covered and encapsulated.

Testing

  • test/layout.test.ts: the data-only tone test now asserts the info and success backgrounds, and a new test covers a partial override. Both failed before the fix and pass after.
  • Old and new builds compared: literal tones (five built-in plus an unknown, panel and alert) with no style, and a full style.tones entry, produce byte-identical HTML.
  • npm audit --audit-level=high --omit=dev, npm test (7 files, 290 tests), npm run examples and npm run test:visual (5 of 5 snapshots unchanged) pass on Node 24. Node 20 and 22 run in CI.

Risk and rollout

Ships in 4.0.1, which is on master but not yet published: tag v4.0.1 once this merges. Visible change: templates that set a tone from data, or pass a partial style.tones entry, now get the tone's colours instead of grey.

🤖 Generated with Claude Code

The layout chose tone colours at compile time, when a data tone is
still the literal {{tone}}, and the render-time style step only used
the caller's style.tones, so data tones rendered grey. The style step
now layers style.tones over the built-in palette.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sabind
sabind merged commit f62ecfd into master Oct 20, 2026
4 checks passed
@sabind
sabind deleted the fix-data-driven-tones branch October 20, 2026 21:51
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