-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.jsx
More file actions
50 lines (46 loc) · 2.54 KB
/
Window.jsx
File metadata and controls
50 lines (46 loc) · 2.54 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
import { useState, useRef } from 'react';
import { motion } from 'framer-motion';
import { X, Minus, Square, Terminal as TerminalIcon } from 'lucide-react';
export default function Window({ title, children, icon, onClose, isFocused, onFocus, initialPosition = { x: 100, y: 100 } }) {
const [isMaximized, setIsMaximized] = useState(false);
// Drag constraints could be the parent desktop ref usually.
return (
<motion.div
drag={!isMaximized}
dragMomentum={false}
initial={initialPosition}
animate={isMaximized ? { x: 0, y: 0, width: '100%', height: '100%' } : { width: '800px', height: '550px' }}
onMouseDown={onFocus}
className={`absolute flex flex-col pointer-events-auto bg-[#1c1d1f] border border-[#333] shadow-2xl overflow-hidden rounded-t-lg
${isFocused ? 'z-40 border-blue-500/50 ring-1 ring-blue-500/20' : 'z-10 opacity-90'}
`}
style={{ top: 0, left: 0 }} // Position handled by motion
>
{/* Window Title Bar */}
<div
className="h-8 bg-[#252525] flex items-center justify-between px-2 select-none cursor-default"
onDoubleClick={() => setIsMaximized(!isMaximized)}
>
<div className="flex items-center gap-2">
{icon || <TerminalIcon size={14} className="text-gray-400" />}
<span className="text-xs font-bold text-gray-300">{title}</span>
</div>
<div className="flex items-center gap-2">
<button className="p-1 hover:bg-white/10 rounded-full" onClick={() => {/* Minimize logic */ }}>
<Minus size={12} className="text-gray-400" />
</button>
<button className="p-1 hover:bg-white/10 rounded-full" onClick={() => setIsMaximized(!isMaximized)}>
<Square size={10} className="text-gray-400" />
</button>
<button className="p-1 hover:bg-red-500 rounded-full group" onClick={onClose}>
<X size={12} className="text-gray-400 group-hover:text-white" />
</button>
</div>
</div>
{/* Window Content */}
<div className="flex-1 overflow-auto bg-[#0d1117] text-gray-200 p-2 font-mono text-sm scrollbar-thin scrollbar-thumb-gray-700 scrollbar-track-transparent">
{children}
</div>
</motion.div>
);
}