diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js index 4368d72645959..1a1853ac62a38 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js @@ -19,12 +19,12 @@ import { __experimentalHeading as Heading, Notice, SelectControl, - Spinner, FlexItem, Flex, Button, DropdownMenu, SearchControl, + privateApis as componentsPrivateApis, } from '@wordpress/components'; import { debounce } from '@wordpress/compose'; import { sprintf, __, _x } from '@wordpress/i18n'; @@ -45,6 +45,8 @@ import GoogleFontsConfirmDialog from './google-fonts-confirm-dialog'; import { downloadFontFaceAssets } from './utils'; import { sortFontFaces } from './utils/sort-font-faces'; import CollectionFontVariant from './collection-font-variant'; +import { unlock } from '../../../lock-unlock'; +const { ProgressBar } = unlock( componentsPrivateApis ); const DEFAULT_CATEGORY = { slug: 'all', @@ -136,6 +138,8 @@ function FontCollection( { slug } ) { [ collectionFonts, filters ] ); + const isLoading = ! selectedCollection?.font_families && ! notice; + // NOTE: The height of the font library modal unavailable to use for rendering font family items is roughly 417px // The height of each font family item is 61px. const windowHeight = Math.max( window.innerHeight, MIN_WINDOW_HEIGHT ); @@ -260,235 +264,255 @@ function FontCollection( { slug } ) { return (
- - - - - - { selectedCollection.name } - - { selectedCollection.description } - - - - - - - - - - - { categories && - categories.map( ( category ) => ( - - ) ) } - - - - - - - { ! selectedCollection?.font_families && ! notice && ( - - ) } + { isLoading && ( +
+ +
+ ) } - { !! selectedCollection?.font_families?.length && - ! fonts.length && ( - - { __( - 'No fonts found. Try with a different search term' + { ! isLoading && ( + <> + + + + + + { selectedCollection.name } + + + { selectedCollection.description } + + + + + + + + + + + + { categories && + categories.map( ( category ) => ( + + ) ) } + + + + + + + { !! selectedCollection?.font_families?.length && + ! fonts.length && ( + + { __( + 'No fonts found. Try with a different search term' + ) } + ) } + +
+ { items.map( ( font ) => ( + { + setSelectedFont( + font.font_family_settings + ); + } } + /> + ) ) } +
+
+ + + + { + setSelectedFont( null ); + setNotice( null ); + } } + label={ __( 'Back' ) } + /> + + { selectedFont?.name } + + + { notice && ( + <> + + setNotice( null ) } + > + { notice.message } + + + + ) } + + + { __( 'Select font variants to install.' ) } - ) } - -
- { items.map( ( font ) => ( - { - setSelectedFont( - font.font_family_settings - ); - } } - /> - ) ) } -
-
- - - - { - setSelectedFont( null ); - setNotice( null ); - } } - label={ __( 'Back' ) } - /> - + + + { getSortedFontFaces( selectedFont ).map( + ( face, i ) => ( + + ) + ) } + + + +
+ + { selectedFont && ( + - { selectedFont?.name } - - - { notice && ( - <> - - setNotice( null ) } + + ) } - - { __( 'Select font variants to install.' ) } - - - - { getSortedFontFaces( selectedFont ).map( - ( face, i ) => ( - - ) - ) } - - -
-
- - { selectedFont && ( - - - - ) } - { ! selectedFont && ( - - - - - { createInterpolateElement( - sprintf( - // translators: %s: Total number of pages. - _x( - 'Page of %s', - 'paging' - ), - totalPages - ), - { - CurrentPageControl: ( - { - return { - label: i + 1, - value: i + 1, - }; - } ) } - onChange={ ( newPage ) => - setPage( parseInt( newPage ) ) - } - size={ 'compact' } - __nextHasNoMarginBottom - /> - ), - } - ) } - - - - + { ! selectedFont && ( + + + + + { createInterpolateElement( + sprintf( + // translators: %s: Total number of pages. + _x( + 'Page of %s', + 'paging' + ), + totalPages + ), + { + CurrentPageControl: ( + { + return { + label: i + 1, + value: i + 1, + }; + } ) } + onChange={ ( newPage ) => + setPage( + parseInt( newPage ) + ) + } + size={ 'compact' } + __nextHasNoMarginBottom + /> + ), + } + ) } + + + + + ) } + ) }
); 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 16011a20e82fb..b33bb1b639d00 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 @@ -15,7 +15,6 @@ import { __experimentalVStack as VStack, Flex, Notice, - Spinner, privateApis as componentsPrivateApis, } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; @@ -114,163 +113,171 @@ function InstalledFonts() { return (
{ isResolvingLibrary && ( - - - - - +
+ +
) } - - - { notice && ( - <> - - setNotice( null ) } - > - { notice.message } - - - - ) } - { baseCustomFonts.length > 0 && ( - <> - - { __( 'Installed Fonts' ) } - - - { baseCustomFonts.map( ( font ) => ( - { - handleSetLibraryFontSelected( font ); - } } - /> - ) ) } - - - ) } + { ! isResolvingLibrary && ( + <> + + + { notice && ( + <> + + setNotice( null ) } + > + { notice.message } + + + + ) } + { baseCustomFonts.length > 0 && ( + <> + + { __( 'Installed Fonts' ) } + + + { baseCustomFonts.map( ( font ) => ( + { + handleSetLibraryFontSelected( + font + ); + } } + /> + ) ) } + + + ) } - { baseThemeFonts.length > 0 && ( - <> - - { __( 'Theme Fonts' ) } - - - { baseThemeFonts.map( ( font ) => ( - 0 && ( + <> + + { __( 'Theme Fonts' ) } + + + { baseThemeFonts.map( ( font ) => ( + { + handleSetLibraryFontSelected( + font + ); + } } + /> + ) ) } + + ) } + + + + + + + { - handleSetLibraryFontSelected( font ); + handleSetLibraryFontSelected( null ); } } + label={ __( 'Back' ) } /> - ) ) } - - ) } - - - - + + { libraryFontSelected?.name } + + + { notice && ( + <> + + setNotice( null ) } + > + { notice.message } + + + + ) } + + + { __( + 'Choose font variants. Keep in mind that too many variants could make your site slower.' + ) } + + + + + { getFontFacesToDisplay( + libraryFontSelected + ).map( ( face, i ) => ( + + ) ) } + + + - - + { isInstalling && } + { shouldDisplayDeleteButton && ( + + ) } + - ) } - - + { __( 'Update' ) } + + + + ) }
); } diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/style.scss b/packages/edit-site/src/components/global-styles/font-library-modal/style.scss index ccf4eb7ea623f..201d4d87a3fb1 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/style.scss +++ b/packages/edit-site/src/components/global-styles/font-library-modal/style.scss @@ -7,7 +7,6 @@ $footer-height: 70px; // the content width, we should use that prop instead of this style. // see https://github.com/WordPress/gutenberg/issues/54471. &.font-library-modal { - @include break-medium() { width: 65vw; } @@ -35,9 +34,22 @@ $footer-height: 70px; } .font-library-modal__tabpanel-layout { - margin-top: $grid-unit-40; + .font-library-modal__loading { + width: 100%; + height: 100%; + display: flex; + position: absolute; + left: 0; + top: 0; + align-items: center; + justify-content: center; + // Push down so that the progress bar is centered vertically. + // It should be 120px (72px modal header height + 48px tab height) + padding-top: $header-height + $grid-unit-15 + $grid-unit-60; + } + .font-library-modal__tabpanel-layout__footer { border-top: 1px solid $gray-300; margin: 0 #{$grid-unit-40 * -1} #{$grid-unit-40 * -1}; @@ -72,19 +84,19 @@ $footer-height: 70px; .font-library-modal__font-card__count { color: $gray-700; } -} -.font-library-modal__font-variant_demo-image { - display: block; - height: $grid-unit-30; - width: auto; -} + .font-library-modal__font-variant_demo-image { + display: block; + height: $grid-unit-30; + width: auto; + } -.font-library-modal__font-variant_demo-text { - white-space: nowrap; - flex-shrink: 0; - transition: opacity 0.3s ease-in-out; - @include reduce-motion("transition"); + .font-library-modal__font-variant_demo-text { + white-space: nowrap; + flex-shrink: 0; + transition: opacity 0.3s ease-in-out; + @include reduce-motion("transition"); + } } .font-library-modal__font-variant {