Branchwell

AI Resource Pro / website · airesourcepro.com / src / components / theme / theme-toggle.tsx

Raw 1.0 KB on b7854f3692d64213a2fce644d0b5101d3e345b03
1"use client";
2
3import { useEffect, useState } from "react";
4import { Moon, Sun } from "lucide-react";
5import { useTheme } from "next-themes";
6import { cn } from "@/lib/utils";
7
8// Switches between the light and dark themes
9export function ThemeToggle({ className }: { className?: string }) {
10 const { resolvedTheme, setTheme } = useTheme();
11 const [mounted, setMounted] = useState(false);
12 useEffect(() => setMounted(true), []);
13
14 const isDark = !mounted || resolvedTheme !== "light";
15 return (
16 <button
17 type="button"
18 onClick={() => setTheme(isDark ? "light" : "dark")}
19 aria-label={isDark ? "Switch to light theme" : "Switch to dark theme"}
20 title={isDark ? "Light theme" : "Dark theme"}
21 className={cn(
22 "flex h-9 w-9 items-center justify-center rounded-full border border-foreground/15 text-[var(--ash)] transition-colors hover:border-foreground/40 hover:text-foreground",
23 className
24 )}
25 >
26 {isDark ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
27 </button>
28 );
29}