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: Group fonts by source #63211

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
62 changes: 33 additions & 29 deletions packages/edit-site/src/components/global-styles/font-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalText as Text,
__experimentalItemGroup as ItemGroup,
__experimentalVStack as VStack,
Button,
Expand Down Expand Up @@ -48,48 +49,51 @@ function FontFamilies() {
/>
) }

<VStack spacing={ 2 }>
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>
{ hasFonts ? (
<>
<VStack spacing={ 4 }>
{ themeFonts.length > 0 && (
<VStack>
<Subtitle level={ 3 }>{ __( 'Theme Fonts' ) }</Subtitle>
<ItemGroup isBordered isSeparated>
{ customFonts.map( ( font ) => (
{ themeFonts.map( ( font ) => (
<FontFamilyItem
key={ font.slug }
font={ font }
/>
) ) }
{ themeFonts.map( ( font ) => (
</ItemGroup>
</VStack>
) }
{ customFonts.length > 0 && (
<VStack>
<Subtitle level={ 3 }>{ __( 'User fonts' ) }</Subtitle>
<ItemGroup isBordered isSeparated>
{ customFonts.map( ( font ) => (
<FontFamilyItem
key={ font.slug }
font={ font }
/>
) ) }
</ItemGroup>
<Button
className="edit-site-global-styles-font-families__manage-fonts"
variant="secondary"
__next40pxDefaultSize
onClick={ () =>
setModalTabOpen( 'installed-fonts' )
}
>
{ __( 'Manage fonts' ) }
</Button>
</>
) : (
<>
{ __( 'No fonts installed.' ) }
<Button
className="edit-site-global-styles-font-families__add-fonts"
variant="secondary"
__next40pxDefaultSize
onClick={ () => setModalTabOpen( 'upload-fonts' ) }
>
{ __( 'Add fonts' ) }
</Button>
</>
</VStack>
) }
{ ! hasFonts && (
<VStack>
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>
<Text as="p">{ __( 'No fonts installed.' ) }</Text>
Copy link
Contributor

@matiasbenedetto matiasbenedetto Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are fonts installed but none of them are active the text, 'No fonts installed' is technically incorrect. Should we replaced this by 'No fonts activated' or add a conditional to render 'activated'/'installed' depending on the availability of base fonts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'd agree that's incorrect but it already happens on trunk. It's not related to this PR.
I'd consider to open a separate issue. With fonts installed but no one activated, the wording should be different. Also, the 'Add fonts' button would be misleading and should be instead the 'Manage fonts' one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will split this to a new issue so that this PR can move on

</VStack>
) }
<Button
className="edit-site-global-styles-font-families__manage-fonts"
variant="secondary"
__next40pxDefaultSize
onClick={ () =>
setModalTabOpen(
hasFonts ? 'installed-fonts' : 'upload-fonts'
)
}
>
{ hasFonts ? __( 'Manage fonts' ) : __( 'Add fonts' ) }
</Button>
</VStack>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ function InstalledFonts() {
{ notice.message }
</Notice>
) }
{ baseCustomFonts.length > 0 && (
{ baseThemeFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
{ __( 'Installed Fonts' ) }
{ __( 'Theme Fonts' ) }
</h2>
{ /*
* Disable reason: The `list` ARIA role is redundant but
Expand All @@ -183,7 +183,7 @@ function InstalledFonts() {
role="list"
className="font-library-modal__fonts-list"
>
{ baseCustomFonts.map( ( font ) => (
{ baseThemeFonts.map( ( font ) => (
<li
key={ font.slug }
className="font-library-modal__fonts-list-item"
Expand All @@ -206,10 +206,10 @@ function InstalledFonts() {
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
</VStack>
) }
{ baseThemeFonts.length > 0 && (
{ baseCustomFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
{ __( 'Theme Fonts' ) }
{ __( 'User fonts' ) }
</h2>
{ /*
* Disable reason: The `list` ARIA role is redundant but
Expand All @@ -220,7 +220,7 @@ function InstalledFonts() {
role="list"
className="font-library-modal__fonts-list"
>
{ baseThemeFonts.map( ( font ) => (
{ baseCustomFonts.map( ( font ) => (
<li
key={ font.slug }
className="font-library-modal__fonts-list-item"
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
color: $gray-700;
}

.edit-site-global-styles-font-families__add-fonts,
.edit-site-global-styles-font-families__manage-fonts {
justify-content: center;
}
Expand Down
Loading