Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title & Featured Image: Hide non content controls when block editing mode is 'contentOnly' #59295

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 9 additions & 11 deletions packages/block-library/src/post-featured-image/edit.js
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
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