diff --git a/src/layouts/DarkLightToggle.tsx b/src/layouts/DarkLightToggle.tsx index 246784c44..8feff13ff 100644 --- a/src/layouts/DarkLightToggle.tsx +++ b/src/layouts/DarkLightToggle.tsx @@ -1,29 +1,39 @@ +import React from "react"; + export default function DarkLightToggle() { + const [isdark, setIsdark] = React.useState( + localStorage.getItem('isdark') === 'true' ? true : false + ); + React.useEffect(() => { + localStorage.setItem('isdark', JSON.stringify(isdark)); + }, [isdark]); return ( ); diff --git a/src/layouts/ThemeMenu.tsx b/src/layouts/ThemeMenu.tsx index 2e23d704c..e9814f0c4 100644 --- a/src/layouts/ThemeMenu.tsx +++ b/src/layouts/ThemeMenu.tsx @@ -9,6 +9,11 @@ interface ThemeMenuProps { const ThemeMenu: React.FC = (props) => { const { t } = useTranslation(); const [open, setOpen] = React.useState(false); + const [theme, setTheme] = React.useState(localStorage.getItem('theme')); + React.useEffect(() => { + localStorage.setItem('theme', theme===null?'default':theme); + }, [theme]); + const themeList = ['default', 'retro', 'cyberpunk', 'valentine', 'aqua']; React.useEffect(() => { document?.activeElement instanceof HTMLElement && @@ -58,51 +63,21 @@ const ThemeMenu: React.FC = (props) => { tabIndex={0} className="menu dropdown-content z-[2] w-32 rounded-box bg-base-100 p-2 shadow-2xl" > -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • + {themeList.map((x)=>{ + return ( +
  • + {setTheme(x)}} + /> +
  • + ) + })}