/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { InspectorControls, PlainText } from '@wordpress/block-editor';
import { PanelBody, ToggleControl, TextControl } from '@wordpress/components';
import { withInstanceId } from '@wordpress/compose';
import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
/**
* Component displaying a product search form.
*
* @param {Object} props Incoming props for the component.
* @param {Object} props.attributes Incoming block attributes.
* @param {string} props.attributes.label
* @param {string} props.attributes.placeholder
* @param {string} props.attributes.formId
* @param {string} props.attributes.className
* @param {boolean} props.attributes.hasLabel
* @param {string} props.attributes.align
* @param {string} props.instanceId
* @param {function(any):any} props.setAttributes Setter for block attributes.
*/
const Edit = ( {
attributes: { label, placeholder, formId, className, hasLabel, align },
instanceId,
setAttributes,
} ) => {
const classes = classnames(
'wc-block-product-search',
align ? 'align' + align : '',
className
);
useEffect( () => {
if ( ! formId ) {
setAttributes( {
formId: `wc-block-product-search-${ instanceId }`,
} );
}
}, [ formId, setAttributes, instanceId ] );
return (
<>