From 894286b3c01a3ba75933cde2a4beff7ef9dc7c85 Mon Sep 17 00:00:00 2001 From: Ella van Durpe Date: Mon, 18 May 2020 21:37:29 +0200 Subject: [PATCH] Buttons: allow split and merge --- packages/block-library/src/button/edit.js | 23 +++++++++++++++++++++- packages/block-library/src/button/index.js | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 46c1223cfbf6ef..0bee117117a6df 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -27,6 +27,7 @@ import { } from '@wordpress/block-editor'; import { rawShortcut, displayShortcut } from '@wordpress/keycodes'; import { link } from '@wordpress/icons'; +import { createBlock } from '@wordpress/blocks'; /** * Internal dependencies @@ -123,7 +124,14 @@ function URLPicker( { } function ButtonEdit( props ) { - const { attributes, setAttributes, className, isSelected } = props; + const { + attributes, + setAttributes, + className, + isSelected, + onReplace, + mergeBlocks, + } = props; const { borderRadius, linkTarget, @@ -183,6 +191,19 @@ function ButtonEdit( props ) { : undefined, ...colorProps.style, } } + onSplit={ ( value ) => { + if ( ! value ) { + return createBlock( 'core/button' ); + } + + return createBlock( 'core/button', { + ...attributes, + text: value, + } ); + } } + onReplace={ onReplace } + onMerge={ mergeBlocks } + identifier="text" /> ( { + text: textA + textB, + } ), };