Sidebar.tsx
4.42 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { NavLink } from 'react-router-dom';
import {
PanelLeftClose,
PanelLeft,
Zap,
type LucideIcon,
} from 'lucide-react';
import { navItems, brandIcon } from './nav';
import { cn } from '@/lib/utils';
import { useConnection } from '@/lib/connection';
function ConnDot() {
const { connected } = useConnection();
return (
<span className="flex items-center gap-2 text-xs">
<span
className={cn(
'relative inline-flex h-2 w-2 rounded-full',
connected ? 'bg-emerald-500 text-emerald-500' : 'bg-rose-500 text-rose-500',
)}
>
{connected && (
<span className="pulse-ring absolute inset-0 rounded-full" />
)}
</span>
<span className="text-muted-foreground">
{connected ? '服务在线' : '连接断开'}
</span>
</span>
);
}
export function Sidebar({
collapsed,
onToggle,
}: {
collapsed: boolean;
onToggle: () => void;
}) {
return (
<aside
className={cn(
'relative z-20 flex shrink-0 flex-col border-r border-border/70 bg-card/60 glass transition-[width] duration-300 ease-in-out dark:shadow-[1px_0_0_0_rgba(255,255,255,0.05),16px_0_44px_-22px_rgba(0,0,0,0.7)]',
collapsed ? 'w-[76px]' : 'w-64',
)}
>
{/* Brand */}
<div
className={cn(
'flex h-16 items-center gap-3 border-b border-border/70 px-5',
collapsed && 'justify-center px-0',
)}
>
<div className="brand-gradient flex h-9 w-9 shrink-0 items-center justify-center rounded-xl shadow-lg shadow-primary/20">
{(() => {
const Icon: LucideIcon = brandIcon;
return <Icon className="h-5 w-5 text-white" />;
})()}
</div>
{!collapsed && (
<div className="min-w-0 animate-fade-in">
<div className="truncate text-[15px] font-semibold tracking-tight">
CodeRio <span className="text-primary">Studio</span>
</div>
<div className="truncate text-[11px] text-muted-foreground">
设计转代码指挥中心
</div>
</div>
)}
</div>
{/* Nav */}
<nav className="flex-1 space-y-1 p-3">
{navItems.map((item) => (
<NavLink
key={item.to}
to={item.to}
end={item.end}
title={collapsed ? item.label : undefined}
className={({ isActive }) =>
cn(
'group relative flex items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium transition-all',
collapsed && 'justify-center px-0',
isActive
? 'bg-primary/10 text-foreground'
: 'text-muted-foreground hover:bg-accent hover:text-foreground',
)
}
>
{({ isActive }) => (
<>
{isActive && (
<span className="absolute left-0 top-1/2 h-5 w-1 -translate-y-1/2 rounded-r-full bg-primary" />
)}
<item.icon
className={cn(
'h-[18px] w-[18px] shrink-0 transition-colors',
isActive && 'text-primary',
)}
/>
{!collapsed && <span className="truncate">{item.label}</span>}
</>
)}
</NavLink>
))}
</nav>
{/* Footer */}
<div className="space-y-3 border-t border-border/70 p-3">
{!collapsed && (
<div className="flex items-center justify-between px-2">
<ConnDot />
<span className="flex items-center gap-1 text-[10px] text-muted-foreground">
<Zap className="h-3 w-3 text-primary" /> v0.1
</span>
</div>
)}
{collapsed && (
<div className="flex justify-center">
<ConnDot />
</div>
)}
<button
onClick={onToggle}
className={cn(
'flex w-full items-center gap-2 rounded-lg px-3 py-2 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground',
collapsed && 'justify-center px-0',
)}
>
{collapsed ? (
<PanelLeft className="h-4 w-4" />
) : (
<>
<PanelLeftClose className="h-4 w-4" />
收起侧栏
</>
)}
</button>
</div>
</aside>
);
}