Repository navigation
ndg: add a theme toggle to the page header - #301
Merged
Merged
Conversation
A click selects the light or the dark theme. The page keeps the selection in `localStorage` and applies it before the first paint. When the selected theme is the same as the system theme, the page follows the system theme again. The style sheet applies each `prefers-color-scheme` rule also when `data-theme` on `<html>` selects that theme, and does not apply it when `data-theme` selects the other theme. The toggle also selects the matching `<source>` of a `<picture>` with a `prefers-color-scheme` media query, and sends an `ndg:themechange` event on `document`. Assisted-by: Claude:claude-opus-5-5 Claude-Session: https://claude.ai/code/session_01RJvbghuj5GtCBiCjmBepNJ
Member
|
Simple enough that I'll go ahead and merge. #300 needs a little bit of work, but I will have a review for it shortly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a button to the page header that selects the light or the dark theme.
localStorageand applies it before the first paint, so the page does not flash in the other theme.prefers-color-schemerule also whendata-themeon<html>selects that theme, and does not apply it whendata-themeselects the other theme.<source>of a<picture>with aprefers-color-schememedia query, so light and dark screenshots follow the page theme.ndg:themechangeevent ondocumentwith{ mode, resolved }when the theme changes, so other scripts can follow the theme.This change is independent of #300 (Mermaid diagrams). When both are merged, Mermaid can draw the diagrams again on
ndg:themechange. I will add that change to the pull request that is merged second.Tests:
deno test -Apasses,deno lintis clean andnix build .#ndgpasses. I also checked the pages in a headless Chromium with a light and a dark system theme, before and after a click.deno fmt --checkreports one file, which is the same onmain.Assisted-by: Claude:claude-opus-5-5
https://claude.ai/code/session_01RJvbghuj5GtCBiCjmBepNJ