Skip to content

Commit

Permalink
Made SiteLogoReplaceFlow always available in the Site Logo block tool…
Browse files Browse the repository at this point in the history
…bar (#63499)


Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mtias <matveb@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
7 people authored Jul 25, 2024
1 parent 1055e02 commit cdab045
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ Removes a media replace notice.
- Required: No

If passed, children are rendered inside the dropdown.

### children

- Type: `Element | func`
- Required: No

If passed, children are rendered inside the dropdown. If a function is provided for this prop, it will receive an object with the `onClose` prop as an argument.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ const MediaReplaceFlow = ( {
{ __( 'Use featured image' ) }
</MenuItem>
) }
{ children }
{ typeof children === 'function'
? children( { onClose } )
: children }
</NavigableMenu>
{ onSelectURL && (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
Expand Down
24 changes: 20 additions & 4 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,29 @@ const SiteLogo = ( {

// This is a light wrapper around MediaReplaceFlow because the block has two
// different MediaReplaceFlows, one for the inspector and one for the toolbar.
function SiteLogoReplaceFlow( { onRemoveLogo, ...mediaReplaceProps } ) {
function SiteLogoReplaceFlow( {
mediaURL,
onRemoveLogo,
...mediaReplaceProps
} ) {
return (
<MediaReplaceFlow
{ ...mediaReplaceProps }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept={ ACCEPT_MEDIA_STRING }
>
<MenuItem onClick={ onRemoveLogo }>{ __( 'Reset' ) }</MenuItem>
{ ( { onClose } ) =>
mediaURL && (
<MenuItem
onClick={ () => {
onRemoveLogo();
onClose();
} }
>
{ __( 'Reset' ) }
</MenuItem>
)
}
</MediaReplaceFlow>
);
}
Expand Down Expand Up @@ -392,7 +407,6 @@ export default function LogoEdit( {
isSelected,
} ) {
const { width, shouldSyncIcon } = attributes;

const {
siteLogoId,
canUserEdit,
Expand Down Expand Up @@ -515,16 +529,18 @@ export default function LogoEdit( {
onInitialSelectLogo( image );
},
onError: onUploadError,
onRemoveLogo,
} );
};

const mediaReplaceFlowProps = {
mediaURL: logoUrl,
name: ! logoUrl ? __( 'Choose logo' ) : __( 'Replace' ),
onSelect: onSelectLogo,
onError: onUploadError,
onRemoveLogo,
};
const controls = canUserEdit && logoUrl && ! temporaryURL && (
const controls = canUserEdit && (
<BlockControls group="other">
<SiteLogoReplaceFlow { ...mediaReplaceFlowProps } />
</BlockControls>
Expand Down

0 comments on commit cdab045

Please sign in to comment.