import React, { useState, useEffect } from "react"; import { ChevronUp, ChevronDown, Code2, FileText } from "lucide-react"; import { CustomTagState } from "./stateTypes"; interface MoreMinimoreCodebaseContextProps { children: React.ReactNode; node?: { properties?: { files?: string; state?: CustomTagState; }; }; } export const MoreMinimoreCodebaseContext: React.FC = ({ node, }) => { const state = node?.properties?.state as CustomTagState; const inProgress = state === "pending"; const [isExpanded, setIsExpanded] = useState(inProgress); const files = node?.properties?.files?.split(",") || []; // Collapse when transitioning from in-progress to not-in-progress useEffect(() => { if (!inProgress && isExpanded) { setIsExpanded(false); } }, [inProgress]); 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 */}
Codebase Context
{/* File count when collapsed */} {files.length > 0 && (
Using {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}
)}
); })}
)}
); };