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

Font Library: Improve 'No fonts installed' state when fonts are installed but not activated #63533

Merged
merged 8 commits into from
Jul 22, 2024
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
Loading