From e4a9ad1d2e3addc0d6a84803232d814256a3fd9f Mon Sep 17 00:00:00 2001 From: Maggie Date: Thu, 4 Jul 2024 18:23:52 +0200 Subject: [PATCH] Add a vertical toolbar for zoom out mode (#60123) * position toolbar popover to the left and change colors on zoomed-out mode * Make zoom out toolbar component * Create zoom out toolbar * Cleanup linting errors * Add orientation to toolbar component * css for vertical toolbars * Add similar classes to existing toolbar * Use correct placement for zoom out toolbar popover * remove cs that shouldn't be needed * Remove icon and block toolbar vertical css and apply just to base component * made toolbar unstyled and fixed stray background * Update Changelog * removed transparent background from component css * Update packages/components/src/toolbar/toolbar/types.ts Co-authored-by: Lena Morita * document new prop for the toolbar component * remove white background * increase margin width * Also include the non-accessible toolbar in the vertical CSS rules * Move styles to the zoom out toolbar CSS * revert * avoid shifting of the toolbar to the right side * fix focus outline * moved vertical styles to toolbar component * missing display flex * removed orientation from NavigableToolbar props * Revert "removed orientation from NavigableToolbar props" This reverts commit 59e5bdba37d77c6632121ca9c208b79494f13aac. * Use ToolbarButton instead of Button for Shuffle * added classes to avoid using component selectors --------- Co-authored-by: Jerry Jones Co-authored-by: Lena Morita Co-authored-by: Ben Dwyer --- .../src/components/block-toolbar/shuffle.js | 1 + .../block-tools/block-selection-button.js | 81 +--------- .../src/components/block-tools/index.js | 9 ++ .../src/components/block-tools/style.scss | 15 ++ .../block-tools/use-show-block-tools.js | 20 ++- .../block-tools/zoom-out-popover.js | 49 ++++++ .../block-tools/zoom-out-toolbar.js | 140 ++++++++++++++++++ .../src/components/navigable-toolbar/index.js | 4 +- packages/components/CHANGELOG.md | 4 + .../components/src/toolbar/toolbar/README.md | 9 ++ .../components/src/toolbar/toolbar/style.scss | 7 + .../components/src/toolbar/toolbar/types.ts | 6 + .../src/components/visual-editor/index.js | 2 +- 13 files changed, 265 insertions(+), 82 deletions(-) create mode 100644 packages/block-editor/src/components/block-tools/zoom-out-popover.js create mode 100644 packages/block-editor/src/components/block-tools/zoom-out-toolbar.js diff --git a/packages/block-editor/src/components/block-toolbar/shuffle.js b/packages/block-editor/src/components/block-toolbar/shuffle.js index e7e40619f6a499..be30d868551d5b 100644 --- a/packages/block-editor/src/components/block-toolbar/shuffle.js +++ b/packages/block-editor/src/components/block-toolbar/shuffle.js @@ -85,6 +85,7 @@ export default function Shuffle( { clientId, as = Container } ) { { const nextPattern = getNextPattern(); nextPattern.blocks[ 0 ].attributes = { diff --git a/packages/block-editor/src/components/block-tools/block-selection-button.js b/packages/block-editor/src/components/block-tools/block-selection-button.js index 805e41c580f950..036aef4f135d3c 100644 --- a/packages/block-editor/src/components/block-tools/block-selection-button.js +++ b/packages/block-editor/src/components/block-tools/block-selection-button.js @@ -6,8 +6,8 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { dragHandle, trash } from '@wordpress/icons'; -import { Button, Flex, FlexItem, ToolbarButton } from '@wordpress/components'; +import { dragHandle } from '@wordpress/icons'; +import { Button, Flex, FlexItem } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { forwardRef, useEffect } from '@wordpress/element'; import { @@ -38,8 +38,6 @@ import BlockIcon from '../block-icon'; import { store as blockEditorStore } from '../../store'; import BlockDraggable from '../block-draggable'; import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs'; -import BlockMover from '../block-mover'; -import Shuffle from '../block-toolbar/shuffle'; /** * Block selection button component, displaying the label of the block. If the block @@ -63,7 +61,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { __unstableGetEditorMode, getNextBlockClientId, getPreviousBlockClientId, - canRemoveBlock, canMoveBlock, } = select( blockEditorStore ); const { getActiveBlockVariation, getBlockType } = @@ -74,26 +71,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { const orientation = getBlockListSettings( rootClientId )?.orientation; const match = getActiveBlockVariation( name, attributes ); - const isBlockTemplatePart = - blockType?.name === 'core/template-part'; - - let isNextBlockTemplatePart = false; - const nextClientId = getNextBlockClientId(); - if ( nextClientId ) { - const { name: nextName } = getBlock( nextClientId ); - const nextBlockType = getBlockType( nextName ); - isNextBlockTemplatePart = - nextBlockType?.name === 'core/template-part'; - } - - let isPrevBlockTemplatePart = false; - const prevClientId = getPreviousBlockClientId(); - if ( prevClientId ) { - const { name: prevName } = getBlock( prevClientId ); - const prevBlockType = getBlockType( prevName ); - isPrevBlockTemplatePart = - prevBlockType?.name === 'core/template-part'; - } return { blockMovingMode: hasBlockMovingClientId(), @@ -105,26 +82,14 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { index + 1, orientation ), - isBlockTemplatePart, - isNextBlockTemplatePart, - isPrevBlockTemplatePart, - canRemove: canRemoveBlock( clientId ), - canMove: canMoveBlock( clientId ), + canMove: canMoveBlock( clientId, rootClientId ), + getNextBlockClientId, + getPreviousBlockClientId, }; }, [ clientId, rootClientId ] ); - const { - label, - icon, - blockMovingMode, - editorMode, - isBlockTemplatePart, - isNextBlockTemplatePart, - isPrevBlockTemplatePart, - canRemove, - canMove, - } = selected; + const { label, icon, blockMovingMode, editorMode, canMove } = selected; const { setNavigationMode, removeBlock } = useDispatch( blockEditorStore ); // Focus the breadcrumb in navigation mode. @@ -276,9 +241,7 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { ); const dragHandleLabel = __( 'Drag' ); - const showBlockDraggable = - ( canMove && editorMode === 'navigation' ) || - ( editorMode === 'zoom-out' && canMove && ! isBlockTemplatePart ); + const showBlockDraggable = canMove && editorMode === 'navigation'; return (
@@ -307,36 +270,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) { ) } - { editorMode === 'zoom-out' && ! isBlockTemplatePart && ( - - - - ) } - { canMove && canRemove && editorMode === 'zoom-out' && ( - - ) } - { canRemove && - editorMode === 'zoom-out' && - ! isBlockTemplatePart && ( - - { - removeBlock( clientId ); - } } - /> - - ) } { editorMode === 'navigation' && (