2019-08-05 10:25:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import classnames from 'classnames';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { HOME_URL } from '@woocommerce/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
|
|
|
*
|
2022-04-08 13:47:19 +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
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {boolean} props.attributes.hasLabel
|
2022-04-08 13:47:19 +00:00
|
|
|
* @param {string} props.attributes.align
|
2019-08-05 10:25:57 +00:00
|
|
|
*/
|
2023-05-24 12:24:08 +00:00
|
|
|
|
|
|
|
interface ProductSearchBlockProps {
|
|
|
|
attributes: {
|
|
|
|
label: string;
|
|
|
|
placeholder: string;
|
|
|
|
formId: string;
|
|
|
|
className: string;
|
|
|
|
hasLabel: boolean;
|
|
|
|
align: string;
|
|
|
|
};
|
|
|
|
}
|
2020-03-02 13:46:56 +00:00
|
|
|
const ProductSearchBlock = ( {
|
|
|
|
attributes: { label, placeholder, formId, className, hasLabel, align },
|
2023-05-24 12:24:08 +00:00
|
|
|
}: ProductSearchBlockProps ) => {
|
2020-03-02 13:46:56 +00:00
|
|
|
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"
|
2023-12-12 23:05:20 +00:00
|
|
|
aria-label={ __( 'Search', 'woocommerce' ) }
|
2019-08-05 10:25:57 +00:00
|
|
|
>
|
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
|
|
|
|
2020-03-02 13:46:56 +00:00
|
|
|
export default ProductSearchBlock;
|