mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
fix darkmode
This commit is contained in:
@ -8,6 +8,14 @@ const DarkModeBtn = () => {
|
|||||||
const { mounted } = useMounted();
|
const { mounted } = useMounted();
|
||||||
const { systemTheme, theme, setTheme } = useTheme();
|
const { systemTheme, theme, setTheme } = useTheme();
|
||||||
const currentTheme = theme === 'system' ? systemTheme : theme;
|
const currentTheme = theme === 'system' ? systemTheme : theme;
|
||||||
|
const handleTheme = (type: 'light' | 'dark') => () => {
|
||||||
|
const map = {
|
||||||
|
light: 'latte',
|
||||||
|
dark: 'mocha',
|
||||||
|
};
|
||||||
|
document.body.className = map[type];
|
||||||
|
setTheme(type);
|
||||||
|
};
|
||||||
|
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return (
|
return (
|
||||||
@ -26,11 +34,11 @@ const DarkModeBtn = () => {
|
|||||||
<>
|
<>
|
||||||
{currentTheme === 'dark' ? (
|
{currentTheme === 'dark' ? (
|
||||||
<button>
|
<button>
|
||||||
<FiSun className="w-5 h-5" onClick={() => setTheme('light')} />
|
<FiSun className="w-5 h-5" onClick={handleTheme('light')} />
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<button>
|
<button>
|
||||||
<FiMoon className="w-5 h-5" onClick={() => setTheme('dark')} />
|
<FiMoon className="w-5 h-5" onClick={handleTheme('dark')} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
Reference in New Issue
Block a user