2023-09-01 11:12:30 +00:00
|
|
|
// next theme
|
|
|
|
import { useTheme } from "next-themes";
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
// mobx react lite
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-09-01 15:08:53 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
export const NavbarTheme = observer(() => {
|
2023-09-01 15:08:53 +00:00
|
|
|
const [appTheme, setAppTheme] = useState("light");
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
const { setTheme, theme } = useTheme();
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
const handleTheme = () => {
|
2023-09-01 11:12:30 +00:00
|
|
|
setTheme(theme === "light" ? "dark" : "light");
|
2023-08-11 11:48:33 +00:00
|
|
|
};
|
|
|
|
|
2023-09-01 15:08:53 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!theme) return;
|
|
|
|
|
|
|
|
setAppTheme(theme);
|
|
|
|
}, [theme]);
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
return (
|
2023-09-01 11:12:30 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2023-08-11 11:48:33 +00:00
|
|
|
onClick={handleTheme}
|
2023-09-01 11:12:30 +00:00
|
|
|
className="relative w-7 h-7 grid place-items-center bg-custom-background-100 hover:bg-custom-background-80 text-custom-text-100 rounded"
|
2023-08-11 11:48:33 +00:00
|
|
|
>
|
2023-09-01 15:08:53 +00:00
|
|
|
<span className="material-symbols-rounded text-sm">{appTheme === "light" ? "dark_mode" : "light_mode"}</span>
|
2023-09-01 11:12:30 +00:00
|
|
|
</button>
|
2023-08-11 11:48:33 +00:00
|
|
|
);
|
|
|
|
});
|