Changes to lcp button and icon selector
This commit is contained in:
@ -10,10 +10,10 @@ export function IconSelectControl(props) {
|
||||
useEffect(() => {
|
||||
const fetchIconData = async () => {
|
||||
try {
|
||||
const response = await fetch('/wp-content/themes/local-content-pro/assets/json/icons.json');
|
||||
const response = await fetch('/wp-json/lcp/v1/icons');
|
||||
const data = await response.json();
|
||||
if (data && data.length > 0) {
|
||||
setIconData(data[0].svgs); // Assuming the structure is correct
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
setIconData(data); // Set the fetched data directly
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching icons:', error);
|
||||
@ -24,15 +24,17 @@ export function IconSelectControl(props) {
|
||||
}, []);
|
||||
|
||||
const handleIconChange = (selectedIconId) => {
|
||||
const selectedIcon = iconData.find(icon => icon.id === selectedIconId);
|
||||
const selectedIcon = iconData.find(icon => icon.iconSvgId === selectedIconId);
|
||||
if (selectedIcon && onIconChange) {
|
||||
// Send both icon ID and path (SVG) to the parent component
|
||||
onIconChange({
|
||||
iconSvgId: selectedIcon.id, // Pass icon ID to parent
|
||||
iconSvgPath: selectedIcon.path // Pass icon path (SVG) to parent
|
||||
iconSvgId: selectedIcon.iconSvgId, // Pass icon ID to parent
|
||||
iconSvgPath: selectedIcon.iconSvgPaths, // Pass icon paths to parent
|
||||
viewbox: selectedIcon.selectedIconViewbox // Pass the viewbox to parent
|
||||
});
|
||||
console.log("Selected Icon ID:", selectedIcon.id); // Debugging output
|
||||
console.log("Selected Icon Path:", selectedIcon.path); // Debugging output
|
||||
console.log("Selected Icon ID:", selectedIcon.iconSvgId); // Debugging output
|
||||
console.log("Selected Icon Path:", selectedIcon.iconSvgPaths); // Debugging output
|
||||
console.log("Selected Icon Viewbox:", selectedIcon.selectedIconViewbox); // Debugging output
|
||||
}
|
||||
};
|
||||
|
||||
@ -41,20 +43,11 @@ export function IconSelectControl(props) {
|
||||
}
|
||||
|
||||
const iconOptions = iconData.map((icon) => ({
|
||||
value: icon.id, // Use icon ID as value for the SelectControl
|
||||
label: (
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox={icon.viewBox || "0 0 512 512"} // Default viewBox if not present
|
||||
style={{ width: '20px', height: '20px' }} // Control icon size
|
||||
dangerouslySetInnerHTML={{ __html: icon.path }} // Insert SVG path
|
||||
/>
|
||||
<span style={{ marginLeft: '8px' }}>{icon.name}</span> {/* Show icon name */}
|
||||
</div>
|
||||
),
|
||||
value: icon.iconSvgId, // Use icon ID as value for the SelectControl
|
||||
label: icon.name, // Directly use the icon's name as the label
|
||||
}));
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<SelectControl
|
||||
label={__('Select Icon', 'lcp')}
|
||||
|
||||
Reference in New Issue
Block a user