import React, { useState } from "react"; import { GoFile } from "react-icons/go"; import { MdClose } from "react-icons/md"; import type { FileNode } from "../types"; interface TabBarProps { openFiles: FileNode[]; activeFile: FileNode | null; onSelectFile: (file: FileNode) => void; onCloseFile: (file: FileNode) => void; onCloseAll: () => void; onCloseOthers: (file: FileNode) => void; } export const TabBar: React.FC = ({ openFiles, activeFile, onSelectFile, onCloseFile, onCloseAll, onCloseOthers, }) => { const [showContextMenu, setShowContextMenu] = useState<{ x: number; y: number; file: FileNode; } | null>(null); const handleContextMenu = (e: React.MouseEvent, file: FileNode) => { e.preventDefault(); setShowContextMenu({ x: e.clientX, y: e.clientY, file }); }; return ( <>
{openFiles.map((file) => (
onSelectFile(file)} onContextMenu={(e) => handleContextMenu(e, file)} style={{ display: "flex", alignItems: "center", padding: "8px 16px", backgroundColor: activeFile?.path === file.path ? "#1e1e1e" : "#2d2d30", color: activeFile?.path === file.path ? "#fff" : "#cccccc", borderRight: "1px solid #3e3e42", cursor: "pointer", fontSize: "13px", gap: "10px", whiteSpace: "nowrap", transition: "all 0.1s", borderTop: activeFile?.path === file.path ? "2px solid #0e639c" : "2px solid transparent", }} > {file.name} {file.dirty && ( )}
))}
{showContextMenu && (
{ onCloseOthers(showContextMenu.file); setShowContextMenu(null); }} style={{ padding: "8px 16px", cursor: "pointer", color: "#cccccc", fontSize: "13px", }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = "#2a2d2e"; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = "transparent"; }} > Close Others
{ onCloseAll(); setShowContextMenu(null); }} style={{ padding: "8px 16px", cursor: "pointer", color: "#cccccc", fontSize: "13px", }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = "#2a2d2e"; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = "transparent"; }} > Close All
)} ); };