Skip to content

Commit

Permalink
Only show zoom out inserters on block selection (WordPress#65759)
Browse files Browse the repository at this point in the history
Removes code related to showing/hiding inserters on hover.
  • Loading branch information
jeryj authored Sep 30, 2024
1 parent 1a47719 commit 5128f04
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
8 changes: 0 additions & 8 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,3 @@
border: none;
}
}

.block-editor-block-tools__zoom-out-mode-inserter-button {
visibility: hidden;

&.is-visible {
visibility: visible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,21 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { plus } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';

function ZoomOutModeInserterButton( { isVisible, onClick } ) {
const [
zoomOutModeInserterButtonHovered,
setZoomOutModeInserterButtonHovered,
] = useState( false );

function ZoomOutModeInserterButton( { onClick } ) {
return (
<Button
variant="primary"
icon={ plus }
size="compact"
className={ clsx(
'block-editor-button-pattern-inserter__button',
'block-editor-block-tools__zoom-out-mode-inserter-button',
{
'is-visible': isVisible || zoomOutModeInserterButtonHovered,
}
'block-editor-block-tools__zoom-out-mode-inserter-button'
) }
onClick={ onClick }
onMouseOver={ () => {
setZoomOutModeInserterButtonHovered( true );
} }
onMouseOut={ () => {
setZoomOutModeInserterButtonHovered( false );
} }
label={ _x(
'Add pattern',
'Generic label for pattern inserter button'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ function ZoomOutModeInserters() {
setInserterIsOpened,
sectionRootClientId,
selectedBlockClientId,
hoveredBlockClientId,
} = useSelect( ( select ) => {
const {
getSettings,
getInsertionPoint,
getBlockOrder,
getSelectionStart,
getSelectedBlockClientId,
getHoveredBlockClientId,
getSectionRootClientId,
isBlockInsertionPointVisible,
} = unlock( select( blockEditorStore ) );
Expand All @@ -46,7 +44,6 @@ function ZoomOutModeInserters() {
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
selectedBlockClientId: getSelectedBlockClientId(),
hoveredBlockClientId: getHoveredBlockClientId(),
};
}, [] );

Expand All @@ -63,7 +60,7 @@ function ZoomOutModeInserters() {
};
}, [] );

if ( ! isReady ) {
if ( ! isReady || ! hasSelection ) {
return null;
}

Expand All @@ -75,23 +72,17 @@ function ZoomOutModeInserters() {
const nextClientId = blockOrder[ index ];

const isSelected =
hasSelection &&
( selectedBlockClientId === previousClientId ||
selectedBlockClientId === nextClientId );

const isHovered =
hoveredBlockClientId === previousClientId ||
hoveredBlockClientId === nextClientId;
selectedBlockClientId === previousClientId ||
selectedBlockClientId === nextClientId;

return (
<BlockPopoverInbetween
key={ index }
previousClientId={ previousClientId }
nextClientId={ nextClientId }
>
{ ! shouldRenderInsertionPoint && (
{ ! shouldRenderInsertionPoint && isSelected && (
<ZoomOutModeInserterButton
isVisible={ isSelected || isHovered }
onClick={ () => {
setInserterIsOpened( {
rootClientId: sectionRootClientId,
Expand Down

0 comments on commit 5128f04

Please sign in to comment.