'use client'; // ── Layout Section — Display / Flex / Grid / Padding ───────────────────────── // Adapts to the element's display mode: block (collapsed), flex, grid. import { useState, useEffect, useRef } from 'react'; import { NumInput, TextInput, FieldLabel, SectionHeader, CssSelect, IconToggleGroup, HSep } from '../DesignInputs'; interface LayoutSectionProps { styles: Record; onPatch: (prop: string, val: string) => void; } export function LayoutSection({ styles, onPatch }: LayoutSectionProps) { const display = styles['display'] ?? 'block'; // BUG-20 fix: useState only runs its initialiser once. When the user selects // a different component the `display` prop changes but `open` would stay // stale. We sync it on display changes while preserving explicit user // toggles: if display changes (new component selected), auto-open for // flex/grid, auto-close for block. const [open, setOpen] = useState(display === 'flex' || display === 'grid' || display === 'inline-flex'); const prevDisplayRef = useRef(display); useEffect(() => { if (prevDisplayRef.current !== display) { prevDisplayRef.current = display; setOpen(display === 'flex' || display === 'grid' || display === 'inline-flex' || display === 'inline-grid'); } }, [display]); const isFlex = display === 'flex' || display === 'inline-flex'; const isGrid = display === 'grid' || display === 'inline-grid'; return ( <> setOpen(!open)} /> {open && (
{/* Display mode */}
Display
{/* Flex-specific controls */} {isFlex && ( <> {/* Direction + Wrap */}
Direction onPatch('flex-direction', v)} />
Wrap onPatch('flex-wrap', v)} />
{/* Align items */}
Align
{/* Justify content */}
Justify
{/* Gap */}
Gap
)} {/* Grid-specific controls */} {isGrid && ( <>
Columns
Rows
Col gap Row gap
Align
)} {/* Padding (always shown) */}
Padding
Top
Right
Bottom
Left
)} ); }