2024-05-14 08:56:54 +00:00
|
|
|
"use client";
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
// next theme
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-09-01 11:12:30 +00:00
|
|
|
import { useTheme } from "next-themes";
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
// mobx react lite
|
|
|
|
|
|
|
|
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-12-10 10:18:10 +00:00
|
|
|
className="relative grid h-7 w-7 place-items-center rounded bg-custom-background-100 text-custom-text-100 hover:bg-custom-background-80"
|
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
|
|
|
);
|
|
|
|
});
|