Skip to content

Commit

Permalink
Font Library: Improve 'No fonts installed' state when fonts are insta…
Browse files Browse the repository at this point in the history
…lled but not activated (#63533)

* Change message when fonts are installed but not activated

* Add custom installed fonts condition for message

* Add installed fonts condition over button text and button action

* Fix e2e test

Co-authored-by: akasunil <sunil25393@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
  • Loading branch information
5 people authored Jul 22, 2024
1 parent a0ed76b commit dc74060
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/edit-site/src/components/global-styles/font-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ import { unlock } from '../../lock-unlock';
const { useGlobalSetting } = unlock( blockEditorPrivateApis );

function FontFamilies() {
const { modalTabOpen, setModalTabOpen } = useContext( FontLibraryContext );
const { baseCustomFonts, modalTabOpen, setModalTabOpen } =
useContext( FontLibraryContext );
const [ fontFamilies ] = useGlobalSetting( 'typography.fontFamilies' );
const [ baseFontFamilies ] = useGlobalSetting(
'typography.fontFamilies',
undefined,
'base'
);
const themeFonts = fontFamilies?.theme
? fontFamilies.theme
.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )
Expand All @@ -40,6 +46,11 @@ function FontFamilies() {
: [];
const hasFonts = 0 < customFonts.length || 0 < themeFonts.length;

const hasInstalledFonts =
hasFonts ||
baseFontFamilies?.theme?.length > 0 ||
baseCustomFonts?.length > 0;

return (
<>
{ !! modalTabOpen && (
Expand Down Expand Up @@ -89,7 +100,11 @@ function FontFamilies() {
{ ! hasFonts && (
<VStack>
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>
<Text as="p">{ __( 'No fonts installed.' ) }</Text>
<Text as="p">
{ hasInstalledFonts
? __( 'No fonts activated.' )
: __( 'No fonts installed.' ) }
</Text>
</VStack>
) }
<Button
Expand All @@ -98,11 +113,15 @@ function FontFamilies() {
__next40pxDefaultSize
onClick={ () =>
setModalTabOpen(
hasFonts ? 'installed-fonts' : 'upload-fonts'
hasInstalledFonts
? 'installed-fonts'
: 'upload-fonts'
)
}
>
{ hasFonts ? __( 'Manage fonts' ) : __( 'Add fonts' ) }
{ hasInstalledFonts
? __( 'Manage fonts' )
: __( 'Add fonts' ) }
</Button>
</VStack>
</>
Expand Down

0 comments on commit dc74060

Please sign in to comment.