+
+
+
+
+ { selectedCollection.name }
+
+
+
+ { selectedCollection.description }
+
+
+
+ }
+ suffix={
+ filters?.search ? (
+
+ ) : null
+ }
+ />
+
+
+
+ { categories &&
+ categories.map( ( category ) => (
+
+ ) ) }
+
+
+
+
+
+
+ { ! selectedCollection?.font_families && ! notice && (
+
+ ) }
+
+ { !! selectedCollection?.font_families?.length &&
+ ! fonts.length && (
+
+ { __(
+ 'No fonts found. Try with a different search term'
+ ) }
+
+ ) }
- { ! renderConfirmDialog && ! selectedFont && (
-
-
- }
- suffix={
- filters?.search ? (
-
- ) : null
- }
+
+ { items.map( ( font ) => (
+ {
+ setSelectedFont(
+ font.font_family_settings
+ );
+ } }
+ />
+ ) ) }
+
+
+
+
+
+ {
+ setSelectedFont( null );
+ } }
+ aria-label={ __( 'Navigate to the previous view' ) }
/>
-
-
-
- { categories &&
- categories.map( ( category ) => (
-
- ) ) }
-
-
+ { selectedFont?.name }
+
+
+ { notice && (
+ <>
+
+ setNotice( null ) }
+ >
+ { notice.message }
+
+
+ >
+ ) }
+
+ { __( 'Select font variants to install.' ) }
+
+
+
+ { getSortedFontFaces( selectedFont ).map(
+ ( face, i ) => (
+
+ )
+ ) }
+
+
+
+
+
+ { selectedFont && (
+
+
) }
-
- { ! renderConfirmDialog &&
- ! selectedCollection?.font_families &&
- ! notice &&
}
-
- { ! renderConfirmDialog &&
- !! selectedCollection?.font_families?.length &&
- ! fonts.length && (
-
- { __(
- 'No fonts found. Try with a different search term'
+ { ! selectedFont && (
+
+
+
+
+ { createInterpolateElement(
+ sprintf(
+ // translators: %s: Total number of pages.
+ _x(
+ 'Page of %s',
+ 'paging'
+ ),
+ totalPages
+ ),
+ {
+ CurrenPageControl: (
+ {
+ return {
+ label: i + 1,
+ value: i + 1,
+ };
+ } ) }
+ onChange={ ( newPage ) =>
+ setPage( parseInt( newPage ) )
+ }
+ size={ 'compact' }
+ __nextHasNoMarginBottom
+ />
+ ),
+ }
) }
-
- ) }
-
- { ! renderConfirmDialog && selectedFont && (
-
- ) }
-
- { ! renderConfirmDialog && ! selectedFont && (
-
- { items.map( ( font ) => (
- {
- setSelectedFont( font.font_family_settings );
- } }
- />
- ) ) }
-
+
+
+
+
) }
-
- );
-}
-
-function PaginationFooter( { page, totalPages, setPage } ) {
- return (
-
-
-
-
- { createInterpolateElement(
- sprintf(
- // translators: %s: Total number of pages.
- _x( 'Page of %s', 'paging' ),
- totalPages
- ),
- {
- CurrenPageControl: (
- {
- return {
- label: i + 1,
- value: i + 1,
- };
- }
- ) }
- onChange={ ( newPage ) =>
- setPage( parseInt( newPage ) )
- }
- size={ 'compact' }
- __nextHasNoMarginBottom
- />
- ),
- }
- ) }
-
-
-
-
- );
-}
-
-function InstallFooter( { handleInstall, isDisabled } ) {
- const { isInstalling } = useContext( FontLibraryContext );
-
- return (
-
-
-
+
);
}
diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/font-demo.js b/packages/edit-site/src/components/global-styles/font-library-modal/font-demo.js
index ee745caf45932e..0320bdd4e4893f 100644
--- a/packages/edit-site/src/components/global-styles/font-library-modal/font-demo.js
+++ b/packages/edit-site/src/components/global-styles/font-library-modal/font-demo.js
@@ -8,7 +8,10 @@ import { useContext, useEffect, useState, useRef } from '@wordpress/element';
* Internal dependencies
*/
import { FontLibraryContext } from './context';
-import { getFacePreviewStyle } from './utils/preview-styles';
+import {
+ getFacePreviewStyle,
+ getFamilyPreviewStyle,
+} from './utils/preview-styles';
function getPreviewUrl( fontFace ) {
if ( fontFace.preview ) {
@@ -19,8 +22,39 @@ function getPreviewUrl( fontFace ) {
}
}
-function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
+function getDisplayFontFace( font ) {
+ // if this IS a font face return it
+ if ( font.fontStyle || font.fontWeight ) {
+ return font;
+ }
+ // if this is a font family with a collection of font faces
+ // return the first one that is normal and 400 OR just the first one
+ if ( font.fontFace && font.fontFace.length ) {
+ return (
+ font.fontFace.find(
+ ( face ) =>
+ face.fontStyle === 'normal' && face.fontWeight === '400'
+ ) || font.fontFace[ 0 ]
+ );
+ }
+ // This must be a font family with no font faces
+ // return a fake font face
+ return {
+ fontStyle: 'normal',
+ fontWeight: '400',
+ fontFamily: font.fontFamily,
+ fake: true,
+ };
+}
+
+function FontDemo( { font, text } ) {
const ref = useRef( null );
+
+ const fontFace = getDisplayFontFace( font );
+ const style = getFamilyPreviewStyle( font );
+ text = text || font.name;
+ const customPreviewUrl = font.preview;
+
const [ isIntersecting, setIsIntersecting ] = useState( false );
const [ isAssetLoaded, setIsAssetLoaded ] = useState( false );
const { loadFontFaceAsset } = useContext( FontLibraryContext );
@@ -34,8 +68,8 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
fontSize: '18px',
lineHeight: 1,
opacity: isAssetLoaded ? '1' : '0',
- ...faceStyles,
...style,
+ ...faceStyles,
};
useEffect( () => {
@@ -79,4 +113,4 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
);
}
-export default FontFaceDemo;
+export default FontDemo;
diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js
index 99c99e44a43afc..a72b7d59d150cf 100644
--- a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js
+++ b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js
@@ -1,27 +1,35 @@
/**
* WordPress dependencies
*/
-import { __ } from '@wordpress/i18n';
-import { useContext, useEffect, useState } from '@wordpress/element';
import {
- privateApis as componentsPrivateApis,
+ Button,
+ __experimentalConfirmDialog as ConfirmDialog,
__experimentalHStack as HStack,
+ __experimentalHeading as Heading,
+ __experimentalNavigatorProvider as NavigatorProvider,
+ __experimentalNavigatorScreen as NavigatorScreen,
+ __experimentalNavigatorToParentButton as NavigatorToParentButton,
+ __experimentalUseNavigator as useNavigator,
__experimentalSpacer as Spacer,
__experimentalText as Text,
- Button,
+ __experimentalVStack as VStack,
+ Flex,
+ Notice,
Spinner,
- FlexItem,
+ privateApis as componentsPrivateApis,
} from '@wordpress/components';
+import { useContext, useEffect, useState } from '@wordpress/element';
+import { __, sprintf } from '@wordpress/i18n';
+import { chevronLeft } from '@wordpress/icons';
/**
* Internal dependencies
*/
-import TabPanelLayout from './tab-panel-layout';
-import { FontLibraryContext } from './context';
-import LibraryFontDetails from './library-font-details';
-import LibraryFontCard from './library-font-card';
-import ConfirmDeleteDialog from './confirm-delete-dialog';
import { unlock } from '../../../lock-unlock';
+import { FontLibraryContext } from './context';
+import FontCard from './font-card';
+import LibraryFontVariant from './library-font-variant';
+import { sortFontFaces } from './utils/sort-font-faces';
const { ProgressBar } = unlock( componentsPrivateApis );
function InstalledFonts() {
@@ -33,102 +41,98 @@ function InstalledFonts() {
refreshLibrary,
uninstallFontFamily,
isResolvingLibrary,
+ isInstalling,
+ saveFontFamilies,
+ getFontFacesActivated,
+ fontFamiliesHasChanges,
notice,
setNotice,
} = useContext( FontLibraryContext );
const [ isConfirmDeleteOpen, setIsConfirmDeleteOpen ] = useState( false );
- const handleUnselectFont = () => {
- handleSetLibraryFontSelected( null );
- };
+ const shouldDisplayDeleteButton =
+ !! libraryFontSelected && libraryFontSelected?.source !== 'theme';
- const handleSelectFont = ( font ) => {
- handleSetLibraryFontSelected( font );
+ const handleUninstallClick = () => {
+ setIsConfirmDeleteOpen( true );
};
- const handleConfirmUninstall = async () => {
- setNotice( null );
-
- try {
- await uninstallFontFamily( libraryFontSelected );
- setNotice( {
- type: 'success',
- message: __( 'Font family uninstalled successfully.' ),
- } );
-
- // If the font was succesfully uninstalled it is unselected.
- handleUnselectFont();
- setIsConfirmDeleteOpen( false );
- } catch ( error ) {
- setNotice( {
- type: 'error',
- message:
- __( 'There was an error uninstalling the font family. ' ) +
- error.message,
- } );
+ const getFontFacesToDisplay = ( font ) => {
+ if ( ! font ) {
+ return [];
}
+ if ( ! font.fontFace || ! font.fontFace.length ) {
+ return [
+ {
+ fontFamily: font.fontFamily,
+ fontStyle: 'normal',
+ fontWeight: '400',
+ },
+ ];
+ }
+ return sortFontFaces( font.fontFace );
};
- const handleUninstallClick = async () => {
- setIsConfirmDeleteOpen( true );
- };
-
- const handleCancelUninstall = () => {
- setIsConfirmDeleteOpen( false );
+ const getFontCardVariantsText = ( font ) => {
+ const variantsInstalled =
+ font?.fontFace?.length > 0 ? font.fontFace.length : 1;
+ const variantsActive = getFontFacesActivated(
+ font.slug,
+ font.source
+ ).length;
+ return sprintf(
+ /* translators: 1: Active font variants, 2: Total font variants. */
+ __( '%1$s/%2$s variants active' ),
+ variantsActive,
+ variantsInstalled
+ );
};
- const tabDescription = !! libraryFontSelected
- ? __(
- 'Choose font variants. Keep in mind that too many variants could make your site slower.'
- )
- : null;
-
- const shouldDisplayDeleteButton =
- !! libraryFontSelected && libraryFontSelected?.source !== 'theme';
-
useEffect( () => {
- handleSelectFont( libraryFontSelected );
+ handleSetLibraryFontSelected( libraryFontSelected );
refreshLibrary();
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, [] );
return (
-