From 9b877082ea6ca20b45127c580dc9dc7b5d547ac9 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Thu, 29 Aug 2024 12:08:30 -0500 Subject: [PATCH] Show block icon in contentOnly toolbar (#64694) --- .../src/components/block-switcher/index.js | 46 +++++++++++-------- .../src/components/block-switcher/style.scss | 7 ++- .../src/components/block-toolbar/index.js | 10 ++-- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index f28d0e49333817..c8ee422091ad1f 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -181,6 +181,21 @@ function BlockSwitcherDropdownMenuContents( { ); } +const BlockIndicator = ( { icon, showTitle, blockTitle } ) => ( + <> + + { showTitle && blockTitle && ( + + { blockTitle } + + ) } + +); + export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { const { canRemove, @@ -247,6 +262,7 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { : __( 'Multiple blocks selected' ); const hideDropdown = disabled || ( ! hasBlockStyles && ! canRemove ); + if ( hideDropdown ) { return ( @@ -255,14 +271,11 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { className="block-editor-block-switcher__no-switcher-icon" title={ blockSwitcherLabel } icon={ - <> - - { ( isReusable || isTemplate ) && ( - - { blockTitle } - - ) } - + } /> @@ -292,18 +305,11 @@ export const BlockSwitcher = ( { clientIds, disabled, isUsingBindings } ) => { className: 'block-editor-block-switcher__popover', } } icon={ - <> - - { ( isReusable || isTemplate ) && ( - - { blockTitle } - - ) } - + } toggleProps={ { description: blockSwitcherDescription, diff --git a/packages/block-editor/src/components/block-switcher/style.scss b/packages/block-editor/src/components/block-switcher/style.scss index afcb576bd8db49..287afaed4055c6 100644 --- a/packages/block-editor/src/components/block-switcher/style.scss +++ b/packages/block-editor/src/components/block-switcher/style.scss @@ -46,12 +46,11 @@ } // Even when the block switcher does not have any transformations, it still serves as a block indicator. -.components-button.block-editor-block-switcher__no-switcher-icon:disabled { - opacity: 1; +.components-button.block-editor-block-switcher__no-switcher-icon[aria-disabled="true"] { + color: $gray-900; // Since it's not clickable, though, don't show a hover state. - &, - .block-editor-block-icon.has-colors { + &:hover { color: $gray-900; } } diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index 90e6394d0975dd..984670762262c9 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -59,6 +59,7 @@ export function PrivateBlockToolbar( { const { blockClientId, blockClientIds, + isContentOnlyEditingMode, isDefaultEditingMode, blockType, toolbarKey, @@ -85,8 +86,8 @@ export function PrivateBlockToolbar( { const firstParentClientId = parents[ parents.length - 1 ]; const parentBlockName = getBlockName( firstParentClientId ); const parentBlockType = getBlockType( parentBlockName ); - const _isDefaultEditingMode = - getBlockEditingMode( selectedBlockClientId ) === 'default'; + const editingMode = getBlockEditingMode( selectedBlockClientId ); + const _isDefaultEditingMode = editingMode === 'default'; const _blockName = getBlockName( selectedBlockClientId ); const isValid = selectedBlockClientIds.every( ( id ) => isBlockValid( id ) @@ -101,6 +102,7 @@ export function PrivateBlockToolbar( { return { blockClientId: selectedBlockClientId, blockClientIds: selectedBlockClientIds, + isContentOnlyEditingMode: editingMode === 'contentOnly', isDefaultEditingMode: _isDefaultEditingMode, blockType: selectedBlockClientId && getBlockType( _blockName ), shouldShowVisualToolbar: isValid && isVisual, @@ -171,7 +173,9 @@ export function PrivateBlockToolbar( { isLargeViewport && isDefaultEditingMode && } { ( shouldShowVisualToolbar || isMultiToolbar ) && - ( isDefaultEditingMode || isSynced ) && ( + ( isDefaultEditingMode || + isContentOnlyEditingMode || + isSynced ) && (