/** * Structure Display Component * * A component that parses and displays a structure array * using individual StructureItem components */ import React, { useState } from 'react'; import StructureItem from './StructureItem'; interface StructureDisplayProps { structure: string | null; getString: (namespace: string, key: string, fallback: string) => string; maxWidth?: string; layout?: 'horizontal' | 'vertical'; } const StructureDisplay: React.FC = ({ structure, getString, maxWidth = 'max-w-xs', layout = 'horizontal', }) => { const [showAll, setShowAll] = useState(false); // Parse the structure string into an array let structureArray = []; try { structureArray = structure ? JSON.parse(structure) : []; if (!Array.isArray(structureArray)) { structureArray = []; } } catch (e) { console.error('Error parsing structure:', e); } // If no structure, show placeholder if (structureArray.length === 0) { return (
{getString('table_cells', 'no_structure', 'No structure')}
); } // Render structure items const layoutClasses = layout === 'vertical' ? 'flex flex-col gap-2' : 'flex flex-wrap gap-1 items-start'; const visibleCount = 3; const displayItems = showAll ? structureArray : structureArray.slice(0, visibleCount); const hiddenCount = Math.max(structureArray.length - visibleCount, 0); return (
{displayItems.map((element: any, index: number) => ( ))} {hiddenCount > 0 && !showAll && ( )} {showAll && hiddenCount > 0 && ( )}
); }; export default StructureDisplay;