/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { AlignmentToolbar, BlockControls as BlockControlsWrapper, MediaReplaceFlow, } from '@wordpress/block-editor'; import { ToolbarButton, ToolbarGroup } from '@wordpress/components'; import { crop } from '@wordpress/icons'; import TextToolbarButton from '@woocommerce/editor-components/text-toolbar-button'; /** * Internal dependencies */ import { useBackgroundImage } from './use-background-image'; export const BlockControls = ( { backgroundImageId, backgroundImageSrc, contentAlign, cropLabel, editLabel, editMode, isEditingImage, mediaSrc, setAttributes, setIsEditingImage, } ) => { return ( { setAttributes( { contentAlign: nextAlign } ); } } /> { backgroundImageSrc && ! isEditingImage && ( setIsEditingImage( true ) } icon={ crop } label={ cropLabel } /> ) } { setAttributes( { mediaId: media.id, mediaSrc: media.url, } ); } } allowedTypes={ [ 'image' ] } /> { backgroundImageId && mediaSrc ? ( setAttributes( { mediaId: 0, mediaSrc: '' } ) } > { __( 'Reset', 'woo-gutenberg-products-block' ) } ) : null } setAttributes( { editMode: ! editMode } ), isActive: editMode, }, ] } /> ); }; export const withBlockControls = ( { cropLabel, editLabel } ) => ( Component ) => ( props ) => { const [ isEditingImage, setIsEditingImage ] = props.useEditingImage; const { attributes, category, name, product, setAttributes } = props; const { contentAlign, editMode, mediaId, mediaSrc } = attributes; const item = category || product; const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( { item, mediaId, mediaSrc, blockName: name, } ); return ( <> ); };