Skip to content

Commit

Permalink
Jetpack AI Logo generator toolbar button label (#39550)
Browse files Browse the repository at this point in the history
* add prop to toggle button text

* show button text Generate if the site has no logo set

* add changelog

* rename prop so it's not misleading
  • Loading branch information
CGastrell authored Sep 27, 2024
1 parent b6a5258 commit eac6e50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Jetpack AI: show button label on logo block toolbar if site's logo is empty
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,34 @@ import type { ReactElement } from 'react';
/**
* The toolbar button that toggles the Logo Generator Modal.
*
* @param {object} props - The component props.
* @param {Function} props.clickHandler - The handler for the click event.
* @param {object} props - The component props.
* @param {Function} props.clickHandler - The handler for the click event.
* @param {boolean} props.showButtonText - Use text for the button face or not.
* @return {ReactElement} The toolbar button.
*/
export default function AiToolbarButton( {
clickHandler,
showButtonText = false,
}: {
clickHandler?: () => void;
showButtonText?: boolean;
} ): ReactElement {
const toggleFromToolbar = useCallback( () => {
clickHandler?.();
}, [ clickHandler ] );

const text = showButtonText ? __( 'Generate', 'jetpack' ) : '';

return (
<>
<ToolbarButton
showTooltip
onClick={ toggleFromToolbar }
label={ __( 'Generate with AI', 'jetpack' ) }
icon={ aiAssistantIcon }
/>
>
{ text }
</ToolbarButton>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type CoreSelect = {
url: string;
title: string;
description: string;
site_logo: number;
};
};

Expand Down Expand Up @@ -80,6 +81,7 @@ const useSiteDetails = () => {
domain: window?.Jetpack_Editor_Initial_State?.siteFragment,
name: siteSettings?.title,
description: siteSettings?.description,
siteLogo: siteSettings?.site_logo || 0,
};
};

Expand Down Expand Up @@ -129,7 +131,7 @@ const siteLogoEditWithAiComponents = createHigherOrderComponent( BlockEdit => {
<>
<BlockEdit { ...props } />
<BlockControls group="block">
<AiToolbarButton clickHandler={ showModal } />
<AiToolbarButton showButtonText={ ! siteDetails?.siteLogo } clickHandler={ showModal } />
</BlockControls>
<GeneratorModal
isOpen={ isLogoGeneratorModalVisible }
Expand Down

0 comments on commit eac6e50

Please sign in to comment.