import React from 'react'; import { useElementDrag } from './hooks/useElementDrag'; import { useElementSelection } from './hooks/useElementSelection'; import { getElementStyle } from './utils/elementUtils'; import './elements.css'; /** * Band element component * Represents a repeating section that iterates over data arrays */ function BandElement({ element, isSelected, isSingleSelection, onSelect, onUpdate, onDelete, onDragStart, onDrag, charWidth, charHeight, toolMode, children // Child elements to render inside band (in design mode) }) { // Use custom hooks for drag and selection const { isDragging, handleMouseDown: handleDragMouseDown } = useElementDrag({ isSelected, onDragStart, onDrag, toolMode, constrainX: true // Only vertical dragging }); const { handleClick } = useElementSelection({ isSelected, onSelect, onDelete, toolMode }); const handleMouseDown = (e) => { e.stopPropagation(); if (!isSelected) { onSelect(); } handleDragMouseDown(e, element.id); }; // Get caption text const captionText = element.caption || `${element.bandType}: ${element.dataSource || 'no data'}`; const style = { ...getElementStyle(element, charWidth, charHeight), borderTop: '2px dashed #667eea', borderBottom: '2px dashed #667eea', borderLeft: 'none', borderRight: 'none', backgroundColor: isSelected ? 'rgba(102, 126, 234, 0.08)' : 'rgba(200, 200, 200, 0.03)', boxSizing: 'border-box' }; return (
{captionText}
{/* Render child elements inside band container in design mode */}
{children}
); } export default BandElement;