76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
/**
|
|
* @file components/theme-toggle.tsx
|
|
* @description 라이트/다크/시스템 테마 전환 토글 버튼
|
|
* @remarks
|
|
* - [레이어] Components/UI
|
|
* - [사용자 행동] 버튼 클릭 -> 드롭다운 메뉴 -> 테마 선택 -> 즉시 반영
|
|
* - [연관 파일] theme-provider.tsx (next-themes)
|
|
*/
|
|
|
|
"use client";
|
|
|
|
import * as React from "react";
|
|
import { Moon, Sun } from "lucide-react";
|
|
import { useTheme } from "next-themes";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
interface ThemeToggleProps {
|
|
className?: string;
|
|
iconClassName?: string;
|
|
}
|
|
|
|
/**
|
|
* 테마 토글 컴포넌트
|
|
* @remarks next-themes의 useTheme 훅 사용
|
|
* @returns Dropdown 메뉴 형태의 테마 선택기
|
|
*/
|
|
export function ThemeToggle({ className, iconClassName }: ThemeToggleProps) {
|
|
const { setTheme } = useTheme();
|
|
|
|
return (
|
|
<DropdownMenu modal={false}>
|
|
{/* ========== 트리거 버튼 ========== */}
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon" className={className}>
|
|
{/* 라이트 모드 아이콘 (회전 애니메이션) */}
|
|
<Sun
|
|
className={cn(
|
|
"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0",
|
|
iconClassName,
|
|
)}
|
|
/>
|
|
{/* 다크 모드 아이콘 (회전 애니메이션) */}
|
|
<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>
|
|
</DropdownMenuTrigger>
|
|
|
|
{/* ========== 메뉴 컨텐츠 (우측 정렬) ========== */}
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onClick={() => setTheme("light")}>
|
|
Light
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
|
Dark
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onClick={() => setTheme("system")}>
|
|
System
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|