react -> extract full editor toolbar button cpm
This commit is contained in:
parent
f573a0a4b4
commit
beca44c12b
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { createElement } from '@wordpress/element';
|
||||||
|
import { ToolbarButton } from '@wordpress/components';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { recordEvent } from '@woocommerce/tracks';
|
||||||
|
import { dispatch } from '@wordpress/data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { store } from '../../../../store/product-editor-ui';
|
||||||
|
|
||||||
|
export default function FullEditorToolbarButton( {
|
||||||
|
label = __( 'Edit Product description', 'woocommerce' ),
|
||||||
|
text = __( 'Full editor', 'woocommerce' ),
|
||||||
|
} ) {
|
||||||
|
const { openModalEditor } = dispatch( store );
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ToolbarButton
|
||||||
|
label={ label }
|
||||||
|
onClick={ () => {
|
||||||
|
recordEvent( 'product_add_description_click' );
|
||||||
|
openModalEditor();
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
{ text }
|
||||||
|
</ToolbarButton>
|
||||||
|
);
|
||||||
|
}
|
|
@ -4,26 +4,20 @@
|
||||||
import { createElement, Fragment } from '@wordpress/element';
|
import { createElement, Fragment } from '@wordpress/element';
|
||||||
import { createHigherOrderComponent } from '@wordpress/compose';
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
||||||
import { BlockControls } from '@wordpress/block-editor';
|
import { BlockControls } from '@wordpress/block-editor';
|
||||||
import { ToolbarButton } from '@wordpress/components';
|
|
||||||
import { __ } from '@wordpress/i18n';
|
|
||||||
import { recordEvent } from '@woocommerce/tracks';
|
|
||||||
import { useDispatch } from '@wordpress/data';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { store } from '../../../../store/product-editor-ai';
|
|
||||||
import type {
|
import type {
|
||||||
DescriptionBlockEditComponent,
|
DescriptionBlockEditComponent,
|
||||||
DescriptionBlockEditProps,
|
DescriptionBlockEditProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
import FullEditorToolbarButton from './full-editor-toolbar-button';
|
||||||
|
|
||||||
const wooBlockwithFullEditorToolbarButton =
|
const wooBlockwithFullEditorToolbarButton =
|
||||||
createHigherOrderComponent< DescriptionBlockEditComponent >(
|
createHigherOrderComponent< DescriptionBlockEditComponent >(
|
||||||
( BlockEdit: DescriptionBlockEditComponent ) => {
|
( BlockEdit: DescriptionBlockEditComponent ) => {
|
||||||
return ( props: DescriptionBlockEditProps ) => {
|
return ( props: DescriptionBlockEditProps ) => {
|
||||||
const { openModalEditor } = useDispatch( store );
|
|
||||||
|
|
||||||
// Only extend summary field block instances
|
// Only extend summary field block instances
|
||||||
if ( props?.name !== 'woocommerce/product-summary-field' ) {
|
if ( props?.name !== 'woocommerce/product-summary-field' ) {
|
||||||
return <BlockEdit { ...props } />;
|
return <BlockEdit { ...props } />;
|
||||||
|
@ -50,20 +44,7 @@ const wooBlockwithFullEditorToolbarButton =
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BlockControls { ...blockControlProps }>
|
<BlockControls { ...blockControlProps }>
|
||||||
<ToolbarButton
|
<FullEditorToolbarButton />
|
||||||
label={ __(
|
|
||||||
'Edit Product description',
|
|
||||||
'woocommerce'
|
|
||||||
) }
|
|
||||||
onClick={ () => {
|
|
||||||
recordEvent(
|
|
||||||
'product_add_description_click'
|
|
||||||
);
|
|
||||||
openModalEditor();
|
|
||||||
} }
|
|
||||||
>
|
|
||||||
{ __( 'Full editor', 'woocommerce' ) }
|
|
||||||
</ToolbarButton>
|
|
||||||
</BlockControls>
|
</BlockControls>
|
||||||
<BlockEdit { ...props } />
|
<BlockEdit { ...props } />
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue