Skip to content

Commit b1a2ae8

Browse files
committed
Update Light Mode UX
1 parent aad1e9a commit b1a2ae8

File tree

4 files changed

+204
-81
lines changed

4 files changed

+204
-81
lines changed

public/index.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
<title>Yuting Zhou</title>
1515
<meta name="description" content="Self Developed personal website build with React.js">
1616

17+
<!-- Match App.js theme init before paint to avoid navbar / preloader color flash -->
18+
<script>
19+
(function () {
20+
try {
21+
var t = localStorage.getItem("theme");
22+
if (t === "light" || t === "dark") {
23+
document.documentElement.setAttribute("data-theme", t);
24+
} else if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
25+
document.documentElement.setAttribute("data-theme", "light");
26+
} else {
27+
document.documentElement.setAttribute("data-theme", "dark");
28+
}
29+
} catch (e) {
30+
document.documentElement.setAttribute("data-theme", "dark");
31+
}
32+
})();
33+
</script>
34+
1735
<!-- Google / Search Engine Tags -->
1836
<meta itemprop="name" content="Yuting Zhou">
1937
<meta itemprop="description" content="Self Developed personal website build with React.js">
@@ -36,7 +54,7 @@
3654
content="https://raw.githubusercontent.com/soumyajit4419/Portfolio/master/Images/readme-img.png?token=AK7VCIF5RYEUZZAURELPTAC76U6AK">
3755
</head>
3856

39-
<body>
57+
<body class="preloader-active">
4058
<noscript>You need to enable JavaScript to run this app.</noscript>
4159
<div id="root"></div>
4260
</body>

src/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ function App() {
3434
}
3535
}, [theme]);
3636

37+
useEffect(() => {
38+
if (typeof document === "undefined") return;
39+
if (load) {
40+
document.body.classList.add("preloader-active");
41+
} else {
42+
document.body.classList.remove("preloader-active");
43+
}
44+
}, [load]);
45+
3746
useEffect(() => {
3847
const mediaQuery = window.matchMedia('(prefers-color-scheme: light)');
3948
const handleChange = (e) => {

src/components/Home/Home2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function Home2() {
108108
href={link.href}
109109
target={link.onClick ? "_self" : "_blank"}
110110
rel="noopener noreferrer"
111-
className="social-icon-color home-social-icons"
111+
className="home-social-icons"
112112
aria-label={link.ariaLabel}
113113
onClick={link.onClick}
114114
>

0 commit comments

Comments
 (0)