Skip to content

Commit f19c76e

Browse files
committed
Added Dark Mode
A bunch of colors inherit from body now
1 parent 9c3677a commit f19c76e

File tree

10 files changed

+122
-58
lines changed

10 files changed

+122
-58
lines changed

src/components/Back/Back.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.Back {
22
display: flex;
33
align-items: center;
4-
color: #3a3a3a;
4+
color: inherit;
55
transition: all 0.15s;
66
font-weight: 600;
77
font-size: 0.85rem;
@@ -15,6 +15,6 @@
1515
}
1616

1717
&:hover {
18-
background-color: #f0f0f0;
18+
background-color: inherit;
1919
}
2020
}

src/components/MultipleChoiceQuestion/MultipleChoiceQuestionOption.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
border-style: solid;
77
border-radius: 0.6rem;
88
border-width: 0.1rem;
9-
border-color: #c0c0c07f;
9+
border-color: #4e4e4e7f;
1010
margin: 1rem 0rem;
1111
transition: all 0.15s;
1212

@@ -16,7 +16,7 @@
1616

1717
&:hover {
1818
&[data-interactive="true"] {
19-
background-color: #ededed;
19+
background-color: #474747;
2020
}
2121
&[data-selected="false"] {
2222
cursor: pointer;
@@ -25,7 +25,7 @@
2525

2626
&[data-revealed="false"] {
2727
&[data-selected="true"] {
28-
background-color: #eaeaea;
28+
background-color: #474747;
2929
}
3030
}
3131

src/components/Page/Page.astro

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
---
22
import "./Page.scss";
3+
import ThemeIcon from "../ThemeIcon/ThemeIcon.astro";
34
---
45

56
<div class="Page">
7+
<ThemeIcon />
68
<slot />
79
</div>
10+
11+
<script type="module">
12+
document.addEventListener("DOMContentLoaded", () => {
13+
const toggleButton = document.getElementById("theme-toggle");
14+
15+
// Check if dark mode is already set in localStorage
16+
const isDarkMode = localStorage.getItem("theme") === "dark";
17+
if (isDarkMode) {
18+
document.body.classList.add("dark-mode");
19+
} else {
20+
document.body.classList.add("light-mode");
21+
}
22+
23+
// Update icon based on the theme
24+
const updateIcon = () => {
25+
const isDarkMode = document.body.classList.contains("dark-mode");
26+
document.querySelector(".sun").style.fill = isDarkMode
27+
? "transparent"
28+
: "black";
29+
document.querySelector(".moon").style.fill = isDarkMode
30+
? "white"
31+
: "transparent";
32+
};
33+
34+
updateIcon();
35+
36+
toggleButton.addEventListener("click", () => {
37+
const isDarkMode = document.body.classList.toggle("dark-mode");
38+
document.body.classList.toggle("light-mode", !isDarkMode);
39+
localStorage.setItem("theme", isDarkMode ? "dark" : "light");
40+
updateIcon();
41+
});
42+
});
43+
</script>

src/components/Page/Page.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,21 @@ $layout-width-inner-spacing-base: 1rem;
1010
$layout-width-inner-spacing-base
1111
);
1212
}
13+
14+
#themeToggle {
15+
border: 0;
16+
background: none;
17+
}
18+
.sun {
19+
fill: black;
20+
}
21+
.moon {
22+
fill: transparent;
23+
}
24+
25+
:global(.dark) .sun {
26+
fill: transparent;
27+
}
28+
:global(.dark) .moon {
29+
fill: white;
30+
}

src/components/RowCard/RowCard.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
align-items: center;
44
justify-content: space-between;
55
gap: 0.75rem;
6-
color: black;
6+
color: inherit;
77
border-radius: 0.6rem;
88
border-width: 0.1rem;
9-
border-color: #f1f1f1;
9+
border-color: inherit;
1010
border-style: solid;
1111
padding: 0.2rem 0.6rem;
1212
transition: all 0.2s;
@@ -15,7 +15,7 @@
1515
cursor: grab;
1616

1717
&:hover {
18-
background-color: rgba(248, 248, 248, 0.753);
18+
background-color: rgba(107, 107, 107, 0.753);
1919
.RowCard__icon {
2020
color: #e30614;
2121
}
@@ -28,7 +28,7 @@
2828
}
2929

