diff --git a/packages/block-library/src/buttons/block.json b/packages/block-library/src/buttons/block.json index 93c7eea7015a16..b0b4762231c810 100644 --- a/packages/block-library/src/buttons/block.json +++ b/packages/block-library/src/buttons/block.json @@ -5,5 +5,11 @@ "align": true, "alignWide": false, "lightBlockWrapper": true + }, + "attributes": { + "orientation": { + "type": "string", + "default": "horizontal" + } } } diff --git a/packages/block-library/src/buttons/edit.js b/packages/block-library/src/buttons/edit.js index f6aa94582b3a6c..0ce58fd6a94283 100644 --- a/packages/block-library/src/buttons/edit.js +++ b/packages/block-library/src/buttons/edit.js @@ -1,11 +1,19 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ import { __experimentalAlignmentHookSettingsProvider as AlignmentHookSettingsProvider, - InnerBlocks, __experimentalBlock as Block, + InnerBlocks, + InspectorControls, } from '@wordpress/block-editor'; +import { PanelBody, RadioControl } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; /** * Internal dependencies @@ -14,22 +22,47 @@ import { name as buttonBlockName } from '../button/'; const ALLOWED_BLOCKS = [ buttonBlockName ]; const BUTTONS_TEMPLATE = [ [ 'core/button' ] ]; +const ORIENTATION_OPTIONS = [ + { label: __( 'Horizontal' ), value: 'horizontal' }, + { + label: __( 'Vertical' ), + value: 'vertical', + }, +]; // Inside buttons block alignment options are not supported. const alignmentHooksSetting = { isEmbedButton: true, }; -function ButtonsEdit() { +function ButtonsEdit( { attributes: { orientation }, setAttributes } ) { return ( - + + + + + setAttributes( { + orientation: value, + } ) + } + /> + + ); } diff --git a/packages/block-library/src/buttons/editor.scss b/packages/block-library/src/buttons/editor.scss index 2a07114b65ad50..93e6ac642abc6e 100644 --- a/packages/block-library/src/buttons/editor.scss +++ b/packages/block-library/src/buttons/editor.scss @@ -3,6 +3,10 @@ width: auto; } +.wp-block-buttons.is-vertical .wp-block.block-editor-block-list__block[data-type="core/button"] { + display: block; +} + .wp-block[data-align="center"] > .wp-block-buttons { display: flex; align-items: center; diff --git a/packages/block-library/src/buttons/save.js b/packages/block-library/src/buttons/save.js index 91cb804231d058..8522d9e6b6691a 100644 --- a/packages/block-library/src/buttons/save.js +++ b/packages/block-library/src/buttons/save.js @@ -1,11 +1,20 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ import { InnerBlocks } from '@wordpress/block-editor'; -export default function save() { +export default function save( { attributes: { orientation } } ) { return ( -
+
); diff --git a/packages/block-library/src/buttons/style.scss b/packages/block-library/src/buttons/style.scss index fa869b97904b5c..def0cdb84d2607 100644 --- a/packages/block-library/src/buttons/style.scss +++ b/packages/block-library/src/buttons/style.scss @@ -13,3 +13,9 @@ .wp-block-buttons.aligncenter { text-align: center; } + +.wp-block-buttons.is-vertical .wp-block-button { + display: block; + margin-left: 0; + margin-right: 0; +} diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.html b/packages/e2e-tests/fixtures/blocks/core__buttons.html index e70af7acc72ad4..21c9205b162d06 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.html +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.html @@ -1,11 +1,15 @@ - + diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.json b/packages/e2e-tests/fixtures/blocks/core__buttons.json index 044daeb82101ac..72578cb04bbd9e 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.json +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.json @@ -3,7 +3,9 @@ "clientId": "_clientId_0", "name": "core/buttons", "isValid": true, - "attributes": {}, + "attributes": { + "orientation": "horizontal" + }, "innerBlocks": [ { "clientId": "_clientId_0", @@ -13,7 +15,7 @@ "text": "My button 1" }, "innerBlocks": [], - "originalContent": "" + "originalContent": "
\n\t\tMy button 1\n\t
" }, { "clientId": "_clientId_1", @@ -23,7 +25,7 @@ "text": "My button 2" }, "innerBlocks": [], - "originalContent": "" + "originalContent": "
\n\t\tMy button 2\n\t
" } ], "originalContent": "
\n\t\n\n\t\n
" diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json b/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json index b96b1f50db1fc9..3ab0c2cd44743a 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json @@ -1,24 +1,26 @@ [ { "blockName": "core/buttons", - "attrs": {}, + "attrs": { + "orientation": "horizontal" + }, "innerBlocks": [ { "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t\n\t", + "innerHTML": "\n\t
\n\t\tMy button 1\n\t
\n\t", "innerContent": [ - "\n\t\n\t" + "\n\t
\n\t\tMy button 1\n\t
\n\t" ] }, { "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t\n\t", + "innerHTML": "\n\t
\n\t\tMy button 2\n\t
\n\t", "innerContent": [ - "\n\t\n\t" + "\n\t
\n\t\tMy button 2\n\t
\n\t" ] } ], diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.html b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.html new file mode 100644 index 00000000000000..a520639ba8da5b --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.html @@ -0,0 +1,15 @@ + +
+ + + + + + + +
+ diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.json b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.json new file mode 100644 index 00000000000000..885987c2cb11b5 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.json @@ -0,0 +1,33 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/buttons", + "isValid": true, + "attributes": { + "orientation": "vertical" + }, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/button", + "isValid": true, + "attributes": { + "text": "My button 1" + }, + "innerBlocks": [], + "originalContent": "
\n\t\tMy button 1\n\t
" + }, + { + "clientId": "_clientId_1", + "name": "core/button", + "isValid": true, + "attributes": { + "text": "My button 2" + }, + "innerBlocks": [], + "originalContent": "
\n\t\tMy button 2\n\t
" + } + ], + "originalContent": "
\n\t\n\n\t\n
" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.parsed.json b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.parsed.json new file mode 100644 index 00000000000000..c070a3490e9cce --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.parsed.json @@ -0,0 +1,45 @@ +[ + { + "blockName": "core/buttons", + "attrs": { + "orientation": "vertical" + }, + "innerBlocks": [ + { + "blockName": "core/button", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\t
\n\t\tMy button 1\n\t
\n\t", + "innerContent": [ + "\n\t
\n\t\tMy button 1\n\t
\n\t" + ] + }, + { + "blockName": "core/button", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\t
\n\t\tMy button 2\n\t
\n\t", + "innerContent": [ + "\n\t
\n\t\tMy button 2\n\t
\n\t" + ] + } + ], + "innerHTML": "\n
\n\t\n\n\t\n
\n", + "innerContent": [ + "\n
\n\t", + null, + "\n\n\t", + null, + "\n
\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.serialized.html b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.serialized.html new file mode 100644 index 00000000000000..079253c245973d --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__vertical.serialized.html @@ -0,0 +1,9 @@ + + + diff --git a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.html b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.html index 02f5487560cee4..b86a635201f94f 100644 --- a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.html +++ b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.html @@ -1,4 +1,4 @@ - +
My button 1 diff --git a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.json b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.json index d77d9752de37b0..1ae83f325b61d5 100644 --- a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.json +++ b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.json @@ -3,7 +3,9 @@ "clientId": "_clientId_0", "name": "core/buttons", "isValid": true, - "attributes": {}, + "attributes": { + "orientation": "horizontal" + }, "innerBlocks": [ { "clientId": "_clientId_0", diff --git a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.parsed.json b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.parsed.json index ee9dd97313a48b..1f968a3e87e047 100644 --- a/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core_buttons__simple__deprecated.parsed.json @@ -1,7 +1,9 @@ [ { "blockName": "core/buttons", - "attrs": {}, + "attrs": { + "orientation": "horizontal" + }, "innerBlocks": [ { "blockName": "core/button",