Topbar.tsx
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useLocation, useNavigate } from 'react-router-dom';
import { Moon, Sun, Plus, ChevronRight, PanelLeft } from 'lucide-react';
import { navItems } from './nav';
import { useTheme } from '@/lib/theme';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
export function Topbar({
onExpand,
collapsed,
}: {
onExpand: () => void;
collapsed: boolean;
}) {
const { pathname } = useLocation();
const navigate = useNavigate();
const { theme, toggle } = useTheme();
const current =
navItems.find((n) => (n.end ? pathname === n.to : pathname.startsWith(n.to))) ??
navItems[0];
return (
<header className="sticky top-0 z-10 flex h-16 items-center justify-between gap-4 border-b border-border/70 bg-background/70 px-6 glass dark:shadow-[0_1px_0_0_rgba(255,255,255,0.05),0_16px_44px_-22px_rgba(0,0,0,0.7)]">
<div className="flex min-w-0 items-center gap-3">
{collapsed && (
<button
onClick={onExpand}
className="flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
title="展开侧栏"
>
<PanelLeft className="h-5 w-5" />
</button>
)}
<div className="min-w-0 animate-fade-in">
<div className="flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wider text-muted-foreground">
<span>CodeRio Studio</span>
<ChevronRight className="h-3 w-3" />
<span className="text-foreground/70">{current.label}</span>
</div>
<h1 className="truncate text-lg font-semibold leading-tight tracking-tight">
{current.label}
</h1>
</div>
</div>
<div className="flex items-center gap-2">
<button
onClick={toggle}
className="flex h-9 w-9 items-center justify-center rounded-lg border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
title={theme === 'dark' ? '切换到浅色' : '切换到深色'}
>
{theme === 'dark' ? (
<Sun className="h-[18px] w-[18px]" />
) : (
<Moon className="h-[18px] w-[18px]" />
)}
</button>
<Button
className={cn(
'brand-gradient shadow-lg shadow-primary/25 transition-transform hover:scale-[1.02]',
)}
onClick={() => navigate('/')}
>
<Plus className="h-4 w-4" />
新建生成
</Button>
</div>
</header>
);
}