import React, { useState, useEffect } from 'react'; import { Button, Icon, PanelBody, ToggleControl, TextControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import LCPDimensionControl from './LCPDimensionControl'; import LCPHTMLModal from './LCPHTMLModal.js'; const LCPChartBlockSettings = ({ attributes, setAttributes }) => { // Attributes from parent edit.js file const { renderLegend, legendLocation, legendAlignment, allowDownloadImage, downloadImageMaxWidth, allowDownloadCsv, allowDownloadJson, allowSorting, allowFiltering, footerContent, chartTitle, chartSubtitle, toolbarLocation = 'top', toolbarAlignment, showXAxisLabel, xAxisLabel, showYAxisLabel, yAxisLabel, renderXGrid, renderYGrid, xGridColor, yGridColor, legendFontSize, includeDataChart, allowChartDataDownload } = attributes; // Set local state for legend location and alignment (for UI updates) const [selectedLegendLocation, setSelectedLegendLocation] = useState(legendLocation); const [selectedLegendAlignment, setSelectedLegendAlignment] = useState(legendAlignment); // Update block attributes when location or alignment changes useEffect(() => { setAttributes({ legendLocation: selectedLegendLocation, legendAlignment: selectedLegendAlignment }); }, [selectedLegendLocation, selectedLegendAlignment, setAttributes]); // Set local state for toolbar location and alignment (for UI updates) const [selectedToolbarLocation, setSelectedToolbarLocation] = useState(toolbarLocation); const [selectedToolbarAlignment, setSelectedToolbarAlignment] = useState(toolbarAlignment); // Update block attributes when toolbar location or alignment changes useEffect(() => { setAttributes({ toolbarLocation: selectedToolbarLocation, toolbarAlignment: selectedToolbarAlignment }); }, [selectedToolbarLocation, selectedToolbarAlignment, setAttributes]); // Render the component return (
{/* Front-end Chart Settings */} {/* Render the chart on the front-end */} setAttributes({ includeDataChart: value })} /> {/* Allow chart data download */} setAttributes({ allowChartDataDownload: value })} /> {/* Grid Settings Panel */} {/* Render X-Grid */} setAttributes({ renderXGrid: value })} /> {/* Render Y-Grid */} setAttributes({ renderYGrid: value })} /> {/* 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 */} setAttributes({ legendFontSize: value })} />
)}
{/* Labels Settings Panel */} {/* Show X-Axis Label*/} setAttributes({ showXAxisLabel: value })} /> {/* X-Axis Label */} setAttributes({ xAxisLabel: value })} placeholder={__('Enter X-axis label...', 'lcp')} /> {/* Show Y-Axis */} setAttributes({ showYAxisLabel: value })} /> {/* Y-Axis Label */} setAttributes({ xAxisLabel: value })} placeholder={__('Enter X-axis label', 'lcp')} /> {/* Controls Settings Panel */}
{/* Top Location Button */} {/* Bottom Location Button */} setAttributes({ legendFontSize: value })} />
{/* 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;