backoffice nextJs replaces admin in rust
This commit is contained in:
28
apps/backoffice/app/theme-toggle.tsx
Normal file
28
apps/backoffice/app/theme-toggle.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTheme } from "next-themes";
|
||||
|
||||
export function ThemeToggle() {
|
||||
const { theme, setTheme, resolvedTheme } = useTheme();
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
const activeTheme = theme === "system" ? resolvedTheme : theme;
|
||||
const nextTheme = activeTheme === "dark" ? "light" : "dark";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="theme-toggle"
|
||||
onClick={() => setTheme(nextTheme)}
|
||||
aria-label="Toggle color theme"
|
||||
disabled={!mounted}
|
||||
>
|
||||
{mounted ? (activeTheme === "dark" ? "Dark" : "Light") : "Theme"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user