You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the preceding commit, I added support for a dark mode, heeding the
operating system's indicated preference.
However, many users will want to be able to switch from/to dark/light
mode without switching the rest of their operating system.
Guided by the excellent advice provided in
https://css-tricks.com/a-complete-guide-to-dark-mode-on-the-web/ and in
https://dev.to/ayc0/light-dark-mode-avoid-flickering-on-reload-1567,
this commit introduces a button to toggle dark/light mode.
To avoid flickering, the idea is to:
- store the user preference in the local storage,
- using Javascript, in the `<head>` section of the HTML page (so that it
is executed _before_ anything is displayed), heed that stored user
preference (if any) by setting the `theme` attribute in the
`document`'s `dataset`, and finally
- use that `theme` via CSS:
:root[data-theme="dark"] {
...
}
The toggle button itself is a newly-introduced SVG file, which means
that `script/serve-public.js` has to learn about SVG files.
Signed-off-by: Johannes Schindelin <[email protected]>
0 commit comments