-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement color theme switcher
- Loading branch information
1 parent
f551b40
commit f0efc76
Showing
9 changed files
with
10,503 additions
and
2,218 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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,25 @@ | ||
import { useState } from "react"; | ||
import { DarkModeSwitch } from "react-toggle-dark-mode"; | ||
import useTheme from "../hooks/useTheme"; | ||
|
||
export default function ThemeSwitcher() { | ||
const [colorTheme, setTheme] = useTheme(); | ||
const [darkSide, setDarkSide] = useState( | ||
colorTheme === "light" ? true : false | ||
); | ||
|
||
const toggleDarkMode = (checked: boolean) => { | ||
setTheme(colorTheme); | ||
setDarkSide(checked); | ||
}; | ||
|
||
return ( | ||
<> | ||
<DarkModeSwitch | ||
checked={darkSide} | ||
onChange={toggleDarkMode} | ||
size={30} | ||
/> | ||
</> | ||
); | ||
} |
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,15 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export default function useThemeSwitcher() { | ||
const [theme, setTheme] = useState<string>(localStorage.theme); | ||
const colorTheme = theme === "dark" ? "light" : "dark"; | ||
|
||
useEffect(() => { | ||
const root = window.document.documentElement; | ||
root.classList.remove(colorTheme); | ||
root.classList.add(theme); | ||
localStorage.setItem('theme', theme); | ||
}, [theme, colorTheme]); | ||
|
||
return [colorTheme, setTheme] as const; | ||
} |
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