Skip to content

Commit

Permalink
Image Block: Conditionally Render Block Control Based on Component Pr…
Browse files Browse the repository at this point in the history
…esence (#62132)

* Refactor image block control rendering logic for clarity.

* Refactor conditional rendering logic for block controls.

Co-authored-by: amitraj2203 <[email protected]>
Co-authored-by: michalczaplinski <[email protected]>
Co-authored-by: annezazu <[email protected]>
  • Loading branch information
4 people authored May 30, 2024
1 parent e108d7c commit 3a95bcc
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,21 @@ export default function Image( {
[ clientId, isSingleSelected, metadata?.bindings ]
);

const showUrlInput =
isSingleSelected &&
! isEditingImage &&
! lockHrefControls &&
! lockUrlControls;

const showCoverControls = isSingleSelected && canInsertCover;

const showBlockControls = showUrlInput || allowCrop || showCoverControls;

const controls = (
<>
<BlockControls group="block">
{ isSingleSelected &&
! isEditingImage &&
! lockHrefControls &&
! lockUrlControls && (
{ showBlockControls && (
<BlockControls group="block">
{ showUrlInput && (
<ImageURLInputUI
url={ href || '' }
onChangeUrl={ onSetHref }
Expand All @@ -521,21 +529,22 @@ export default function Image( {
resetLightbox={ resetLightbox }
/>
) }
{ allowCrop && (
<ToolbarButton
onClick={ () => setIsEditingImage( true ) }
icon={ crop }
label={ __( 'Crop' ) }
/>
) }
{ isSingleSelected && canInsertCover && (
<ToolbarButton
icon={ overlayText }
label={ __( 'Add text over image' ) }
onClick={ switchToCover }
/>
) }
</BlockControls>
{ allowCrop && (
<ToolbarButton
onClick={ () => setIsEditingImage( true ) }
icon={ crop }
label={ __( 'Crop' ) }
/>
) }
{ showCoverControls && (
<ToolbarButton
icon={ overlayText }
label={ __( 'Add text over image' ) }
onClick={ switchToCover }
/>
) }
</BlockControls>
) }
{ isSingleSelected && ! isEditingImage && ! lockUrlControls && (
<BlockControls group="other">
<MediaReplaceFlow
Expand Down

0 comments on commit 3a95bcc

Please sign in to comment.