Update react/components/lcp/IconSelectControl iconselectcontrol.js
This commit is contained in:
54
react/components/lcp/IconSelectControl iconselectcontrol.js
Normal file
54
react/components/lcp/IconSelectControl iconselectcontrol.js
Normal file
@ -0,0 +1,54 @@
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
|
||||
import { PanelBody, SelectControl, TextControl } from '@wordpress/components';
|
||||
import { useState, useEffect } from '@wordpress/element';
|
||||
|
||||
import './editor.scss';
|
||||
|
||||
export default function Edit(props) {
|
||||
const { attributes, setAttributes } = props;
|
||||
const { type, popUpId, buttonText, iconSvgId, iconSvgPath } = attributes; // iconSvgId holds the UUID and iconSvgPath holds the SVG path
|
||||
const [popups, setPopups] = useState([]);
|
||||
const [icons, setIcons] = useState([]); // To hold the icon data
|
||||
|
||||
|
||||
// Fetch icon data from the JSON source
|
||||
useEffect(() => {
|
||||
const fetchIcons = async () => {
|
||||
// Assuming the icon data is in a file called 'icons.json'
|
||||
const response = await fetch('/iconsvgs.json');
|
||||
const iconData = await response.json();
|
||||
setIcons(iconData); // Set the fetched icon data
|
||||
};
|
||||
fetchIcons();
|
||||
}, []);
|
||||
|
||||
// Handle icon selection from dropdown
|
||||
const handleIconChange = (selectedIconId) => {
|
||||
const selectedIcon = icons.find(icon => icon.uuid === selectedIconId);
|
||||
|
||||
if (selectedIcon) {
|
||||
setAttributes({
|
||||
iconSvgId: selectedIconId,
|
||||
iconSvgPath: selectedIcon.path
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
|
||||
|
||||
{/* Pass the icons array to the IconSelectControl component */}
|
||||
<IconSelectControl
|
||||
label={__("Icon")}
|
||||
value={iconSvgId}
|
||||
onChange={handleIconChange}
|
||||
icons={icons} // Passing the icons data here
|
||||
/>
|
||||
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user