Skip to content

Commit 046b0b9

Browse files
fix: improve contrast for all links, button and label text (#545)
Co-authored-by: Sam Cunliffe <samcunliffe@users.noreply.github.com>
1 parent eea75f4 commit 046b0b9

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

docs/_includes/header_custom.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
<script>
66
const toggleDarkMode = document.querySelector(".js-toggle-dark-mode");
7+
8+
const setHtmlThemeAttr = (theme) => {
9+
document.documentElement.setAttribute("data-theme", theme);
10+
};
11+
712
jtd.addEvent(toggleDarkMode, "click", function () {
813
if (jtd.getTheme() === "light") {
914
jtd.setTheme("dark");
15+
setHtmlThemeAttr("dark");
1016
toggleDarkMode.textContent = "☼";
1117
toggleDarkMode.ariaLabel = "Switch to light mode";
1218
localStorage.setItem("theme", "dark");
1319
} else {
1420
jtd.setTheme("light");
21+
setHtmlThemeAttr("light");
1522
toggleDarkMode.textContent = "☾";
1623
toggleDarkMode.ariaLabel = "Switch to dark mode";
1724
localStorage.setItem("theme", "light");
@@ -22,12 +29,9 @@
2229
* Meanwhile, we check each time if there is a theme written to local storage and obey it.
2330
*/
2431
window.addEventListener("DOMContentLoaded", function () {
25-
if (localStorage.getItem("theme") === "dark") {
26-
jtd.setTheme("dark");
27-
toggleDarkMode.textContent = "☼";
28-
} else {
29-
jtd.setTheme("light");
30-
toggleDarkMode.textContent = "☾";
31-
}
32+
const theme = localStorage.getItem("theme") === "dark" ? "dark" : "light";
33+
jtd.setTheme(theme);
34+
setHtmlThemeAttr(theme);
35+
toggleDarkMode.textContent = theme === "dark" ? "☼" : "☾";
3236
});
3337
</script>

docs/_sass/custom/custom.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,41 @@ div.site-logo {
2828
width: 100%;
2929
color: $body-text-color;
3030
}
31+
32+
//Dark mode link styles
33+
html[data-theme="dark"] {
34+
.main-header a,
35+
.main-header button,
36+
.side-bar a {
37+
color: $link-color-dark;
38+
}
39+
40+
main a,
41+
footer a {
42+
color: $link-color-dark;
43+
text-decoration: underline;
44+
text-decoration-color: $link-color-dark;
45+
text-decoration-thickness: 1px;
46+
transition:
47+
text-decoration-thickness 0.2s ease-in-out,
48+
text-underline-offset 0.2s ease-in-out;
49+
}
50+
51+
main a:hover,
52+
footer a:hover {
53+
text-decoration-color: $link-color-dark;
54+
text-decoration-thickness: 2px;
55+
text-underline-offset: 3px;
56+
}
57+
}
58+
59+
//Label colors
60+
main {
61+
.label-green {
62+
background-color: $label-success-bg;
63+
}
64+
65+
.label-red {
66+
background-color: $label-error-bg;
67+
}
68+
}

docs/_sass/custom/setup.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Color palette
2+
$blue-400: #4da6ff;
3+
$green-700: #00755c;
4+
$red-600: #d13c3c;
5+
6+
// Semantic mappings
7+
$link-color-dark: $blue-400;
8+
$label-success-bg: $green-700;
9+
$label-error-bg: $red-600;

0 commit comments

Comments
 (0)