/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import { Component } from '@wordpress/element';
import PropTypes from 'prop-types';
import { withInstanceId, compose } from '@wordpress/compose';
import { PlainText } from '@wordpress/editor';
import { HOME_URL } from '@woocommerce/block-settings';
/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
/**
* Component displaying a product search form.
*/
class ProductSearchBlock extends Component {
renderView() {
const {
attributes: {
label,
placeholder,
formId,
className,
hasLabel,
align,
},
} = this.props;
const classes = classnames(
'wc-block-product-search',
align ? 'align' + align : '',
className
);
return (
);
}
renderEdit() {
const { attributes, setAttributes, instanceId } = this.props;
const {
label,
placeholder,
formId,
className,
hasLabel,
align,
} = attributes;
const classes = classnames(
'wc-block-product-search',
align ? 'align' + align : '',
className
);
if ( ! formId ) {
setAttributes( {
formId: `wc-block-product-search-${ instanceId }`,
} );
}
return (
{ !! hasLabel && (
setAttributes( { label: value } )
}
/>
) }
setAttributes( { placeholder: value } )
}
/>
);
}
render() {
if ( this.props.isEditor ) {
return this.renderEdit();
}
return this.renderView();
}
}
ProductSearchBlock.propTypes = {
/**
* The attributes for this block.
*/
attributes: PropTypes.object.isRequired,
/**
* A unique ID for identifying the label for the select dropdown.
*/
instanceId: PropTypes.number,
/**
* Whether it's in the editor or frontend display.
*/
isEditor: PropTypes.bool,
/**
* A callback to update attributes.
*/
setAttributes: PropTypes.func,
};
export default compose( [ withInstanceId ] )( ProductSearchBlock );