/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { createInterpolateElement, useEffect } from '@wordpress/element'; import { getAdminLink, getSettingWithCoercion } from '@woocommerce/settings'; import { isBoolean } from '@woocommerce/types'; import type { BlockEditProps } from '@wordpress/blocks'; import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types'; import { Disabled, PanelBody, ToggleControl, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions. // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions. // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from '@wordpress/components'; /** * Internal dependencies */ import Block from './block'; import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE as label, BLOCK_ICON as icon, BLOCK_DESCRIPTION as description, } from './constants'; import type { BlockAttributes } from './types'; type SaleBadgeAlignProps = 'left' | 'center' | 'right'; type ImageSizingProps = 'full-size' | 'cropped'; const Edit = ( { attributes, setAttributes, context, }: BlockEditProps< BlockAttributes > & { context: Context } ): JSX.Element => { const { showProductLink, imageSizing, showSaleBadge, saleBadgeAlign } = attributes; const blockProps = useBlockProps(); const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); const isBlockThemeEnabled = getSettingWithCoercion( 'is_block_theme_enabled', false, isBoolean ); useEffect( () => setAttributes( { isDescendentOfQueryLoop } ), [ setAttributes, isDescendentOfQueryLoop ] ); useEffect( () => { if ( isBlockThemeEnabled && attributes.imageSizing !== 'full-size' ) { setAttributes( { imageSizing: 'full-size' } ); } }, [ attributes.imageSizing, isBlockThemeEnabled, setAttributes ] ); return (
setAttributes( { showProductLink: ! showProductLink, } ) } /> setAttributes( { showSaleBadge: ! showSaleBadge, } ) } /> { showSaleBadge && ( setAttributes( { saleBadgeAlign: value } ) } > ) } { ! isBlockThemeEnabled && ( Customizer.', 'woo-gutenberg-products-block' ), { a: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } value={ imageSizing } onChange={ ( value: ImageSizingProps ) => setAttributes( { imageSizing: value } ) } > ) }
); }; export default withProductSelector( { icon, label, description } )( Edit );