({
node,
selectedPath,
onSelect,
depth = 0,
}: {
node: FileNode;
selectedPath: string | null;
onSelect: (path: string) => void;
depth?: number;
})
| 36 | }; |
| 37 | |
| 38 | function TreeNode({ |
| 39 | node, |
| 40 | selectedPath, |
| 41 | onSelect, |
| 42 | depth = 0, |
| 43 | }: { |
| 44 | node: FileNode; |
| 45 | selectedPath: string | null; |
| 46 | onSelect: (path: string) => void; |
| 47 | depth?: number; |
| 48 | }) { |
| 49 | const [isExpanded, setIsExpanded] = useState(false); |
| 50 | const isSelected = selectedPath === node.path; |
| 51 | const isFolder = node.type === "folder"; |
| 52 | |
| 53 | const handleClick = () => { |
| 54 | if (isFolder) { |
| 55 | setIsExpanded(!isExpanded); |
| 56 | } else { |
| 57 | onSelect(node.path); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | const Icon = isFolder |
| 62 | ? isExpanded |
| 63 | ? FolderOpen |
| 64 | : Folder |
| 65 | : getFileIcon(node.name); |
| 66 | |
| 67 | return ( |
| 68 | <div> |
| 69 | <button |
| 70 | onClick={handleClick} |
| 71 | className="w-full flex items-center gap-1.5 md:gap-2 px-2 md:px-3 py-1.5 md:py-2 text-xs md:text-sm rounded-lg transition-colors" |
| 72 | style={{ |
| 73 | paddingLeft: `${8 + depth * 12}px`, |
| 74 | backgroundColor: isSelected ? "var(--accent)" : "transparent", |
| 75 | color: isSelected ? "var(--text-primary)" : "var(--text-secondary)", |
| 76 | }} |
| 77 | onMouseEnter={(e) => { |
| 78 | if (!isSelected) { |
| 79 | e.currentTarget.style.backgroundColor = "var(--border)"; |
| 80 | e.currentTarget.style.color = "var(--text-primary)"; |
| 81 | } |
| 82 | }} |
| 83 | onMouseLeave={(e) => { |
| 84 | if (!isSelected) { |
| 85 | e.currentTarget.style.backgroundColor = "transparent"; |
| 86 | e.currentTarget.style.color = "var(--text-secondary)"; |
| 87 | } |
| 88 | }} |
| 89 | > |
| 90 | {isFolder && ( |
| 91 | <span className="w-3.5 h-3.5 md:w-4 md:h-4 flex items-center justify-center"> |
| 92 | {isExpanded ? ( |
| 93 | <ChevronDown className="w-3 h-3 md:w-3.5 md:h-3.5" /> |
| 94 | ) : ( |
| 95 | <ChevronRight className="w-3 h-3 md:w-3.5 md:h-3.5" /> |
nothing calls this directly
no test coverage detected