From 82ff784f25a78b1d3557a73c23eeee40dfb417cb Mon Sep 17 00:00:00 2001 From: Tomasz Tunik Date: Wed, 23 Feb 2022 08:16:47 +0100 Subject: [PATCH] Add to Featured Product block option to remove custom image (#5886) * adds toolbar option to remove custom image removing custom image will reset it back to the default product image if available * update copy as per discussion went with just Reset as it is commonly used in WordPress and will have translation available --- assets/js/blocks/featured-product/block.js | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/assets/js/blocks/featured-product/block.js b/assets/js/blocks/featured-product/block.js index 3c64c9c2951..d463958986b 100644 --- a/assets/js/blocks/featured-product/block.js +++ b/assets/js/blocks/featured-product/block.js @@ -31,6 +31,7 @@ import PropTypes from 'prop-types'; import { getSetting } from '@woocommerce/settings'; import ProductControl from '@woocommerce/editor-components/product-control'; import ErrorPlaceholder from '@woocommerce/editor-components/error-placeholder'; +import TextToolbarButton from '@woocommerce/editor-components/text-toolbar-button'; import { withProduct } from '@woocommerce/block-hocs'; import { Icon, starEmpty } from '@wordpress/icons'; @@ -138,19 +139,29 @@ const FeaturedProduct = ( { setAttributes( { contentAlign: nextAlign } ); } } /> - { - setAttributes( { - mediaId: media.id, - mediaSrc: media.url, - } ); - } } - allowedTypes={ [ 'image' ] } - /> - + + { + setAttributes( { + mediaId: media.id, + mediaSrc: media.url, + } ); + } } + allowedTypes={ [ 'image' ] } + /> + { mediaId && mediaSrc ? ( + + setAttributes( { mediaId: 0, mediaSrc: '' } ) + } + > + { __( 'Reset', 'woo-gutenberg-products-block' ) } + + ) : null } +