feat: 侧边栏可点击折叠/展开
顶栏左侧新增切换按钮,点击后左侧菜单在 w-60↔w-0 间平滑伸缩隐藏。 折叠状态通过 SidebarProvider(context) 在侧边栏与顶栏间共享。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,13 +6,22 @@ import { cn } from "@/lib/utils";
|
||||
import { copyright } from "@/lib/brand";
|
||||
import { BrandLogo } from "./brand-logo";
|
||||
import { navSections, activeHref } from "./nav";
|
||||
import { useSidebar } from "./sidebar-context";
|
||||
|
||||
export function Sidebar() {
|
||||
const pathname = usePathname();
|
||||
const active = activeHref(pathname);
|
||||
const { collapsed } = useSidebar();
|
||||
|
||||
return (
|
||||
<aside className="flex w-60 shrink-0 flex-col bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]">
|
||||
<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="/">
|
||||
@@ -54,6 +63,7 @@ export function Sidebar() {
|
||||
<div className="px-5 py-4 text-[11px] text-[var(--color-sidebar-muted)]">
|
||||
{copyright()}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user