el.xwx.moe/components/ToggleDarkMode.tsx

30 lines
832 B
TypeScript
Raw Normal View History

2023-08-02 12:53:55 -05:00
import { useTheme } from "next-themes";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSun, faMoon } from "@fortawesome/free-solid-svg-icons";
export default function ToggleDarkMode() {
const { theme, setTheme } = useTheme();
const handleToggle = () => {
if (theme === "dark") {
setTheme("light");
} else {
setTheme("dark");
}
};
return (
<div
2023-08-10 23:25:02 -05:00
className="flex gap-1 duration-100 h-10 rounded-full items-center w-fit cursor-pointer"
2023-08-02 12:53:55 -05:00
onClick={handleToggle}
>
2023-08-10 23:25:02 -05:00
<div className="shadow bg-sky-700 dark:bg-sky-400 flex items-center justify-center rounded-full text-white w-10 h-10 duration-100">
2023-08-02 12:53:55 -05:00
<FontAwesomeIcon
icon={theme === "dark" ? faSun : faMoon}
className="w-1/2 h-1/2"
/>
</div>
</div>
);
}