From 65468ce8a509fac6689395bad954221bdbcd2aca Mon Sep 17 00:00:00 2001 From: Mustafa Bharmal Date: Fri, 30 Oct 2026 19:40:16 +0530 Subject: [PATCH 1/2] Font Library: Paginate installed fonts --- .../src/font-library/font-collection.tsx | 116 ++---------------- .../src/font-library/installed-fonts.tsx | 55 ++++++++- .../src/font-library/pagination.tsx | 107 ++++++++++++++++ 3 files changed, 168 insertions(+), 110 deletions(-) create mode 100644 packages/global-styles-ui/src/font-library/pagination.tsx diff --git a/packages/global-styles-ui/src/font-library/font-collection.tsx b/packages/global-styles-ui/src/font-library/font-collection.tsx index 319c2b24af65ed..f4d64d7d891d99 100644 --- a/packages/global-styles-ui/src/font-library/font-collection.tsx +++ b/packages/global-styles-ui/src/font-library/font-collection.tsx @@ -1,10 +1,4 @@ -import { - useContext, - useEffect, - useState, - useMemo, - createInterpolateElement, -} from '@wordpress/element'; +import { useContext, useEffect, useState, useMemo } from '@wordpress/element'; import { __experimentalSpacer as Spacer, __experimentalText as WCText, @@ -23,17 +17,10 @@ import { // eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135. Menu, Progress, - Select, } from '@wordpress/ui'; import { debounce } from '@wordpress/compose'; -import { sprintf, __, _x, isRTL } from '@wordpress/i18n'; -import { - moreVertical, - next, - previous, - chevronLeft, - chevronRight, -} from '@wordpress/icons'; +import { __, _x, isRTL } from '@wordpress/i18n'; +import { moreVertical, chevronLeft, chevronRight } from '@wordpress/icons'; import { useEntityRecord } from '@wordpress/core-data'; import type { FontCollection as FontCollectionType, @@ -43,6 +30,7 @@ import type { } from '@wordpress/core-data'; import { FontLibraryContext } from './context'; import FontCard from './font-card'; +import Pagination, { getFontsPerPage } from './pagination'; import filterFonts from './utils/filter-fonts'; import { toggleFont } from './utils/toggleFont'; import { @@ -61,7 +49,6 @@ const DEFAULT_CATEGORY = { }; const LOCAL_STORAGE_ITEM = 'wp-font-library-google-fonts-permission'; -const MIN_WINDOW_HEIGHT = 500; function FontCollection( { slug }: { slug: string } ) { const requiresPermission = slug === 'google-fonts'; @@ -136,10 +123,7 @@ function FontCollection( { slug }: { slug: string } ) { [ collectionFonts, filters ] ); - // 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 ); - const pageSize = Math.floor( ( windowHeight - 417 ) / 61 ); + const pageSize = getFontsPerPage(); const totalPages = Math.ceil( fonts.length / pageSize ); const itemsStart = ( page - 1 ) * pageSize; const itemsLimit = page * pageSize; @@ -546,91 +530,11 @@ function FontCollection( { slug }: { slug: string } ) { justify="end" spacing={ 6 } > - - { createInterpolateElement( - sprintf( - // translators: 1: Current page number, 2: Total number of pages. - _x( - '
Page
%1$s
of %2$d
', - 'paging' - ), - '', - totalPages - ), - { - div:
, - // @ts-expect-error — Tag injected via sprintf argument, not visible in format string. - CurrentPage: ( - { - if ( newPage !== null ) { - setPage( - parseInt( newPage ) - ); - } - } } - > - - - { [ - ...Array( totalPages ), - ].map( ( e, i ) => { - const value = ( - i + 1 - ).toString(); - return ( - - - { value } - - - ); - } ) } - - - ), - } - ) } - - -