3030
&__icon {
31-
background-color: #f2f2f2;
31+
background-color: inherit;
3232
padding: 0.3rem 0.6rem;
3333
border-radius: 0.5rem;
3434
font-size: 1.4rem;

src/components/Sidebar/Sidebar.scss

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
width: 14rem;
55
height: 100vh;
66
overflow: hidden;
7-
background-color: #fafafa;
7+
background-color: inherit;
88
border-right: 0.1rem solid #f3f3f3;
99
display: flex;
1010
padding: 0.5rem;
@@ -26,7 +26,7 @@
2626
padding-top: -0.3rem;
2727
font-size: 0.9rem;
2828
font-weight: 600;
29-
color: #000000;
29+
color: inherit;
3030
}
3131

3232
&__sections {
@@ -48,7 +48,7 @@
4848
&--enabled {
4949
cursor: pointer;
5050
&:hover {
51-
background-color: #f0f0f0;
51+
background-color: inherit;
5252
.Sidebar__item__icon {
5353
color: #e30614;
5454
}
@@ -61,19 +61,19 @@
6161
}
6262

6363
&--active {
64-
background-color: #f3f3f3;
64+
background-color: inherit;
6565
}
6666

6767
&__icon {
6868
font-size: 1.5rem;
69-
color: #000000;
69+
color: inherit;
7070
}
7171

7272
&__title {
7373
padding-left: 0.75rem;
7474
font-size: 1rem;
7575
font-weight: 500;
76-
color: #000000;
76+
color: inherit;
7777
}
7878
}
7979

@@ -97,38 +97,9 @@
9797
width: 100vw;
9898
z-index: 1;
9999
position: fixed;
100-
background-color: #ffffff;
100+
background-color: inherit;
101101
bottom: 0;
102102
justify-content: center;
103103
border-top-width: 0.1rem;
104104
border-color: #f1f1f1;
105-
border-style: solid;
106-
@media (max-width: 768px) {
107-
display: flex;
108-
}
109-
110-
&__inner {
111-
display: flex;
112-
justify-content: space-between;
113-
min-width: 14rem;
114-
padding: 0.5rem;
115-
gap: 1rem;
116-
}
117-
}
118-
119-
@media (max-width: 768px) {
120-
.Sidebar__item {
121-
flex-direction: column;
122-
justify-content: center;
123-
gap: 0.3rem;
124-
min-width: 3rem;
125-
}
126-
.Sidebar__item__icon {
127-
font-size: 2rem;
128-
}
129-
.Sidebar__item__title {
130-
font-size: 0.6rem;
131-
padding-left: 0rem;
132-
text-align: center;
133-
}
134105
}

src/components/Them

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
import "./ThemeIcon.scss";
3+
---
4+
5+
<div id="theme-toggle">
6+
<svg width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
7+
<path
8+
class="sun"
9+
fill-rule="evenodd"
10+
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"
11+
></path>
12+
<path
13+
class="moon"
14+
fill-rule="evenodd"
15+
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"
16+
></path>
17+
</svg>
18+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#themeToggle {
2+
border: 0;
3+
background: none;
4+
}
5+
.sun {
6+
fill: black;
7+
}
8+
.moon {
9+
fill: transparent;
10+
}
11+
12+
:global(.light-mode) .sun {
13+
fill: transparent;
14+
}
15+
:global(.dark-mode) .moon {
16+
fill: white;
17+
}

src/layouts/Base/Base.scss

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@ body {
55

66
a {
77
text-decoration: none;
8-
color: #e30614;
8+
color: inherit;
99
}
1010

1111
:root {
1212
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
1313
"Helvetica Neue", Helvetica, Arial, sans-serif;
14+
}
1415

15-
/* color-scheme: light dark; */
16-
// background-color: #1f2023; // var(--color-background);
17-
// color: #1f2023; //var(--color-foreground);
16+
.light-mode {
17+
--color: #000000;
18+
--color-background: #ffffff;
19+
--color-foreground: #000000;
20+
--color-accent: #5c6ac4;
21+
}
1822

19-
// --color-background: #ffffff;
20-
// --color-foreground: #1f2023;
21-
// --color-accent: #5c6ac4;
23+
.dark-mode {
24+
--color: #ffffff;
25+
--color-background: #000000;
26+
--color-foreground: #ffffff;
27+
--color-accent: #5c6ac4;
2228
}
2329

24-
// @media (prefers-color-scheme: light) {
25-
// :root {
26-
// --color-background: #1f2023;
27-
// --color-foreground: #ffffff;
28-
// }
29-
// }
30+
body {
31+
background-color: var(--color-background);
32+
color: var(--color);
33+
}

0 commit comments

Comments
 (0)