-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PxlSyl
authored and
PxlSyl
committed
May 23, 2024
1 parent
dfb9de7
commit 8bc720e
Showing
5 changed files
with
95 additions
and
64 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
File renamed without changes.
78 changes: 15 additions & 63 deletions
78
components/ThemeSwitch.tsx → components/theme/ThemeSwitch.tsx
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,42 @@ | ||
export const Sun = () => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
fill="currentColor" | ||
className="h-6 w-6 text-gray-900 transition-transform duration-300 dark:text-gray-100" | ||
> | ||
<path | ||
fillRule="evenodd" | ||
d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" | ||
clipRule="evenodd" | ||
/> | ||
</svg> | ||
) | ||
|
||
export const Moon = () => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
fill="currentColor" | ||
className="h-6 w-6 text-gray-900 transition-transform duration-300 dark:text-gray-100" | ||
> | ||
<path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" /> | ||
</svg> | ||
) | ||
|
||
export const Monitor = () => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className="h-6 w-6 text-gray-900 transition-transform duration-300 dark:text-gray-100" | ||
> | ||
<rect x="3" y="3" width="14" height="10" rx="2" ry="2"></rect> | ||
<line x1="7" y1="17" x2="13" y2="17"></line> | ||
<line x1="10" y1="13" x2="10" y2="17"></line> | ||
</svg> | ||
) |
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,37 @@ | ||
import { useState, useEffect, useRef } from 'react'; | ||
import { useTheme } from 'next-themes'; | ||
|
||
export const useThemeSwitch = () => { | ||
const [mounted, setMounted] = useState(false); | ||
const { theme, setTheme, resolvedTheme } = useTheme(); | ||
|
||
const [menuOpen, setMenuOpen] = useState(false); | ||
const menubarRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => setMounted(true), []); | ||
|
||
const [darkModeChecked, setDarkModeChecked] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (resolvedTheme === 'dark') { | ||
setDarkModeChecked(true); | ||
} | ||
}, [resolvedTheme]); | ||
|
||
const handleThemeChange = (newTheme: string) => { | ||
setTheme(newTheme); | ||
setDarkModeChecked(newTheme === 'dark'); | ||
setMenuOpen(false); | ||
}; | ||
|
||
return { | ||
mounted, | ||
theme, | ||
menuOpen, | ||
darkModeChecked, | ||
menubarRef, | ||
setDarkModeChecked, | ||
setMenuOpen, | ||
handleThemeChange | ||
}; | ||
}; |