From 51a775a1792fd7db3bc87834fa4fa98930028bfc Mon Sep 17 00:00:00 2001 From: jrangel Date: Wed, 11 Dec 2024 16:29:10 +0000 Subject: [PATCH] Initial --- react/components/iconselectcontrol.js | 81 +++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 react/components/iconselectcontrol.js diff --git a/react/components/iconselectcontrol.js b/react/components/iconselectcontrol.js new file mode 100644 index 0000000..143aa4d --- /dev/null +++ b/react/components/iconselectcontrol.js @@ -0,0 +1,81 @@ +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 IconSelectControl from './IconSelectControl'; // Import the new component +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 published popups (lcp-popup CPT) + useEffect(() => { + const fetchPopups = async () => { + const response = await fetch('/wp-json/wp/v2/lcp-popup'); + const data = await response.json(); + setPopups(data); + }; + fetchPopups(); + }, []); + + // Fetch icon data from the JSON source (local or remote) + useEffect(() => { + const fetchIcons = async () => { + // Assuming the icon data is in a file called 'icons.json' + const response = await fetch('/path/to/icons.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 ( + <> + + + ({ + label: popup.title.rendered, + value: popup.id, + }))} + onChange={(value) => setAttributes({ popUpId: value })} + /> + setAttributes({ buttonText: value })} + /> + {/* Pass the icons array to the IconSelectControl component */} + + + +
+
+ {buttonText} +
+
+ + ); +}