-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathCustomTitlebar.tsx
More file actions
257 lines (238 loc) · 9.37 KB
/
CustomTitlebar.tsx
File metadata and controls
257 lines (238 loc) · 9.37 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import React, { useState, useRef, useEffect } from 'react';
import { motion } from 'framer-motion';
import { Settings, Minus, Square, X, Bot, BarChart3, FileText, Network, Info, MoreVertical } from 'lucide-react';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { TooltipProvider, TooltipSimple } from '@/components/ui/tooltip-modern';
interface CustomTitlebarProps {
onSettingsClick?: () => void;
onAgentsClick?: () => void;
onUsageClick?: () => void;
onClaudeClick?: () => void;
onMCPClick?: () => void;
onInfoClick?: () => void;
}
export const CustomTitlebar: React.FC<CustomTitlebarProps> = ({
onSettingsClick,
onAgentsClick,
onUsageClick,
onClaudeClick,
onMCPClick,
onInfoClick
}) => {
const [isHovered, setIsHovered] = useState(false);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsDropdownOpen(false);
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, []);
const handleMinimize = async () => {
try {
const window = getCurrentWindow();
await window.minimize();
console.log('Window minimized successfully');
} catch (error) {
console.error('Failed to minimize window:', error);
}
};
const handleMaximize = async () => {
try {
const window = getCurrentWindow();
const isMaximized = await window.isMaximized();
if (isMaximized) {
await window.unmaximize();
console.log('Window unmaximized successfully');
} else {
await window.maximize();
console.log('Window maximized successfully');
}
} catch (error) {
console.error('Failed to maximize/unmaximize window:', error);
}
};
const handleClose = async () => {
try {
const window = getCurrentWindow();
await window.close();
console.log('Window closed successfully');
} catch (error) {
console.error('Failed to close window:', error);
}
};
return (
<TooltipProvider>
<div
className="relative z-[200] h-11 bg-background/95 backdrop-blur-sm flex items-center justify-between select-none border-b border-border/50 tauri-drag"
data-tauri-drag-region
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
{/* Left side - macOS Traffic Light buttons */}
<div className="flex items-center space-x-2 pl-5">
<div className="flex items-center space-x-2">
{/* Close button */}
<button
onClick={(e) => {
e.stopPropagation();
handleClose();
}}
className="group relative w-3 h-3 rounded-full bg-red-500 hover:bg-red-600 transition-all duration-200 flex items-center justify-center tauri-no-drag"
title="Close"
>
{isHovered && (
<X size={8} className="text-red-900 opacity-60 group-hover:opacity-100" />
)}
<span className="sr-only">Close window</span>
</button>
{/* Minimize button */}
<button
onClick={(e) => {
e.stopPropagation();
handleMinimize();
}}
className="group relative w-3 h-3 rounded-full bg-yellow-500 hover:bg-yellow-600 transition-all duration-200 flex items-center justify-center tauri-no-drag"
title="Minimize"
>
{isHovered && (
<Minus size={8} className="text-yellow-900 opacity-60 group-hover:opacity-100" />
)}
<span className="sr-only">Minimize window</span>
</button>
{/* Maximize button */}
<button
onClick={(e) => {
e.stopPropagation();
handleMaximize();
}}
className="group relative w-3 h-3 rounded-full bg-green-500 hover:bg-green-600 transition-all duration-200 flex items-center justify-center tauri-no-drag"
title="Maximize"
>
{isHovered && (
<Square size={6} className="text-green-900 opacity-60 group-hover:opacity-100" />
)}
<span className="sr-only">Maximize window</span>
</button>
</div>
</div>
{/* Center - Title (hidden) */}
{/* <div
className="absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 pointer-events-none"
data-tauri-drag-region
>
<span className="text-sm font-medium text-foreground/80">{title}</span>
</div> */}
{/* Right side - Navigation icons with improved spacing */}
<div className="flex items-center pr-5 gap-3 tauri-no-drag">
{/* Primary actions group */}
<div className="flex items-center gap-1">
{onAgentsClick && (
<TooltipSimple content="Agents" side="bottom">
<motion.button
onClick={onAgentsClick}
whileTap={{ scale: 0.97 }}
transition={{ duration: 0.15 }}
className="p-2 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors tauri-no-drag"
>
<Bot size={16} />
<span className="sr-only">Agents</span>
</motion.button>
</TooltipSimple>
)}
{onUsageClick && (
<TooltipSimple content="Usage Dashboard" side="bottom">
<motion.button
onClick={onUsageClick}
whileTap={{ scale: 0.97 }}
transition={{ duration: 0.15 }}
className="p-2 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors tauri-no-drag"
>
<BarChart3 size={16} />
<span className="sr-only">Usage Dashboard</span>
</motion.button>
</TooltipSimple>
)}
</div>
{/* Visual separator */}
<div className="w-px h-5 bg-border/50" />
{/* Secondary actions group */}
<div className="flex items-center gap-1">
{onSettingsClick && (
<TooltipSimple content="Settings" side="bottom">
<motion.button
onClick={onSettingsClick}
whileTap={{ scale: 0.97 }}
transition={{ duration: 0.15 }}
className="p-2 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors tauri-no-drag"
>
<Settings size={16} />
<span className="sr-only">Settings</span>
</motion.button>
</TooltipSimple>
)}
{/* Dropdown menu for additional options */}
<div className="relative" ref={dropdownRef}>
<TooltipSimple content="More options" side="bottom">
<motion.button
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
whileTap={{ scale: 0.97 }}
transition={{ duration: 0.15 }}
className="p-2 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors flex items-center gap-1"
>
<MoreVertical size={16} />
<span className="sr-only">More options</span>
</motion.button>
</TooltipSimple>
{isDropdownOpen && (
<div className="absolute right-0 mt-2 w-48 bg-popover border border-border rounded-lg shadow-lg z-[250]">
<div className="py-1">
{onClaudeClick && (
<button
onClick={() => {
onClaudeClick();
setIsDropdownOpen(false);
}}
className="w-full px-4 py-2 text-left text-sm hover:bg-accent hover:text-accent-foreground transition-colors flex items-center gap-3"
>
<FileText size={14} />
<span>CLAUDE.md</span>
</button>
)}
{onMCPClick && (
<button
onClick={() => {
onMCPClick();
setIsDropdownOpen(false);
}}
className="w-full px-4 py-2 text-left text-sm hover:bg-accent hover:text-accent-foreground transition-colors flex items-center gap-3"
>
<Network size={14} />
<span>MCP Servers</span>
</button>
)}
{onInfoClick && (
<button
onClick={() => {
onInfoClick();
setIsDropdownOpen(false);
}}
className="w-full px-4 py-2 text-left text-sm hover:bg-accent hover:text-accent-foreground transition-colors flex items-center gap-3"
>
<Info size={14} />
<span>About</span>
</button>
)}
</div>
</div>
)}
</div>
</div>
</div>
</div>
</TooltipProvider>
);
};