diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index c6dd37884807e..44f5bbb5966f4 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -319,7 +319,7 @@ export default function NavigationLinkEdit( { } ), }, { - allowedBlocks: [ 'core/navigation-link' ], + allowedBlocks: [ 'core/navigation-link', 'core/spacer' ], renderAppender: ( isSelected && hasDescendants ) || ( isImmediateParentOfSelectedBlock && diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index c826a2783330d..211d20a97c18c 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -40,7 +40,8 @@ "fontSize": "fontSize", "customFontSize": "customFontSize", "showSubmenuIcon": "showSubmenuIcon", - "style": "style" + "style": "style", + "orientation": "orientation" }, "supports": { "align": [ diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index d3b7cb9535c0a..f93399e38931a 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -70,6 +70,7 @@ function Navigation( { 'core/search', 'core/social-links', 'core/page-list', + 'core/spacer', ], orientation: attributes.orientation || 'horizontal', renderAppender: diff --git a/packages/block-library/src/spacer/block.json b/packages/block-library/src/spacer/block.json index fd4172079fa50..16f843be4cb76 100644 --- a/packages/block-library/src/spacer/block.json +++ b/packages/block-library/src/spacer/block.json @@ -6,8 +6,14 @@ "height": { "type": "number", "default": 100 + }, + "width": { + "type": "number" } }, + "usesContext": [ + "orientation" + ], "supports": { "anchor": true }, diff --git a/packages/block-library/src/spacer/edit.js b/packages/block-library/src/spacer/edit.js index 940d85fb31923..6c2b2221d18d4 100644 --- a/packages/block-library/src/spacer/edit.js +++ b/packages/block-library/src/spacer/edit.js @@ -15,33 +15,43 @@ import { import { PanelBody, ResizableBox, RangeControl } from '@wordpress/components'; import { compose, withInstanceId } from '@wordpress/compose'; import { withDispatch } from '@wordpress/data'; -import { useState } from '@wordpress/element'; +import { useState, useEffect } from '@wordpress/element'; import { View } from '@wordpress/primitives'; const MIN_SPACER_HEIGHT = 1; const MAX_SPACER_HEIGHT = 500; +const MIN_SPACER_WIDTH = 1; +const MAX_SPACER_WIDTH = 500; + const SpacerEdit = ( { attributes, isSelected, setAttributes, onResizeStart, onResizeStop, + context, } ) => { + const { orientation } = context; const [ isResizing, setIsResizing ] = useState( false ); - const { height } = attributes; + const { height, width } = attributes; const updateHeight = ( value ) => { setAttributes( { height: value, } ); }; + const updateWidth = ( value ) => { + setAttributes( { + width: value, + } ); + }; const handleOnResizeStart = ( ...args ) => { onResizeStart( ...args ); setIsResizing( true ); }; - const handleOnResizeStop = ( event, direction, elt, delta ) => { + const handleOnVerticalResizeStop = ( event, direction, elt, delta ) => { onResizeStop(); const spacerHeight = Math.min( parseInt( height + delta.height, 10 ), @@ -51,24 +61,36 @@ const SpacerEdit = ( { setIsResizing( false ); }; - return ( - <> - + const handleOnHorizontalResizeStop = ( event, direction, elt, delta ) => { + onResizeStop(); + const spacerWidth = Math.min( + parseInt( width + delta.width, 10 ), + MAX_SPACER_WIDTH + ); + updateWidth( spacerWidth ); + setIsResizing( false ); + }; + + const resizableBoxWithOrientation = ( blockOrientation ) => { + if ( blockOrientation === 'horizontal' ) { + return ( + ); + } + + return ( + + ); + }; + + useEffect( () => { + if ( orientation === 'horizontal' && ! width ) { + updateWidth( 72 ); + updateHeight( 0 ); + } + }, [] ); + + return ( + <> + + { resizableBoxWithOrientation( orientation ) } - + { orientation === 'horizontal' && ( + + ) } + { orientation !== 'horizontal' && ( + + ) } diff --git a/packages/block-library/src/spacer/editor.scss b/packages/block-library/src/spacer/editor.scss index 66aa8ef55bb06..3d80b99766870 100644 --- a/packages/block-library/src/spacer/editor.scss +++ b/packages/block-library/src/spacer/editor.scss @@ -27,4 +27,8 @@ .components-resizable-box__handle::before { content: none; } + + &.resize-horizontal { + margin-bottom: 0; + } } diff --git a/packages/block-library/src/spacer/save.js b/packages/block-library/src/spacer/save.js index 28a882557306e..77cf37ff61251 100644 --- a/packages/block-library/src/spacer/save.js +++ b/packages/block-library/src/spacer/save.js @@ -7,7 +7,7 @@ export default function save( { attributes } ) { return (
diff --git a/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.html b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.html new file mode 100644 index 0000000000000..7381e2582f311 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.json b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.json new file mode 100644 index 0000000000000..35ae07f2b69b5 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.json @@ -0,0 +1,13 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/spacer", + "isValid": true, + "attributes": { + "height": 0, + "width": 72 + }, + "innerBlocks": [], + "originalContent": "
" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.parsed.json b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.parsed.json new file mode 100644 index 0000000000000..391254e101891 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.parsed.json @@ -0,0 +1,14 @@ +[ + { + "blockName": "core/spacer", + "attrs": { + "height": 0, + "width": 72 + }, + "innerBlocks": [], + "innerHTML": "\n
\n", + "innerContent": [ + "\n
\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.serialized.html b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.serialized.html new file mode 100644 index 0000000000000..580702a7ee1e4 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__spacer__horizontal.serialized.html @@ -0,0 +1,3 @@ + + +