2019-01-10 19:01:49 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-05-12 20:31:49 +00:00
|
|
|
import { InnerBlocks } from '@wordpress/block-editor';
|
2019-01-10 19:01:49 +00:00
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2020-01-31 18:20:33 +00:00
|
|
|
import { Icon, star } from '@woocommerce/icons';
|
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-10-24 13:55:44 +00:00
|
|
|
import { example } from './example';
|
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: {
|
2020-01-31 18:20:33 +00:00
|
|
|
src: <Icon srcElement={ star } />,
|
2019-05-28 10:18:07 +00:00
|
|
|
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
|
|
|
},
|
2019-10-24 13:55:44 +00:00
|
|
|
example,
|
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',
|
2021-04-22 11:37:27 +00:00
|
|
|
default: getSetting( 'default_height', 500 ),
|
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-10-24 13:55:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Product preview.
|
|
|
|
*/
|
|
|
|
previewProduct: {
|
|
|
|
type: 'object',
|
|
|
|
default: null,
|
|
|
|
},
|
2019-01-10 19:01:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders and manages the block.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Props to pass to block.
|
2019-01-10 19:01:49 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
},
|
|
|
|
} );
|