From 8bf79e3646fc75e7dcf0e6475d18abd3be344fd3 Mon Sep 17 00:00:00 2001 From: Amirhossein Khalili Date: Sat, 3 Oct 2026 09:53:20 +0330 Subject: [PATCH] feat: add theme toggle to mobile profile menu --- src/components/ModeToggle.tsx | 54 +++++++++++++++++++++++++++++------ src/components/Navbar.tsx | 9 +++--- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/components/ModeToggle.tsx b/src/components/ModeToggle.tsx index aff11ce..9e69b7d 100644 --- a/src/components/ModeToggle.tsx +++ b/src/components/ModeToggle.tsx @@ -1,21 +1,57 @@ import { Button } from "@/components/ui/button"; +import { DropdownMenuCheckboxItem } from "@/components/ui/dropdown-menu"; import { useTheme } from "@/components/ThemeProvider"; import { cn } from "@/lib/utils"; import { Moon, Sun } from "lucide-react"; -export default function ModeToggle({ className }: { className?: string }) { - const { theme, setTheme } = useTheme(); +type ModeToggleProps = { + className?: string; + variant?: "icon" | "menu"; +}; + +export default function ModeToggle({ className, variant = "icon" }: ModeToggleProps) { + const { theme, resolvedTheme, setTheme } = useTheme(); + const isDark = resolvedTheme === "dark" || theme === "dark"; const handleToggle = () => { - if (theme === "system" && typeof window !== "undefined") { - const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false; - setTheme(prefersDark ? "light" : "dark"); - return; - } - - setTheme(theme === "dark" ? "light" : "dark"); + setTheme(isDark ? "light" : "dark"); }; + if (variant === "menu") { + return ( + setTheme(checked ? "dark" : "light")} + onSelect={(event) => event.preventDefault()} + className={cn( + "my-1 justify-between gap-3 rounded-xl px-3 py-3 text-foreground focus:bg-secondary focus:text-foreground [&>span:first-child]:hidden", + className, + )} + aria-label="حالت نمایش" + > + + {isDark ? : } + حالت نمایش + + + ); + } + return (