Files
kfpa-cx-dash-front/src/components/layout/Header.tsx

111 lines
3.9 KiB
TypeScript

'use client'
import Image from "next/image";
import {Button} from "@/components/ui/button";
import {LogIn, LogOut} from "lucide-react";
import {cn} from "@/lib/utils";
import {SITE_TITLE} from "@/config/kfpa.config";
import {TopMenuItem} from "@/config/menu.type";
import {usePathname} from "next/navigation";
interface HeaderProps {
topMenus: TopMenuItem[];
userName: string;
isAdmin: boolean;
isAuthenticated: boolean;
baseDateLabel: string;
onNavigate: (path: string) => void;
onLogin: () => void;
onLogout: () => void;
}
const Header = ({
topMenus,
userName,
isAdmin,
isAuthenticated,
baseDateLabel,
onNavigate,
onLogin,
onLogout,
}: HeaderProps) => {
const pathname = usePathname();
return (
<header className="app-header sticky top-0 z-40">
<div className="relative grid h-[4rem] grid-cols-[10rem_minmax(0,1fr)_minmax(12rem,auto)] grid-rows-[2rem_2rem] items-center gap-x-4 px-4">
<div className="row-span-2 flex h-full min-w-0 items-center">
<button
type="button"
className="flex h-full w-37 cursor-pointer items-center justify-center gap-2 bg-transparent p-0"
onClick={() => onNavigate("/")}
>
<Image
src="/head_logo.png"
alt="logo"
width={150}
height={90}
className="object-contain"
priority
/>
</button>
</div>
<div className="pointer-events-none absolute left-1/2 top-0 flex h-10 -translate-x-1/2 items-center justify-center">
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
</div>
<div className="col-start-3 row-start-1 flex min-w-0 items-center justify-end gap-4">
{isAdmin && (
<>
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
{userName}
</span>
<Button
className="gap-2 border border-transparent bg-green-600 text-white w-25 shadow-sm hover:bg-green-500 hover:text-white"
onClick={isAuthenticated ? onLogout : onLogin}
>
{isAuthenticated ? (
<>
<LogOut className="w-4 h-4" />
<span className="hidden sm:inline">로그아웃</span>
</>
) : (
<>
<LogIn className="w-4 h-4" />
<span className="hidden sm:inline">로그인</span>
</>
)}
</Button>
</>
)}
</div>
<nav className="col-start-2 row-start-2 flex min-w-0 items-center gap-3 overflow-hidden pb-1.5">
{topMenus.map((topMenu) => {
const active = topMenu.match?.(pathname) ?? pathname === topMenu.path;
return (
<button
key={topMenu.id}
type="button"
onClick={() => onNavigate(topMenu.path)}
className={cn(
"relative inline-flex h-5 cursor-pointer items-center font-bold transition-colors",
"content-text-lg bg-transparent px-1",
active
? "text-header-primary"
: "text-header-secondary-hover"
)}
>
{topMenu.label}
</button>
);
})}
</nav>
<div className="col-start-3 row-start-2 flex min-w-0 items-center justify-end gap-4 content-text-base font-bold text-header-color">
{baseDateLabel}
</div>
</div>
</header>
);
}
export default Header;