/* eslint-disable @wordpress/no-unsafe-wp-apis */ /** * External dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls as GutenbergInspectorControls, __experimentalPanelColorGradientSettings as PanelColorGradientSettings, __experimentalUseGradient as useGradient, } from '@wordpress/block-editor'; import { FocalPointPicker, PanelBody, RangeControl, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, TextareaControl, ExternalLink, } from '@wordpress/components'; /** * Internal dependencies */ import { useBackgroundImage } from './use-background-image'; import { BLOCK_NAMES } from './constants'; export const InspectorControls = ( { alt, backgroundImageSrc, contentPanel, dimRatio, focalPoint = { x: 0.5, y: 0.5 }, hasParallax, isRepeated, imageFit, overlayColor, overlayGradient, setAttributes, setGradient, showDesc, } ) => { // FocalPointPicker was introduced in Gutenberg 5.0 (WordPress 5.2), // so we need to check if it exists before using it. const focalPointPickerExists = typeof FocalPointPicker === 'function'; const isImgElement = ! isRepeated && ! hasParallax; return ( setAttributes( { showDesc: ! showDesc } ) } /> { contentPanel } { !! backgroundImageSrc && ( <> { focalPointPickerExists && ( { setAttributes( { hasParallax: ! hasParallax, } ); } } /> { setAttributes( { isRepeated: ! isRepeated, } ); } } /> { ! isRepeated && (

{ __( 'Choose “Cover” if you want the image to scale automatically to always fit its container.', 'woo-gutenberg-products-block' ) }

{ __( 'Note: by choosing “Cover” you will lose the ability to freely move the focal point precisely.', 'woo-gutenberg-products-block' ) }

} label={ __( 'Image fit', 'woo-gutenberg-products-block' ) } value={ imageFit } onChange={ ( value ) => setAttributes( { imageFit: value, } ) } >
) } setAttributes( { focalPoint: value, } ) } /> { isImgElement && ( { setAttributes( { alt: value } ); } } help={ <> { __( 'Describe the purpose of the image', 'woo-gutenberg-products-block' ) } } /> ) }
) } setAttributes( { overlayColor: value } ), onGradientChange: ( value ) => { setGradient( value ); setAttributes( { overlayGradient: value, } ); }, label: __( 'Color', 'woo-gutenberg-products-block' ), }, ] } > setAttributes( { dimRatio: value } ) } min={ 0 } max={ 100 } step={ 10 } required /> ) }
); }; export const withInspectorControls = ( Component ) => ( props ) => { const { attributes, name, setAttributes } = props; const { alt, dimRatio, focalPoint, hasParallax, isRepeated, imageFit, mediaId, mediaSrc, overlayColor, overlayGradient, showDesc, showPrice, } = attributes; const item = name === BLOCK_NAMES.featuredProduct ? props.product : props.category; const { setGradient } = useGradient( { gradientAttribute: 'overlayGradient', customGradientAttribute: 'overlayGradient', } ); const { backgroundImageSrc } = useBackgroundImage( { item, mediaId, mediaSrc, blockName: name, } ); const contentPanel = name === BLOCK_NAMES.featuredProduct && ( setAttributes( { showPrice: ! showPrice, } ) } /> ); return ( <> ); };