2019-01-10 19:01:49 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-01-13 17:22:15 +00:00
|
|
|
import './style.scss';
|
2019-01-10 19:01:49 +00:00
|
|
|
import Block from './block';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register and run the "Featured Product" block.
|
|
|
|
*/
|
|
|
|
registerBlockType( 'woocommerce/featured-product', {
|
|
|
|
title: __( 'Featured Product', 'woo-gutenberg-products-block' ),
|
2019-01-14 19:37:35 +00:00
|
|
|
icon: 'star-filled',
|
2019-01-10 19:01:49 +00:00
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
|
|
|
'Visually highlight a product and encourage prompt action.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
|
|
|
},
|
|
|
|
attributes: {
|
2019-01-13 17:22:15 +00:00
|
|
|
/**
|
|
|
|
* Alignment of content inside block.
|
|
|
|
*/
|
|
|
|
contentAlign: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'center',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Percentage opacity of overlay.
|
|
|
|
*/
|
|
|
|
dimRatio: {
|
|
|
|
type: 'number',
|
|
|
|
default: 50,
|
|
|
|
},
|
|
|
|
|
2019-01-10 19:01:49 +00:00
|
|
|
/**
|
|
|
|
* Toggle for edit mode in the block preview.
|
|
|
|
*/
|
|
|
|
editMode: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2019-01-13 17:22:15 +00:00
|
|
|
* The overlay color, from the color list.
|
|
|
|
*/
|
|
|
|
overlayColor: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The overlay color, if a custom color value.
|
|
|
|
*/
|
|
|
|
customOverlayColor: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text for the product link.
|
|
|
|
*/
|
|
|
|
linkText: {
|
|
|
|
type: 'string',
|
|
|
|
default: __( 'Shop now', 'woo-gutenberg-products-block' ),
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The product ID to display.
|
2019-01-10 19:01:49 +00:00
|
|
|
*/
|
|
|
|
productId: {
|
|
|
|
type: 'number',
|
|
|
|
},
|
2019-01-13 17:22:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the product description.
|
|
|
|
*/
|
|
|
|
showDesc: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the product price.
|
|
|
|
*/
|
|
|
|
showPrice: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
2019-01-10 19:01:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders and manages the block.
|
|
|
|
*/
|
|
|
|
edit( props ) {
|
|
|
|
return <Block { ...props } />;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Block content is rendered in PHP, not via save function.
|
|
|
|
*/
|
|
|
|
save() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
} );
|