Files
auto-trade/components/theme-toggle.tsx

65 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

/**
* @file components/theme-toggle.tsx
2026-02-11 14:06:06 +09:00
* @description /
* @remarks
* - [] Components/UI
2026-02-11 14:06:06 +09:00
* - [ ] -> /
* - [ ] theme-provider.tsx (next-themes)
*/
"use client";
import * as React from "react";
import { Moon, Sun } from "lucide-react";
import { useTheme } from "next-themes";
2026-02-10 11:16:39 +09:00
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
2026-02-10 11:16:39 +09:00
interface ThemeToggleProps {
className?: string;
iconClassName?: string;
}
/**
*
* @remarks next-themes의 useTheme
2026-02-11 14:06:06 +09:00
* @returns /
* @see features/layout/components/header.tsx Header -
*/
2026-02-10 11:16:39 +09:00
export function ThemeToggle({ className, iconClassName }: ThemeToggleProps) {
2026-02-11 14:06:06 +09:00
const { resolvedTheme, setTheme } = useTheme();
2026-02-11 14:06:06 +09:00
const handleToggleTheme = React.useCallback(() => {
// 시스템 테마 사용 중에도 현재 화면 기준으로 명확히 라이트/다크를 토글합니다.
setTheme(resolvedTheme === "dark" ? "light" : "dark");
}, [resolvedTheme, setTheme]);
2026-02-11 14:06:06 +09:00
return (
<Button
type="button"
variant="ghost"
size="icon"
className={className}
onClick={handleToggleTheme}
aria-label="테마 전환"
>
{/* ========== LIGHT ICON ========== */}
<Sun
className={cn(
"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0",
iconClassName,
)}
/>
{/* ========== DARK ICON ========== */}
<Moon
className={cn(
"absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100",
iconClassName,
)}
/>
<span className="sr-only">Toggle theme</span>
</Button>
);
}