forked from GDSC-Jadavpur-University/GDSC-JU-Website
-
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.
added theme toggle button to the website
- Loading branch information
1 parent
8d5a56e
commit 02b146e
Showing
6 changed files
with
2,596 additions
and
153 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
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,27 @@ | ||
import { useTheme } from "next-themes"; | ||
import { SunIcon, MoonIcon } from "@heroicons/react/24/solid"; | ||
import { useState, useEffect } from "react"; | ||
|
||
export const ThemeSwitcher = () => { | ||
const { theme, setTheme } = useTheme(); | ||
|
||
// handle hydration error | ||
const [mounted, setMounted] = useState(false); | ||
useEffect(() => setMounted(true), []); | ||
if (!mounted) return null; | ||
|
||
return ( | ||
<button | ||
aria-label="Toggle Dark Mode" | ||
type="button" | ||
className="flex items-center justify-center rounded-lg p-2 transition-colors hover:bg-zinc-300 dark:hover:bg-zinc-700" | ||
onClick={() => setTheme(theme === "dark" ? "light" : "dark")} | ||
> | ||
{theme === "dark" ? ( | ||
<SunIcon className="h-5 w-5 text-orange-300" /> | ||
) : ( | ||
<MoonIcon className="h-5 w-5 text-slate-800" /> | ||
)} | ||
</button> | ||
); | ||
}; |
Oops, something went wrong.