Skip to content

Commit

Permalink
added theme toggle button to the website
Browse files Browse the repository at this point in the history
  • Loading branch information
0xankityadav committed Oct 3, 2023
1 parent 8d5a56e commit 02b146e
Show file tree
Hide file tree
Showing 6 changed files with 2,596 additions and 153 deletions.
5 changes: 5 additions & 0 deletions components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
FaGithub,
} from "react-icons/fa";

import { ThemeSwitcher } from "./ThemeSwitcher";

function Footer() {
const socials = [
{
Expand Down Expand Up @@ -103,6 +105,9 @@ function Footer() {
))}
</div>
</div>
<div className="flex justify-end mr-20">
<ThemeSwitcher />
</div>
</footer>
);
}
Expand Down
27 changes: 27 additions & 0 deletions components/ThemeSwitcher.jsx
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>
);
};
Loading

0 comments on commit 02b146e

Please sign in to comment.