2019-08-05 10:25:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
2020-01-31 18:20:33 +00:00
|
|
|
import { Icon, search } from '@woocommerce/icons';
|
2019-08-05 10:25:57 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
import './editor.scss';
|
|
|
|
import Block from './block.js';
|
2020-03-02 13:46:56 +00:00
|
|
|
import edit from './edit.js';
|
2019-08-05 10:25:57 +00:00
|
|
|
|
|
|
|
registerBlockType( 'woocommerce/product-search', {
|
|
|
|
title: __( 'Product Search', 'woo-gutenberg-products-block' ),
|
|
|
|
icon: {
|
2020-01-31 18:20:33 +00:00
|
|
|
src: <Icon srcElement={ search } />,
|
2019-08-05 10:25:57 +00:00
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
2020-02-17 22:02:59 +00:00
|
|
|
'A search box to allow customers to search for products by keyword.',
|
2019-08-05 10:25:57 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
|
|
|
},
|
2019-11-05 10:32:53 +00:00
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
hasLabel: true,
|
|
|
|
},
|
|
|
|
},
|
2019-08-05 10:25:57 +00:00
|
|
|
attributes: {
|
|
|
|
/**
|
|
|
|
* Whether to show the field label.
|
|
|
|
*/
|
|
|
|
hasLabel: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search field label.
|
|
|
|
*/
|
|
|
|
label: {
|
|
|
|
type: 'string',
|
|
|
|
default: __( 'Search', 'woo-gutenberg-products-block' ),
|
|
|
|
source: 'text',
|
|
|
|
selector: 'label',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search field placeholder.
|
|
|
|
*/
|
|
|
|
placeholder: {
|
|
|
|
type: 'string',
|
2020-01-30 09:28:17 +00:00
|
|
|
default: __( 'Search products…', 'woo-gutenberg-products-block' ),
|
2019-08-05 10:25:57 +00:00
|
|
|
source: 'attribute',
|
|
|
|
selector: 'input.wc-block-product-search__field',
|
|
|
|
attribute: 'placeholder',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the instance ID.
|
|
|
|
*/
|
|
|
|
formId: {
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-02 13:46:56 +00:00
|
|
|
edit,
|
2019-08-05 10:25:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the props to post content.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {Object} attributes Props to pass to block.
|
2019-08-05 10:25:57 +00:00
|
|
|
*/
|
|
|
|
save( attributes ) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Block { ...attributes } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
} );
|