/** * JsonSectionHeader - Self-contained header for AdvancedJsonSection * * A simplified version of MarkdownJsonViewHeader specifically for JSON sections. * Includes: * - Title with optional icon * - Copy button * - Custom control buttons (search, expand/collapse, etc.) */ import { useState } from "react"; import { Button } from "@/src/components/ui/button"; import { Check, ChevronDown, ChevronRight, Copy } from "lucide-react"; export interface AdvancedJsonSectionHeaderProps { /** Section title (can be string or React node for custom rendering) */ title: string | React.ReactNode; /** Optional icon to display next to title */ titleIcon?: React.ReactNode; /** Callback when copy button is clicked */ handleOnCopy: (event?: React.MouseEvent) => void; /** Additional control buttons to render (search, expand/collapse, etc.) */ controlButtons?: React.ReactNode; /** Background color for the header */ backgroundColor?: string; /** Callback when header title area is clicked (for expand/collapse) */ onToggleCollapse?: () => void; /** Whether the section is currently collapsed */ sectionCollapsed?: boolean; } export function AdvancedJsonSectionHeader({ title, titleIcon, handleOnCopy, controlButtons, backgroundColor, onToggleCollapse, sectionCollapsed, }: AdvancedJsonSectionHeaderProps) { const [isCopied, setIsCopied] = useState(false); return (
{ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onToggleCollapse?.(); } }} > {onToggleCollapse && ( )} {titleIcon} {title}
{controlButtons}
); }