Files
liandong-crm/src/components/app/sidebar.tsx
T

70 lines
2.3 KiB
TypeScript
Raw Normal View History

"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import { copyright } from "@/lib/brand";
import { BrandLogo } from "./brand-logo";
import { navSections, activeHref } from "./nav";
2026-07-11 22:56:04 +08:00
import { useSidebar } from "./sidebar-context";
export function Sidebar() {
const pathname = usePathname();
const active = activeHref(pathname);
2026-07-11 22:56:04 +08:00
const { collapsed } = useSidebar();
return (
2026-07-11 22:56:04 +08:00
<aside
className={cn(
"shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",
collapsed ? "w-0" : "w-60"
)}
>
{/* 固定宽度内容容器:折叠时被外层裁剪,形成平滑滑动而非挤压 */}
<div className="flex h-full w-60 flex-col bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]">
{/* 品牌 */}
<div className="flex h-16 items-center px-5">
<Link href="/">
<BrandLogo size={36} invert />
</Link>
</div>
<nav className="flex-1 space-y-6 overflow-y-auto px-3 py-4">
{navSections.map((section) => (
<div key={section.title}>
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
{section.title}
</div>
<div className="space-y-1">
{section.items.map((item) => {
const Icon = item.icon;
const isActive = active === item.href;
return (
<Link
key={item.href}
href={item.href}
className={cn(
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors",
isActive
? "bg-[var(--color-primary)] text-white shadow-sm"
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
)}
>
<Icon className="h-[18px] w-[18px]" />
{item.label}
</Link>
);
})}
</div>
</div>
))}
</nav>
<div className="px-5 py-4 text-[11px] text-[var(--color-sidebar-muted)]">
{copyright()}
</div>
2026-07-11 22:56:04 +08:00
</div>
</aside>
);
}