feat: add dark mode support via prefers-color-scheme#676
feat: add dark mode support via prefers-color-scheme#676alok wants to merge 12 commits intoleanprover:mainfrom
Conversation
2d3bac6 to
3d68642
Compare
Add automatic dark mode support that respects operating system preferences using the `@media (prefers-color-scheme: dark)` CSS media query. Changes: - verso-vars.css: Add new CSS custom properties for backgrounds, borders, links, shadows, and message colors with dark mode variants - code.css: Update API docs styling to use CSS variables - search-box.css/search-highlight.css: Update search UI to use CSS variables - Style.lean: Update manual page styling to use CSS variables The color scheme is harmonized with lean-lang.org: - Light: #ffffff background, leanprover#333 text, #386ee0 links - Dark: #1e1e1e background, #eee text, #3b94ff links Closes leanprover#641
3d68642 to
be4f660
Compare
|
This sounds great, and looks good based on the diffs! Given that you've got a checklist, I'll hold off on reviewing it until you indicate that you're ready. WRT testing the dark mode toggle, we do have Playwright tests for some features already, which seems like a natural place to put these tests. |
|
Thanks for the feedback! I've fixed the prettier formatting issue that was causing CI to fail. The core dark mode via
For testing the dark mode toggle, I can add Playwright tests. Should I:
|
|
Sorry for the delay in replying. Winter holidays are now over! I think that Playwright tests for the toggle button are important, because local storage won't be "automatically" tested in any reasonable way by most daily use of the sites, and issues would affect first-time readers disproportionately. I think the risk of regressions on the visual aspects is relatively small, though. So number 1 :-) Thanks again, this is really a wonderful improvement! |
|
|
||
| /** Background colors **/ | ||
| --verso-background-color: #ffffff; | ||
| --verso-surface-color: #f9fbfd; |
There was a problem hiding this comment.
A comment here explaining the "surface" terminology would be helpful.
There was a problem hiding this comment.
Added in 5837227. I documented "surface" directly above --verso-surface-color in static-web/verso-vars.css as the secondary/elevated background for controls and sidebars.
There was a problem hiding this comment.
Thanks for the comment!
I'm still not wild about this terminology, even with the explanatory comment - surface immediately makes my brain want to think about graphics contexts and drawing APIs and the like, not regions of webpages. What about calling it --verso-secondary-background-color?
|
Addressed the remaining dark-mode feedback in 3 commits now pushed:\n\n- |
|
Pushed one more follow-up commit (
Please take another look when convenient. |
|
Thanks, I'll give it a look when I can. I'm on vacation until Monday, and will be away from computers until then :-) |
|
In the meantime there's a couple of merge conflicts... |
|
Preview for this PR is ready! 🎉 |
|
OK, the previews for the PRs are working again. It's looking like it works now - I'll get into details ASAP. Thanks for your patience! |
| } | ||
|
|
||
| /** Manual dark mode override **/ | ||
| :root[data-verso-dark-mode][data-theme="dark"] { |
There was a problem hiding this comment.
This section is a duplicate of the variables above, right? How do we keep them in sync?
| "aria-label", | ||
| effective === "dark" ? "Switch to light mode" : "Switch to dark mode", | ||
| ); | ||
| toggle.innerHTML = effective === "dark" ? "☀️" : "🌙"; |
There was a problem hiding this comment.
I'm a bit concerned about emoji as UI elements. They can look very different in different places, and their color is a bit out of place. Can we use some standard SVG icons here? Maybe the one from lean-lang.org?
Also, when clicking through the page, I had a hard time figuring out the workflow for getting back to the system theme. How should users do that?
|
I'm not sure where to put it, but this should probably also set the color-scheme property, right? |
| position: absolute; | ||
| top: 0; | ||
| right: 0; | ||
| right: 3rem; |
There was a problem hiding this comment.
This feels like a fragile way to make space. What about some kind of flexbox wrapper into which the search box and toggle widget are placed that can manage them well, also if we add another widget there in the future?
| --verso-link-hover-color: #4d9efc; | ||
|
|
||
| /** Border colors **/ | ||
| --verso-border-color: #4c4c4c; |
There was a problem hiding this comment.
The contrast ratio between 4c4c4c and 1e1e1e is 1.94:1 according to https://webaim.org/resources/contrastchecker/ . WCAG wants 3:1 for interface components, which would put the border at #696969 according to that site. What do you think about this solution?
|
Thanks a bunch, once again! |


Summary
Add automatic dark mode support that respects operating system preferences using the
@media (prefers-color-scheme: dark)CSS media query.The color scheme is harmonized with lean-lang.org as requested:
#ffffffbackground,#333text,#386ee0links,#f9fbfdsurface#1e1e1ebackground,#eeetext,#3b94fflinks,#181818surfaceTest plan
lake build)Closes #641