import React, { useState, useEffect } from 'react'; import { Button, Icon, PanelBody, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import LCPDimensionControl from './LCPDimensionControl'; import LCPHTMLModal from './LCPHTMLModal.js'; const LCPChartBlockSettings = ({ attributes, setAttributes }) => { // Use `legendAlignment` from props (block attributes) const { renderLegend, legendLocation, legendAlignment, allowDownloadImage, downloadImageMaxWidth, allowDownloadCsv, allowDownloadJson, allowSorting, allowFiltering, footerContent, chartTitle, chartSubtitle, toolbarLocation, toolbarAlignment } = attributes; // Set local state for legend location (for UI updates) const [selectedLegendLocation, setSelectedLegendLocation] = useState(legendLocation); // Update block attribute when location changes useEffect(() => { setAttributes({ legendLocation: selectedLegendLocation }); }, [selectedLegendLocation, setAttributes]); // Set local state for alignment (for UI updates) const [selectedLegendAlignment, setSelectedLegendAlignment] = useState(legendAlignment); // Update block attribute when alignment changes useEffect(() => { setAttributes({ legendAlignment: selectedLegendAlignment }); }, [selectedLegendAlignment, setAttributes]); // Set local state for alignment (for UI updates) const [selectedToolbarAlignment, setSelectedToolbarAlignment] = useState(toolbarAlignment); // Update block attribute when alignment changes useEffect(() => { setAttributes({ toolbarAlignment: selectedToolbarAlignment }); }, [selectedToolbarAlignment, setAttributes]); // Render the component return (
{/* Legend Settings Panel */} setAttributes({ renderLegend: value })} /> {renderLegend && (
{/* Legend - Alignment Buttons */}
{/* Left Alignment Button */} {/* Center Alignment Button */} {/* Right Alignment Button */}
{/* Legend - Location Buttons */}
{/* Top Location Button */} {/* Bottom Location Button */}
)}
{/* Controls Settings Panel */}
{/* Left Alignment Button */} {/* Center Alignment Button */} {/* Right Alignment Button */}
setAttributes({ allowFiltering: value })} /> setAttributes({ allowSorting: value })} /> setAttributes({ allowDownloadImage: value })} /> {allowDownloadImage && ( setAttributes({ downloadImageMaxWidth: value })} /> )} setAttributes({ allowDownloadCsv: value })} /> setAttributes({ allowDownloadJson: value })} />
{/* Tooltips and Popups Panel */} {/* Header Settings Panel */} {/* Footer Settings Panel */}
); }; export default LCPChartBlockSettings;