2019-08-05 10:25:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-06-04 14:47:30 +00:00
|
|
|
import { createBlock, 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
|
|
|
|
2021-08-12 16:39:38 +00:00
|
|
|
const attributes = {
|
|
|
|
/**
|
|
|
|
* Whether to show the field label.
|
|
|
|
*/
|
|
|
|
hasLabel: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search field label.
|
|
|
|
*/
|
|
|
|
label: {
|
|
|
|
type: 'string',
|
|
|
|
default: __( 'Search', 'woo-gutenberg-products-block' ),
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search field placeholder.
|
|
|
|
*/
|
|
|
|
placeholder: {
|
|
|
|
type: 'string',
|
|
|
|
default: __( 'Search products…', 'woo-gutenberg-products-block' ),
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the instance ID.
|
|
|
|
*/
|
|
|
|
formId: {
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
2021-08-12 16:39:38 +00:00
|
|
|
attributes,
|
2021-06-04 14:47:30 +00:00
|
|
|
transforms: {
|
|
|
|
from: [
|
|
|
|
{
|
|
|
|
type: 'block',
|
|
|
|
blocks: [ 'core/legacy-widget' ],
|
|
|
|
// We can't transform if raw instance isn't shown in the REST API.
|
|
|
|
isMatch: ( { idBase, instance } ) =>
|
|
|
|
idBase === 'woocommerce_product_search' && !! instance?.raw,
|
|
|
|
transform: ( { instance } ) =>
|
|
|
|
createBlock( 'woocommerce/product-search', {
|
|
|
|
label:
|
|
|
|
instance.raw.title === ''
|
|
|
|
? __( 'Search', 'woo-gutenberg-products-block' )
|
|
|
|
: instance.raw.title,
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-08-12 16:39:38 +00:00
|
|
|
deprecated: [
|
|
|
|
{
|
|
|
|
attributes,
|
|
|
|
save( props ) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Block { ...props } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-03-02 13:46:56 +00:00
|
|
|
edit,
|
2021-08-12 16:39:38 +00:00
|
|
|
save() {
|
|
|
|
return null;
|
2019-08-05 10:25:57 +00:00
|
|
|
},
|
|
|
|
} );
|