-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dark mode): Started to do the base code for a dark mode
- Loading branch information
1 parent
89ca538
commit 30e489c
Showing
6 changed files
with
104 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,5 @@ next-env.d.ts | |
|
||
# Local Netlify folder | ||
.netlify | ||
|
||
certificates |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
export default function DarkMode(): JSX.Element { | ||
const [isDarkMode, setIsDarkMode] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const darkModePreference = localStorage.getItem("dark-mode"); | ||
if (darkModePreference !== null) { | ||
setIsDarkMode(darkModePreference === "true"); | ||
} else { | ||
setIsDarkMode(window.matchMedia("(prefers-color-scheme: dark)").matches); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (isDarkMode) { | ||
document.body.classList.remove("light"); | ||
document.body.classList.add("dark"); | ||
} else { | ||
document.body.classList.remove("dark"); | ||
document.body.classList.add("light"); | ||
} | ||
}, [isDarkMode]); | ||
|
||
function handleDarkMode() { | ||
const newDarkMode = !isDarkMode; | ||
setIsDarkMode(newDarkMode); | ||
localStorage.setItem("dark-mode", newDarkMode.toString()); | ||
} | ||
|
||
return ( | ||
<button className="darkModeToggle" onClick={handleDarkMode}>{!isDarkMode ? "☀️" : "🌙"}</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters