mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 14:44:12 +00:00
fix: add theme icon to index page
This commit is contained in:
parent
8a43d9978b
commit
2df5496b46
2 changed files with 37 additions and 3 deletions
31
src/components/home/ThemeIcon.tsx
Normal file
31
src/components/home/ThemeIcon.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { useContext } from "react";
|
||||
import { ThemeContext } from "@/context/Theme";
|
||||
import { MoonIcon, SunIcon, SunMoonIcon } from "lucide-react";
|
||||
|
||||
function ThemeIcon() {
|
||||
const { theme, setTheme } = useContext(ThemeContext);
|
||||
|
||||
const onClick = () => {
|
||||
const nextTheme = theme === "light" ? "dark" : theme === "dark" ? "system" : "light";
|
||||
setTheme(nextTheme);
|
||||
};
|
||||
|
||||
const getIcon = () => {
|
||||
switch (theme) {
|
||||
case "light":
|
||||
return <SunIcon size={30} />;
|
||||
case "dark":
|
||||
return <MoonIcon size={30} />;
|
||||
case "system":
|
||||
return <SunMoonIcon size={30} />;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<button onClick={onClick} title={theme} className="text-white">
|
||||
{getIcon()}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ThemeIcon;
|
||||
Loading…
Add table
Add a link
Reference in a new issue