2024-06-06 07:25:07 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-06-14 08:21:44 +00:00
|
|
|
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
2024-06-06 07:25:07 +00:00
|
|
|
import { useDispatch } from '@wordpress/data';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { trash } from '@wordpress/icons';
|
|
|
|
import {
|
|
|
|
store as blockEditorStore,
|
|
|
|
// @ts-expect-error missing type
|
|
|
|
} from '@wordpress/block-editor';
|
|
|
|
|
2024-07-16 11:24:55 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { trackEvent } from '~/customize-store/tracking';
|
|
|
|
|
2024-06-10 12:33:32 +00:00
|
|
|
export default function Delete( {
|
|
|
|
clientId,
|
2024-07-16 11:24:55 +00:00
|
|
|
currentBlockName,
|
2024-06-10 12:33:32 +00:00
|
|
|
nextBlockClientId,
|
|
|
|
}: {
|
|
|
|
clientId: string;
|
2024-07-16 11:24:55 +00:00
|
|
|
currentBlockName: string | undefined;
|
2024-06-10 12:33:32 +00:00
|
|
|
nextBlockClientId: string | undefined;
|
|
|
|
} ) {
|
2024-06-06 07:25:07 +00:00
|
|
|
// @ts-expect-error missing type
|
2024-06-10 12:33:32 +00:00
|
|
|
const { removeBlock, selectBlock } = useDispatch( blockEditorStore );
|
2024-06-06 07:25:07 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ToolbarGroup>
|
2024-06-14 08:21:44 +00:00
|
|
|
<ToolbarButton
|
|
|
|
showTooltip={ true }
|
2024-07-10 07:13:55 +00:00
|
|
|
label={ __( 'Delete', 'woocommerce' ) }
|
2024-06-14 08:21:44 +00:00
|
|
|
icon={ trash }
|
|
|
|
onClick={ () => {
|
|
|
|
removeBlock( clientId );
|
|
|
|
if ( nextBlockClientId ) {
|
|
|
|
selectBlock( nextBlockClientId );
|
|
|
|
}
|
2024-07-16 11:24:55 +00:00
|
|
|
trackEvent(
|
|
|
|
'customize_your_store_assembler_pattern_delete_click',
|
|
|
|
{ pattern: currentBlockName }
|
|
|
|
);
|
2024-06-14 08:21:44 +00:00
|
|
|
} }
|
|
|
|
/>
|
2024-06-06 07:25:07 +00:00
|
|
|
</ToolbarGroup>
|
|
|
|
);
|
|
|
|
}
|