2019-08-05 10:25:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-08-27 15:25:32 +00:00
|
|
|
import { HOME_URL } from '@woocommerce/block-settings';
|
2019-08-05 10:25:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './editor.scss';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component displaying a product search form.
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @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
|
2019-08-05 10:25:57 +00:00
|
|
|
*/
|
2020-03-02 13:46:56 +00:00
|
|
|
const ProductSearchBlock = ( {
|
|
|
|
attributes: { label, placeholder, formId, className, hasLabel, align },
|
|
|
|
} ) => {
|
|
|
|
const classes = classnames(
|
|
|
|
'wc-block-product-search',
|
|
|
|
align ? 'align' + align : '',
|
|
|
|
className
|
|
|
|
);
|
2019-08-05 10:25:57 +00:00
|
|
|
|
2020-03-02 13:46:56 +00:00
|
|
|
return (
|
|
|
|
<div className={ classes }>
|
|
|
|
<form role="search" method="get" action={ HOME_URL }>
|
|
|
|
<label
|
|
|
|
htmlFor={ formId }
|
|
|
|
className={
|
|
|
|
hasLabel
|
|
|
|
? 'wc-block-product-search__label'
|
|
|
|
: 'wc-block-product-search__label screen-reader-text'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{ label }
|
|
|
|
</label>
|
2019-08-05 10:25:57 +00:00
|
|
|
<div className="wc-block-product-search__fields">
|
2020-03-02 13:46:56 +00:00
|
|
|
<input
|
|
|
|
type="search"
|
|
|
|
id={ formId }
|
|
|
|
className="wc-block-product-search__field"
|
|
|
|
placeholder={ placeholder }
|
|
|
|
name="s"
|
2019-08-05 10:25:57 +00:00
|
|
|
/>
|
2020-03-02 13:46:56 +00:00
|
|
|
<input type="hidden" name="post_type" value="product" />
|
2019-08-05 10:25:57 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
className="wc-block-product-search__button"
|
|
|
|
label={ __( 'Search', 'woo-gutenberg-products-block' ) }
|
|
|
|
>
|
2019-09-05 15:09:31 +00:00
|
|
|
<svg
|
|
|
|
aria-hidden="true"
|
|
|
|
role="img"
|
|
|
|
focusable="false"
|
|
|
|
className="dashicon dashicons-arrow-right-alt2"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
width="20"
|
|
|
|
height="20"
|
|
|
|
viewBox="0 0 20 20"
|
|
|
|
>
|
|
|
|
<path d="M6 15l5-5-5-5 1-2 7 7-7 7z" />
|
2019-08-05 10:25:57 +00:00
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-03-02 13:46:56 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2019-08-05 10:25:57 +00:00
|
|
|
|
|
|
|
ProductSearchBlock.propTypes = {
|
|
|
|
/**
|
|
|
|
* The attributes for this block.
|
|
|
|
*/
|
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2020-03-02 13:46:56 +00:00
|
|
|
export default ProductSearchBlock;
|