2019-01-10 19:01:49 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-02-08 23:57:58 +00:00
|
|
|
import { InnerBlocks } from '@wordpress/editor';
|
2019-01-10 19:01:49 +00:00
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
2019-08-27 15:25:32 +00:00
|
|
|
import { DEFAULT_HEIGHT } from '@woocommerce/block-settings';
|
2019-01-10 19:01:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-01-13 17:22:15 +00:00
|
|
|
import './style.scss';
|
2019-02-19 21:09:36 +00:00
|
|
|
import './editor.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-05-28 10:18:07 +00:00
|
|
|
icon: {
|
|
|
|
src: 'star-filled',
|
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
2019-01-10 19:01:49 +00:00
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
2019-07-09 09:48:31 +00:00
|
|
|
'Visually highlight a product or variation and encourage prompt action.',
|
2019-01-10 19:01:49 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
2019-08-06 14:10:01 +00:00
|
|
|
html: false,
|
2019-01-10 19:01:49 +00:00
|
|
|
},
|
|
|
|
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-05-03 14:37:52 +00:00
|
|
|
/**
|
|
|
|
* Focus point for the background image
|
|
|
|
*/
|
|
|
|
focalPoint: {
|
|
|
|
type: 'object',
|
|
|
|
},
|
|
|
|
|
2019-02-05 20:49:24 +00:00
|
|
|
/**
|
|
|
|
* A fixed height for the block.
|
|
|
|
*/
|
|
|
|
height: {
|
|
|
|
type: 'number',
|
2019-08-17 09:14:11 +00:00
|
|
|
default: DEFAULT_HEIGHT,
|
2019-02-05 20:49:24 +00:00
|
|
|
},
|
|
|
|
|
2019-01-14 22:22:00 +00:00
|
|
|
/**
|
|
|
|
* ID for a custom image, overriding the product's featured image.
|
|
|
|
*/
|
|
|
|
mediaId: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* URL for a custom image, overriding the product's featured image.
|
|
|
|
*/
|
|
|
|
mediaSrc: {
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
|
2019-01-10 19:01:49 +00:00
|
|
|
/**
|
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() {
|
2019-02-08 23:57:58 +00:00
|
|
|
return <InnerBlocks.Content />;
|
2019-01-10 19:01:49 +00:00
|
|
|
},
|
|
|
|
} );
|