Skip to content

Commit

Permalink
Featured Image & Post Title: Hide non content controls when block edi…
Browse files Browse the repository at this point in the history
…ting mode is 'contentOnly' (#59295)

Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
  • Loading branch information
6 people committed Feb 23, 2024
1 parent c9faf06 commit e31be2f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
20 changes: 9 additions & 11 deletions packages/block-library/src/post-featured-image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useBlockProps,
store as blockEditorStore,
__experimentalUseBorderProps as useBorderProps,
useBlockEditingMode,
} from '@wordpress/block-editor';
import { useMemo } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
Expand Down Expand Up @@ -143,6 +144,7 @@ export default function PostFeaturedImageEdit( {
style: { width, height, aspectRatio },
} );
const borderProps = useBorderProps( attributes );
const blockEditingMode = useBlockEditingMode();

const placeholder = ( content ) => {
return (
Expand Down Expand Up @@ -174,8 +176,13 @@ export default function PostFeaturedImageEdit( {
createErrorNotice( message, { type: 'snackbar' } );
};

const controls = (
const controls = blockEditingMode === 'default' && (
<>
<Overlay
attributes={ attributes }
setAttributes={ setAttributes }
clientId={ clientId }
/>
<DimensionControls
clientId={ clientId }
attributes={ attributes }
Expand Down Expand Up @@ -224,6 +231,7 @@ export default function PostFeaturedImageEdit( {
</InspectorControls>
</>
);

let image;

/**
Expand Down Expand Up @@ -251,11 +259,6 @@ export default function PostFeaturedImageEdit( {
) : (
placeholder()
) }
<Overlay
attributes={ attributes }
setAttributes={ setAttributes }
clientId={ clientId }
/>
</div>
</>
);
Expand Down Expand Up @@ -360,11 +363,6 @@ export default function PostFeaturedImageEdit( {
) : (
image
) }
<Overlay
attributes={ attributes }
setAttributes={ setAttributes }
clientId={ clientId }
/>
</figure>
</>
);
Expand Down
92 changes: 49 additions & 43 deletions packages/block-library/src/post-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,53 +115,59 @@ export default function PostTitleEdit( {
return (
<>
{ blockEditingMode === 'default' && (
<BlockControls group="block">
<HeadingLevelDropdown
value={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
) }
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Make title a link' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
{ isLink && (
<>
<>
<BlockControls group="block">
<HeadingLevelDropdown
value={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value ? '_blank' : '_self',
} )
label={ __( 'Make title a link' ) }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ linkTarget === '_blank' }
checked={ isLink }
/>
<TextControl
__nextHasNoMarginBottom
label={ __( 'Link rel' ) }
value={ rel }
onChange={ ( newRel ) =>
setAttributes( { rel: newRel } )
}
/>
</>
) }
</PanelBody>
</InspectorControls>
{ isLink && (
<>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
onChange={ ( value ) =>
setAttributes( {
linkTarget: value
? '_blank'
: '_self',
} )
}
checked={ linkTarget === '_blank' }
/>
<TextControl
__nextHasNoMarginBottom
label={ __( 'Link rel' ) }
value={ rel }
onChange={ ( newRel ) =>
setAttributes( { rel: newRel } )
}
/>
</>
) }
</PanelBody>
</InspectorControls>
</>
) }
{ titleElement }
</>
);
Expand Down

0 comments on commit e31be2f

Please sign in to comment.