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

refactor site logo media panel. #67972

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 87 additions & 30 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '@wordpress/element';
import { __, isRTL } from '@wordpress/i18n';
import {
PanelBody,
RangeControl,
ResizableBox,
Spinner,
Expand All @@ -24,6 +23,8 @@ import {
Button,
DropZone,
FlexItem,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
__experimentalItemGroup as ItemGroup,
__experimentalHStack as HStack,
__experimentalTruncate as Truncate,
Expand Down Expand Up @@ -278,31 +279,55 @@ const SiteLogo = ( {
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
<ToolsPanel label={ __( 'Settings' ) }>
<ToolsPanelItem
hasValue={ () => !! width }
label={ __( 'Image width' ) }
onChange={ ( newWidth ) =>
setAttributes( { width: newWidth } )
onDeselect={ () =>
setAttributes( { width: undefined } )
}
min={ minWidth }
max={ maxWidthBuffer }
initialPosition={ Math.min(
defaultWidth,
maxWidthBuffer
) }
value={ width || '' }
disabled={ ! isResizable }
/>
<ToggleControl
__nextHasNoMarginBottom
>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Image width' ) }
onChange={ ( newWidth ) =>
setAttributes( { width: newWidth } )
}
min={ minWidth }
max={ maxWidthBuffer }
initialPosition={ Math.min(
defaultWidth,
maxWidthBuffer
) }
value={ width || '' }
disabled={ ! isResizable }
/>
</ToolsPanelItem>

<ToolsPanelItem
hasValue={ () => !! isLink }
label={ __( 'Link image to home' ) }
onChange={ () => setAttributes( { isLink: ! isLink } ) }
checked={ isLink }
/>
onDeselect={ () => setAttributes( { isLink: false } ) }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Link image to home' ) }
onChange={ () =>
setAttributes( { isLink: ! isLink } )
}
checked={ isLink }
/>
</ToolsPanelItem>

{ isLink && (
<>
<ToolsPanelItem
hasValue={ () => linkTarget === '_blank' }
label={ __( 'Open in new tab' ) }
onDeselect={ () =>
setAttributes( { linkTarget: '_self' } )
}
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Open in new tab' ) }
Expand All @@ -313,10 +338,18 @@ const SiteLogo = ( {
}
checked={ linkTarget === '_blank' }
/>
</>
</ToolsPanelItem>
) }

{ canUserEdit && (
<>
<ToolsPanelItem
hasValue={ () => !! shouldSyncIcon }
label={ __( 'Use as Site Icon' ) }
onDeselect={ () => {
setAttributes( { shouldSyncIcon: false } );
setIcon( undefined );
} }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Use as Site Icon' ) }
Expand All @@ -327,9 +360,9 @@ const SiteLogo = ( {
checked={ !! shouldSyncIcon }
help={ syncSiteIconHelpText }
/>
</>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
<BlockControls group="block">
{ canEditImage && ! isEditingImage && (
Expand Down Expand Up @@ -597,8 +630,20 @@ export default function LogoEdit( {

const mediaInspectorPanel = ( canUserEdit || logoUrl ) && (
<InspectorControls>
<PanelBody title={ __( 'Media' ) }>
<div className="block-library-site-logo__inspector-media-replace-container">
<ToolsPanel
label={ __( 'Media' ) }
resetAll={ () => {
setAttributes( {
logoUrl: null,
mediaItemData: null,
} );
} }
>
<ToolsPanelItem
hasValue={ () => !! logoUrl && ! canUserEdit }
label={ __( 'Preview Logo (Read-only)' ) }
resetAll={ () => setAttributes( { logoUrl: null } ) }
>
{ ! canUserEdit && !! logoUrl && (
<InspectorLogoPreview
mediaItemData={ mediaItemData }
Expand All @@ -609,6 +654,12 @@ export default function LogoEdit( {
} }
/>
) }
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => !! logoUrl && canUserEdit }
label={ __( 'Replace Logo' ) }
resetAll={ () => setAttributes( { logoUrl: null } ) }
>
{ canUserEdit && !! logoUrl && (
<SiteLogoReplaceFlow
{ ...mediaReplaceFlowProps }
Expand All @@ -620,6 +671,12 @@ export default function LogoEdit( {
popoverProps={ {} }
/>
) }
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => ! logoUrl && canUserEdit }
label={ __( 'Upload Logo' ) }
resetAll={ () => setAttributes( { logoUrl: null } ) }
>
{ canUserEdit && ! logoUrl && (
<MediaUploadCheck>
<MediaUpload
Expand All @@ -644,8 +701,8 @@ export default function LogoEdit( {
/>
</MediaUploadCheck>
) }
</div>
</PanelBody>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>
);

Expand Down
Loading