import React, { useState, useMemo } from "react"; import { ChevronDown, ChevronUp, FileCode, FileText } from "lucide-react"; interface MoreMinimoreCodeSearchResultProps { node?: any; children?: React.ReactNode; } export const MoreMinimoreCodeSearchResult: React.FC = ({ children, }) => { const [isExpanded, setIsExpanded] = useState(false); // Parse file paths from children content const files = useMemo(() => { if (typeof children !== "string") { return []; } const filePaths: string[] = []; const lines = children.split("\n"); for (const line of lines) { const trimmedLine = line.trim(); // Skip empty lines and lines that look like tags if ( trimmedLine && !trimmedLine.startsWith("<") && !trimmedLine.startsWith(">") ) { filePaths.push(trimmedLine); } } return filePaths; }, [children]); return (
setIsExpanded(!isExpanded)} role="button" aria-expanded={isExpanded} tabIndex={0} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); setIsExpanded(!isExpanded); } }} > {/* Top-left label badge */}
Code Search Result
{/* File count when collapsed */} {files.length > 0 && (
Found {files.length} file{files.length !== 1 ? "s" : ""}
)} {/* Indicator icon */}
{isExpanded ? : }
{/* Main content with smooth transition */}
{/* File list when expanded */} {files.length > 0 && (
{files.map((file, index) => { const filePath = file.trim(); const fileName = filePath.split("/").pop() || filePath; const pathPart = filePath.substring(0, filePath.length - fileName.length) || ""; return (
{fileName}
{pathPart && (
{pathPart}
)}
); })}
)}
); };