Spaces:
Running
Running
File size: 6,810 Bytes
5c86297 b53e6f3 5c86297 b53e6f3 5c86297 b53e6f3 5c86297 | 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 | import React, { useState } from 'react';
import {
useFloating,
offset,
flip,
shift,
autoUpdate,
useHover,
useDismiss,
useRole,
useInteractions,
FloatingPortal,
} from '@floating-ui/react';
import type { WindowId } from '../../types/windowTypes';
import { useOSStore } from '../../stores/useOSStore';
interface TaskbarWindowItemProps {
id: WindowId | string;
title: string;
shortTitle: string;
icon: string;
isOpen: boolean;
isMinimized: boolean;
isActive: boolean;
isMobile: boolean;
color?: string;
onToggle: (id: WindowId | string) => void;
}
export const TaskbarWindowItem: React.FC<TaskbarWindowItemProps> = ({
id,
title,
shortTitle,
icon,
isOpen,
isMinimized,
isActive,
isMobile,
color,
onToggle,
}) => {
const [isHovered, setIsHovered] = useState(false);
const closeWindow = useOSStore(s => s.closeWindow);
const focusWindow = useOSStore(s => s.focusWindow);
const minimizeWindow = useOSStore(s => s.minimizeWindow);
const {
refs: { setReference, setFloating },
floatingStyles,
context,
} = useFloating({
open: isHovered && !isMobile,
onOpenChange: setIsHovered,
placement: 'top',
middleware: [
offset(10),
flip({ padding: 8 }),
shift({ padding: 8 }),
],
whileElementsMounted: autoUpdate,
});
const hover = useHover(context, {
delay: { open: 350, close: 150 },
restMs: 120,
enabled: !isMobile,
});
const dismiss = useDismiss(context);
const role = useRole(context, { role: 'tooltip' });
const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss, role]);
if (!isOpen) return null;
return (
<>
<button
ref={setReference}
{...getReferenceProps()}
onClick={() => {
setIsHovered(false);
onToggle(id);
}}
className={`h-full ${isMobile ? 'px-2 text-[10px] gap-1' : 'px-4 text-xs gap-2'} border-r-[4px] border-ink-black font-bold font-window-title cursor-pointer transition-all shadow-[inset_0px_3px_0px_rgba(255,255,255,0.8)] text-ink-black ${
isActive && !isMinimized
? 'bg-paper-white font-extrabold translate-y-[2px]'
: 'bg-surface-variant hover:bg-white/40'
}`}
>
<span
className="material-symbols-outlined text-sm font-bold"
style={color && isActive ? { color } : undefined}
>
{icon}
</span>
<span style={color && isActive ? { color } : undefined}>
{isMobile ? shortTitle : title}
</span>
</button>
{/* Retro Arcade Window Preview Hover Card via @floating-ui/react */}
{isHovered && !isMobile && (
<FloatingPortal>
<div
ref={setFloating}
style={floatingStyles}
{...getFloatingProps()}
className="z-[90] w-64 bg-paper-white border-[3px] border-ink-black shadow-[4px_4px_0px_0px_#1E293B] flex flex-col p-3 select-none animate-fade-in pointer-events-auto"
>
{/* Header */}
<div className="flex items-center justify-between border-b-2 border-ink-black/20 pb-1.5 mb-2">
<div className="flex items-center gap-1.5">
<span className="material-symbols-outlined text-base" style={color ? { color } : undefined}>
{icon}
</span>
<span className="font-window-title text-xs font-bold text-ink-black truncate max-w-[140px]">
{title}
</span>
</div>
<span
className={`font-arcade text-[8px] font-bold px-1.5 py-0.5 border border-ink-black ${
isActive && !isMinimized
? 'bg-[#39ff14] text-ink-black'
: isMinimized
? 'bg-amber-200 text-amber-900'
: 'bg-slate-200 text-slate-700'
}`}
>
{isActive && !isMinimized ? 'ACTIVE' : isMinimized ? 'MINIMIZED' : 'BACKGROUND'}
</span>
</div>
{/* Preview visual thumbnail placeholder with scanline styling */}
<div className="w-full h-20 bg-slate-900 border-2 border-ink-black mb-2.5 flex flex-col items-center justify-center p-2 relative overflow-hidden group">
<div className="absolute inset-0 opacity-15 pointer-events-none bg-[radial-gradient(#39ff14_1px,transparent_1px)] [background-size:8px_8px]" />
<span className="material-symbols-outlined text-3xl text-emerald-400 opacity-60 mb-1">
{icon}
</span>
<span className="font-arcade text-[8px] text-emerald-300 tracking-wider">
ALGOSPACED VIEWPORT
</span>
</div>
{/* Quick Actions */}
<div className="flex items-center justify-between gap-1.5 pt-1 border-t border-ink-black/20">
<button
onClick={(e) => {
e.stopPropagation();
setIsHovered(false);
focusWindow(id as string);
}}
className="flex-1 py-1 px-2 bg-emerald-100 hover:bg-emerald-200 border-2 border-ink-black text-ink-black font-window-title text-[10px] font-bold flex items-center justify-center gap-1 transition-colors cursor-pointer"
title="Bring to front"
>
<span className="material-symbols-outlined text-xs">open_in_full</span>
Focus
</button>
<button
onClick={(e) => {
e.stopPropagation();
setIsHovered(false);
minimizeWindow(id as string);
}}
className="py-1 px-2 bg-amber-100 hover:bg-amber-200 border-2 border-ink-black text-ink-black font-window-title text-[10px] font-bold flex items-center justify-center transition-colors cursor-pointer"
title="Minimize window"
>
<span className="material-symbols-outlined text-xs">minimize</span>
</button>
<button
onClick={(e) => {
e.stopPropagation();
setIsHovered(false);
closeWindow(id as string);
}}
className="py-1 px-2 bg-rose-100 hover:bg-rose-200 border-2 border-ink-black text-rose-700 font-window-title text-[10px] font-bold flex items-center justify-center transition-colors cursor-pointer"
title="Close window"
>
<span className="material-symbols-outlined text-xs">close</span>
</button>
</div>
</div>
</FloatingPortal>
)}
</>
);
};
|