Skip to content

Commit 418edb6

Browse files
committed
chore: replace partially working switcher with prefers-color-scheme media query
1 parent d885041 commit 418edb6

File tree

4 files changed

+54
-79
lines changed

4 files changed

+54
-79
lines changed

demo/index.html

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<a href="#paragraph">Paragraph Content.</a>
1717
<a href="#tabledata">Table Data</a>
1818
<a href="#formdata">Form Data</a>
19-
<a href="#themeswitcher">Theme Switcher</a>
2019
</nav>
2120
</header>
2221
<main>
@@ -135,47 +134,7 @@ <h2 id="formdata">Form</h2>
135134
<input type="submit" value="Send message" />
136135
</fieldset>
137136
</form>
138-
139-
<h2 id="themeswitcher">Theme Switcher</h2>
140-
<input
141-
type="radio"
142-
id="light"
143-
name="theme-name"
144-
value="light"
145-
onclick="setTheme('light')"
146-
/>
147-
<label for="light">light</label><br />
148-
<input
149-
type="radio"
150-
id="dark"
151-
name="theme-name"
152-
value="dark"
153-
onclick="setTheme('dark')"
154-
/>
155-
<label for="dark">dark</label><br />
156-
157-
<input
158-
type="radio"
159-
id="high-contrast"
160-
name="theme-name"
161-
value="high-contrast"
162-
onclick="setTheme('high-contrast')"
163-
/>
164-
<label for="high-contrast">high-contrast</label><br />
165137
</main>
166138
<footer>author, (c), etc</footer>
167-
<script>
168-
// let dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
169-
170-
// if (dark) setTheme("dark");
171-
172-
function setTheme(theme) {
173-
document.documentElement.classList.add("theme-switch");
174-
document.documentElement.setAttribute("data-theme", theme);
175-
window.setTimeout(function () {
176-
document.documentElement.classList.remove("theme-switch");
177-
}, 1000);
178-
}
179-
</script>
180139
</body>
181140
</html>

demo/tinycss.css

Lines changed: 24 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/tinycss.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/base.scss

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
// todo: high-contrast: https://mwichary.medium.com/dark-theme-in-a-day-3518dde2955a
21
* {
32
box-sizing: border-box;
43
}
54

65
:root {
76
--sans-font: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
87

9-
--background: #fff;
10-
--accent-background: #dfe1e9;
11-
--text: #252525;
12-
--text-light: #585858;
8+
--background-light: #fff;
9+
--accent-background-light: #dfe1e9;
10+
--text-light: #252525;
11+
--text-light-light: #585858;
12+
13+
--background-dark: rgb(52, 51, 58);
14+
--accent-background-dark: rgb(81, 79, 90);
15+
--text-dark: #d8d8d8;
16+
--text-light-dark: #ffffff;
17+
1318
--border: #cecfd4;
1419
--accent: #fa986b;
20+
--accent-dark: #b44512;
21+
--accent-light: #f7bca3;
22+
}
23+
24+
html {
25+
--background: var(--background-light);
26+
--accent-background: var(--accent-background-light);
27+
--text: var(--text-light);
28+
--text-light: var(--text-light-light);
1529
}
1630

17-
html[data-theme="dark"] {
18-
--background: rgb(52, 51, 58);
19-
--accent-background: rgb(81, 79, 90);
20-
--text: #d8d8d8;
21-
--text-light: #ffffff;
31+
@media (prefers-color-scheme: dark) {
32+
html {
33+
--background: var(--background-dark);
34+
--accent-background: var(--accent-background-dark);
35+
--text: var(--text-dark);
36+
--text-light: var(--text-light-dark);
37+
}
2238
}
2339

2440
html {
@@ -29,14 +45,6 @@ html {
2945
background: var(--background);
3046
}
3147

32-
html.theme-switch,
33-
html.theme-switch *,
34-
html.theme-switch *:before,
35-
html.theme-switch *:after {
36-
transition: all 650ms !important;
37-
transition-delay: 0 !important;
38-
}
39-
4048
header {
4149
color: var(--text);
4250
}
@@ -50,12 +58,14 @@ body {
5058
}
5159

5260
a {
53-
color: #b44512;
61+
color: var(--accent-dark);
5462
text-decoration: underline;
63+
5564
&:visited {
5665
color: var(--text);
5766
text-decoration: dotted;
5867
}
68+
5969
&:hover {
6070
color: var(--accent);
6171
text-decoration: none;

0 commit comments

Comments
 (0)