From 11525f7c9ad1f0cb7f464d86cdc0b9e207bb3d45 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Thu, 16 Feb 2023 11:17:41 +0000 Subject: [PATCH] Navigation List View: Add block movers to the more menu (#48099) * Navigation List View: Add block movers to the more menu * add arrows * put the remove action in its own group --- .../off-canvas-editor/leaf-more-menu.js | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/leaf-more-menu.js b/packages/block-editor/src/components/off-canvas-editor/leaf-more-menu.js index a266f0d9377c36..a3829998361bc0 100644 --- a/packages/block-editor/src/components/off-canvas-editor/leaf-more-menu.js +++ b/packages/block-editor/src/components/off-canvas-editor/leaf-more-menu.js @@ -2,9 +2,14 @@ * WordPress dependencies */ import { createBlock } from '@wordpress/blocks'; -import { addSubmenu, moreVertical } from '@wordpress/icons'; +import { + addSubmenu, + chevronUp, + chevronDown, + moreVertical, +} from '@wordpress/icons'; import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components'; -import { useDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; /** @@ -80,14 +85,24 @@ function AddSubmenuItem( { block, onClose } ) { export default function LeafMoreMenu( props ) { const { clientId, block } = props; - const { removeBlocks } = useDispatch( blockEditorStore ); + const { moveBlocksDown, moveBlocksUp, removeBlocks } = + useDispatch( blockEditorStore ); - const label = sprintf( + const removeLabel = sprintf( /* translators: %s: block name */ __( 'Remove %s' ), BlockTitle( { clientId, maximumLength: 25 } ) ); + const rootClientId = useSelect( + ( select ) => { + const { getBlockRootClientId } = select( blockEditorStore ); + + return getBlockRootClientId( clientId ); + }, + [ clientId ] + ); + return ( { ( { onClose } ) => ( - - - { - removeBlocks( [ clientId ], false ); - onClose(); - } } - > - { label } - - + <> + + { + moveBlocksUp( [ clientId ], rootClientId ); + onClose(); + } } + > + { __( 'Move up' ) } + + { + moveBlocksDown( [ clientId ], rootClientId ); + onClose(); + } } + > + { __( 'Move down' ) } + + + + + { + removeBlocks( [ clientId ], false ); + onClose(); + } } + > + { removeLabel } + + + ) } );