/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Disabled, PanelBody, ToggleControl } from '@wordpress/components'; import { compose } from '@wordpress/compose'; import { InspectorControls, BlockControls, AlignmentToolbar, useBlockProps, } from '@wordpress/block-editor'; import { isFeaturePluginBuild } from '@woocommerce/block-settings'; import HeadingToolbar from '@woocommerce/editor-components/heading-toolbar'; /** * Internal dependencies */ import Block from './block'; import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE, BLOCK_ICON } from './constants'; import { Attributes } from './types'; import './editor.scss'; interface Props { attributes: Attributes; setAttributes: ( attributes: Record< string, unknown > ) => void; } const TitleEdit = ( { attributes, setAttributes }: Props ): JSX.Element => { const blockProps = useBlockProps(); const { headingLevel, showProductLink, align, linkTarget } = attributes; return (
setAttributes( { headingLevel: newLevel } ) } /> { isFeaturePluginBuild() && ( { setAttributes( { align: newAlign } ); } } /> ) } setAttributes( { showProductLink: ! showProductLink, } ) } /> { showProductLink && ( <> setAttributes( { linkTarget: value ? '_blank' : '_self', } ) } checked={ linkTarget === '_blank' } /> ) }
); }; const Title = isFeaturePluginBuild() ? compose( [ withProductSelector( { icon: BLOCK_ICON, label: BLOCK_TITLE, description: __( 'Choose a product to display its title.', 'woo-gutenberg-products-block' ), } ), ] )( TitleEdit ) : TitleEdit; export default Title;