_content: add dark theme toggle
Added a toggle button with three states: auto, light, and dark to set the preferred color scheme of go.dev. For golang/go#34601. Change-Id: I771f64f34294fa0a86bbcdd6c0acaa4af7e7cf8c Reviewed-on: https://go-review.googlesource.com/c/website/+/391536 Run-TryBot: Jamal Carvalho <jamal@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jamal Carvalho <jamalcarvalho@google.com>
This commit is contained in:
Родитель
a3d868e5e5
Коммит
7c52741a0f
|
@ -212,9 +212,14 @@ window.initFuncs = [];
|
|||
} else if (theme === 'light') {
|
||||
nextTheme = 'auto';
|
||||
}
|
||||
let domain = '';
|
||||
if (location.hostname === 'go.dev') {
|
||||
// Include subdomains to apply the setting to pkg.go.dev.
|
||||
domain = 'domain=.go.dev;';
|
||||
}
|
||||
document.documentElement.setAttribute('data-theme', nextTheme);
|
||||
document.cookie =
|
||||
`prefers-color-scheme=${nextTheme};domain=.go.dev;path=/;max-age=31536000;`;
|
||||
`prefers-color-scheme=${nextTheme};${domain}path=/;max-age=31536000;`;
|
||||
}
|
||||
|
||||
initialThemeSetup();
|
||||
|
|
|
@ -143,6 +143,31 @@
|
|||
Report an Issue
|
||||
</a>
|
||||
</li>
|
||||
<li class="Footer-listItem go-Footer-listItem">
|
||||
<button class="go-Button go-Button--text go-Footer-toggleTheme js-toggleTheme" aria-label="Toggle theme">
|
||||
<img
|
||||
data-value="auto"
|
||||
class="go-Icon go-Icon--inverted"
|
||||
height="24"
|
||||
width="24"
|
||||
src="/images/icons/brightness_6_gm_grey_24dp.svg"
|
||||
alt="System theme">
|
||||
<img
|
||||
data-value="dark"
|
||||
class="go-Icon go-Icon--inverted"
|
||||
height="24"
|
||||
width="24"
|
||||
src="/images/icons/brightness_2_gm_grey_24dp.svg"
|
||||
alt="Dark theme">
|
||||
<img
|
||||
data-value="light"
|
||||
class="go-Icon go-Icon--inverted"
|
||||
height="24"
|
||||
width="24"
|
||||
src="/images/icons/light_mode_gm_grey_24dp.svg"
|
||||
alt="Light theme">
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<a class="Footer-googleLogo" target="_blank" href="https://google.com" rel="noopener">
|
||||
<img class="Footer-googleLogoImg" src="/images/google-white.png" alt="Google logo">
|
||||
|
|
Загрузка…
Ссылка в новой задаче