@wordpress/edit-site 5.28.3 → 5.28.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/build/components/global-styles/font-library-modal/collection-font-variant.js +2 -2
  2. package/build/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
  3. package/build/components/global-styles/font-library-modal/font-card.js +10 -15
  4. package/build/components/global-styles/font-library-modal/font-card.js.map +1 -1
  5. package/build/components/global-styles/font-library-modal/font-collection.js +113 -60
  6. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  7. package/build/components/global-styles/font-library-modal/font-demo.js +29 -8
  8. package/build/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  9. package/build/components/global-styles/font-library-modal/installed-fonts.js +142 -79
  10. package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  11. package/build/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  12. package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  13. package/build/components/global-styles/font-library-modal/upload-fonts.js +6 -4
  14. package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  15. package/build/components/global-styles/screen-revisions/index.js +2 -2
  16. package/build/components/global-styles/screen-revisions/index.js.map +1 -1
  17. package/build/components/global-styles/ui.js +27 -2
  18. package/build/components/global-styles/ui.js.map +1 -1
  19. package/build/components/header-edit-mode/index.js +1 -1
  20. package/build/components/header-edit-mode/index.js.map +1 -1
  21. package/build/components/page-patterns/index.js +14 -14
  22. package/build/components/page-patterns/index.js.map +1 -1
  23. package/build/components/sidebar/index.js +3 -2
  24. package/build/components/sidebar/index.js.map +1 -1
  25. package/build/components/sidebar-dataviews/default-views.js +2 -0
  26. package/build/components/sidebar-dataviews/default-views.js.map +1 -1
  27. package/build/components/sidebar-navigation-screen-templates-browse/content.js +2 -2
  28. package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
  29. package/build/components/sidebar-navigation-screen-templates-browse/index.js +7 -5
  30. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  31. package/build/components/style-book/index.js +2 -0
  32. package/build/components/style-book/index.js.map +1 -1
  33. package/build-module/components/global-styles/font-library-modal/collection-font-variant.js +4 -4
  34. package/build-module/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
  35. package/build-module/components/global-styles/font-library-modal/font-card.js +11 -16
  36. package/build-module/components/global-styles/font-library-modal/font-card.js.map +1 -1
  37. package/build-module/components/global-styles/font-library-modal/font-collection.js +116 -63
  38. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  39. package/build-module/components/global-styles/font-library-modal/font-demo.js +30 -9
  40. package/build-module/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  41. package/build-module/components/global-styles/font-library-modal/installed-fonts.js +142 -79
  42. package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  43. package/build-module/components/global-styles/font-library-modal/library-font-variant.js +4 -4
  44. package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  45. package/build-module/components/global-styles/font-library-modal/upload-fonts.js +7 -5
  46. package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  47. package/build-module/components/global-styles/screen-revisions/index.js +2 -2
  48. package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
  49. package/build-module/components/global-styles/ui.js +27 -2
  50. package/build-module/components/global-styles/ui.js.map +1 -1
  51. package/build-module/components/header-edit-mode/index.js +1 -1
  52. package/build-module/components/header-edit-mode/index.js.map +1 -1
  53. package/build-module/components/page-patterns/index.js +14 -14
  54. package/build-module/components/page-patterns/index.js.map +1 -1
  55. package/build-module/components/sidebar/index.js +3 -2
  56. package/build-module/components/sidebar/index.js.map +1 -1
  57. package/build-module/components/sidebar-dataviews/default-views.js +3 -1
  58. package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
  59. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +2 -2
  60. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
  61. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +7 -5
  62. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  63. package/build-module/components/style-book/index.js +2 -0
  64. package/build-module/components/style-book/index.js.map +1 -1
  65. package/build-style/style-rtl.css +28 -22
  66. package/build-style/style.css +28 -22
  67. package/package.json +18 -18
  68. package/src/components/global-styles/font-library-modal/collection-font-variant.js +4 -4
  69. package/src/components/global-styles/font-library-modal/font-card.js +11 -26
  70. package/src/components/global-styles/font-library-modal/font-collection.js +304 -210
  71. package/src/components/global-styles/font-library-modal/font-demo.js +38 -4
  72. package/src/components/global-styles/font-library-modal/installed-fonts.js +226 -114
  73. package/src/components/global-styles/font-library-modal/library-font-variant.js +4 -4
  74. package/src/components/global-styles/font-library-modal/style.scss +15 -8
  75. package/src/components/global-styles/font-library-modal/upload-fonts.js +13 -5
  76. package/src/components/global-styles/screen-revisions/index.js +5 -2
  77. package/src/components/global-styles/ui.js +26 -2
  78. package/src/components/header-edit-mode/index.js +3 -1
  79. package/src/components/page-patterns/index.js +20 -20
  80. package/src/components/sidebar/index.js +2 -1
  81. package/src/components/sidebar-dataviews/default-views.js +3 -1
  82. package/src/components/sidebar-navigation-screen-templates-browse/content.js +2 -2
  83. package/src/components/sidebar-navigation-screen-templates-browse/index.js +5 -3
  84. package/src/components/style-book/index.js +5 -1
  85. package/build/components/global-styles/font-library-modal/collection-font-details.js +0 -50
  86. package/build/components/global-styles/font-library-modal/collection-font-details.js.map +0 -1
  87. package/build/components/global-styles/font-library-modal/confirm-delete-dialog.js +0 -30
  88. package/build/components/global-styles/font-library-modal/confirm-delete-dialog.js.map +0 -1
  89. package/build/components/global-styles/font-library-modal/library-font-card.js +0 -39
  90. package/build/components/global-styles/font-library-modal/library-font-card.js.map +0 -1
  91. package/build/components/global-styles/font-library-modal/tab-panel-layout.js +0 -67
  92. package/build/components/global-styles/font-library-modal/tab-panel-layout.js.map +0 -1
  93. package/build-module/components/global-styles/font-library-modal/collection-font-details.js +0 -42
  94. package/build-module/components/global-styles/font-library-modal/collection-font-details.js.map +0 -1
  95. package/build-module/components/global-styles/font-library-modal/confirm-delete-dialog.js +0 -23
  96. package/build-module/components/global-styles/font-library-modal/confirm-delete-dialog.js.map +0 -1
  97. package/build-module/components/global-styles/font-library-modal/library-font-card.js +0 -31
  98. package/build-module/components/global-styles/font-library-modal/library-font-card.js.map +0 -1
  99. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js +0 -60
  100. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js.map +0 -1
  101. package/src/components/global-styles/font-library-modal/collection-font-details.js +0 -56
  102. package/src/components/global-styles/font-library-modal/confirm-delete-dialog.js +0 -33
  103. package/src/components/global-styles/font-library-modal/library-font-card.js +0 -34
  104. package/src/components/global-styles/font-library-modal/tab-panel-layout.js +0 -85
@@ -13,43 +13,58 @@ import {
13
13
  __experimentalInputControl as InputControl,
14
14
  __experimentalText as Text,
15
15
  __experimentalHStack as HStack,
16
+ __experimentalVStack as VStack,
17
+ __experimentalNavigatorProvider as NavigatorProvider,
18
+ __experimentalNavigatorScreen as NavigatorScreen,
19
+ __experimentalNavigatorToParentButton as NavigatorToParentButton,
20
+ __experimentalHeading as Heading,
21
+ Notice,
16
22
  SelectControl,
17
23
  Spinner,
18
24
  Icon,
19
25
  FlexItem,
20
26
  Flex,
21
27
  Button,
28
+ DropdownMenu,
22
29
  } from '@wordpress/components';
23
30
  import { debounce } from '@wordpress/compose';
24
31
  import { sprintf, __, _x } from '@wordpress/i18n';
25
- import { search, closeSmall } from '@wordpress/icons';
32
+ import {
33
+ search,
34
+ closeSmall,
35
+ moreVertical,
36
+ chevronLeft,
37
+ } from '@wordpress/icons';
26
38
 
27
39
  /**
28
40
  * Internal dependencies
29
41
  */
30
- import TabPanelLayout from './tab-panel-layout';
31
42
  import { FontLibraryContext } from './context';
32
43
  import FontCard from './font-card';
33
44
  import filterFonts from './utils/filter-fonts';
34
- import CollectionFontDetails from './collection-font-details';
35
45
  import { toggleFont } from './utils/toggleFont';
36
- import { getFontsOutline } from './utils/fonts-outline';
46
+ import {
47
+ getFontsOutline,
48
+ isFontFontFaceInOutline,
49
+ } from './utils/fonts-outline';
37
50
  import GoogleFontsConfirmDialog from './google-fonts-confirm-dialog';
38
51
  import { downloadFontFaceAssets } from './utils';
52
+ import { sortFontFaces } from './utils/sort-font-faces';
53
+ import CollectionFontVariant from './collection-font-variant';
39
54
 
40
55
  const DEFAULT_CATEGORY = {
41
56
  slug: 'all',
42
57
  name: _x( 'All', 'font categories' ),
43
58
  };
59
+
60
+ const LOCAL_STORAGE_ITEM = 'wp-font-library-google-fonts-permission';
61
+ const MIN_WINDOW_HEIGHT = 500;
62
+
44
63
  function FontCollection( { slug } ) {
45
64
  const requiresPermission = slug === 'google-fonts';
46
65
 
47
66
  const getGoogleFontsPermissionFromStorage = () => {
48
- return (
49
- window.localStorage.getItem(
50
- 'wp-font-library-google-fonts-permission'
51
- ) === 'true'
52
- );
67
+ return window.localStorage.getItem( LOCAL_STORAGE_ITEM ) === 'true';
53
68
  };
54
69
 
55
70
  const [ selectedFont, setSelectedFont ] = useState( null );
@@ -59,8 +74,14 @@ function FontCollection( { slug } ) {
59
74
  const [ renderConfirmDialog, setRenderConfirmDialog ] = useState(
60
75
  requiresPermission && ! getGoogleFontsPermissionFromStorage()
61
76
  );
62
- const { collections, getFontCollection, installFont, notice, setNotice } =
63
- useContext( FontLibraryContext );
77
+ const {
78
+ collections,
79
+ getFontCollection,
80
+ installFont,
81
+ isInstalling,
82
+ notice,
83
+ setNotice,
84
+ } = useContext( FontLibraryContext );
64
85
  const selectedCollection = collections.find(
65
86
  ( collection ) => collection.slug === slug
66
87
  );
@@ -76,6 +97,11 @@ function FontCollection( { slug } ) {
76
97
  return () => window.removeEventListener( 'storage', handleStorage );
77
98
  }, [ slug, requiresPermission ] );
78
99
 
100
+ const revokeAccess = () => {
101
+ window.localStorage.setItem( LOCAL_STORAGE_ITEM, 'false' );
102
+ window.dispatchEvent( new Event( 'storage' ) );
103
+ };
104
+
79
105
  useEffect( () => {
80
106
  const fetchFontCollection = async () => {
81
107
  try {
@@ -118,7 +144,8 @@ function FontCollection( { slug } ) {
118
144
 
119
145
  // NOTE: The height of the font library modal unavailable to use for rendering font family items is roughly 417px
120
146
  // The height of each font family item is 61px.
121
- const pageSize = Math.floor( ( window.innerHeight - 417 ) / 61 );
147
+ const windowHeight = Math.max( window.innerHeight, MIN_WINDOW_HEIGHT );
148
+ const pageSize = Math.floor( ( windowHeight - 417 ) / 61 );
122
149
  const totalPages = Math.ceil( fonts.length / pageSize );
123
150
  const itemsStart = ( page - 1 ) * pageSize;
124
151
  const itemsLimit = page * pageSize;
@@ -146,10 +173,6 @@ function FontCollection( { slug } ) {
146
173
  setPage( 1 );
147
174
  };
148
175
 
149
- const handleUnselectFont = () => {
150
- setSelectedFont( null );
151
- };
152
-
153
176
  const handleToggleVariant = ( font, face ) => {
154
177
  const newFontsToInstall = toggleFont( font, face, fontsToInstall );
155
178
  setFontsToInstall( newFontsToInstall );
@@ -205,212 +228,283 @@ function FontCollection( { slug } ) {
205
228
  resetFontsToInstall();
206
229
  };
207
230
 
208
- let footerComponent = null;
209
- if ( selectedFont ) {
210
- footerComponent = (
211
- <InstallFooter
212
- handleInstall={ handleInstall }
213
- isDisabled={ fontsToInstall.length === 0 }
214
- />
215
- );
216
- } else if ( ! renderConfirmDialog && totalPages > 1 ) {
217
- footerComponent = (
218
- <PaginationFooter
219
- page={ page }
220
- totalPages={ totalPages }
221
- setPage={ setPage }
231
+ const getSortedFontFaces = ( fontFamily ) => {
232
+ if ( ! fontFamily ) {
233
+ return [];
234
+ }
235
+ if ( ! fontFamily.fontFace || ! fontFamily.fontFace.length ) {
236
+ return [
237
+ {
238
+ fontFamily: fontFamily.fontFamily,
239
+ fontStyle: 'normal',
240
+ fontWeight: '400',
241
+ },
242
+ ];
243
+ }
244
+ return sortFontFaces( fontFamily.fontFace );
245
+ };
246
+
247
+ if ( renderConfirmDialog ) {
248
+ return <GoogleFontsConfirmDialog />;
249
+ }
250
+
251
+ const ActionsComponent = () => {
252
+ if ( slug !== 'google-fonts' || renderConfirmDialog || selectedFont ) {
253
+ return null;
254
+ }
255
+ return (
256
+ <DropdownMenu
257
+ icon={ moreVertical }
258
+ label={ __( 'Actions' ) }
259
+ popoverProps={ {
260
+ position: 'bottom left',
261
+ } }
262
+ controls={ [
263
+ {
264
+ title: __( 'Revoke access to Google Fonts' ),
265
+ onClick: revokeAccess,
266
+ },
267
+ ] }
222
268
  />
223
269
  );
224
- }
270
+ };
225
271
 
226
272
  return (
227
- <TabPanelLayout
228
- title={
229
- ! selectedFont ? selectedCollection.name : selectedFont.name
230
- }
231
- description={
232
- ! selectedFont
233
- ? selectedCollection.description
234
- : __( 'Select font variants to install.' )
235
- }
236
- notice={ notice }
237
- handleBack={ !! selectedFont && handleUnselectFont }
238
- footer={ footerComponent }
239
- >
240
- { renderConfirmDialog && (
241
- <>
242
- <Spacer margin={ 8 } />
243
- <GoogleFontsConfirmDialog />
244
- </>
245
- ) }
273
+ <div className="font-library-modal__tabpanel-layout">
274
+ <NavigatorProvider
275
+ initialPath="/"
276
+ className="font-library-modal__tabpanel-layout"
277
+ >
278
+ <NavigatorScreen path="/">
279
+ <HStack justify="space-between">
280
+ <Heading level={ 2 } size={ 13 }>
281
+ { selectedCollection.name }
282
+ </Heading>
283
+ <ActionsComponent />
284
+ </HStack>
285
+ <Text>{ selectedCollection.description }</Text>
286
+ <Spacer margin={ 4 } />
287
+ <Flex>
288
+ <FlexItem>
289
+ <InputControl
290
+ value={ filters.search }
291
+ placeholder={ __( 'Font name…' ) }
292
+ label={ __( 'Search' ) }
293
+ onChange={ debouncedUpdateSearchInput }
294
+ prefix={ <Icon icon={ search } /> }
295
+ suffix={
296
+ filters?.search ? (
297
+ <Icon
298
+ icon={ closeSmall }
299
+ onClick={ resetSearch }
300
+ />
301
+ ) : null
302
+ }
303
+ />
304
+ </FlexItem>
305
+ <FlexItem>
306
+ <SelectControl
307
+ label={ __( 'Category' ) }
308
+ value={ filters.category }
309
+ onChange={ handleCategoryFilter }
310
+ >
311
+ { categories &&
312
+ categories.map( ( category ) => (
313
+ <option
314
+ value={ category.slug }
315
+ key={ category.slug }
316
+ >
317
+ { category.name }
318
+ </option>
319
+ ) ) }
320
+ </SelectControl>
321
+ </FlexItem>
322
+ </Flex>
323
+
324
+ <Spacer margin={ 4 } />
325
+
326
+ { ! selectedCollection?.font_families && ! notice && (
327
+ <Spinner />
328
+ ) }
329
+
330
+ { !! selectedCollection?.font_families?.length &&
331
+ ! fonts.length && (
332
+ <Text>
333
+ { __(
334
+ 'No fonts found. Try with a different search term'
335
+ ) }
336
+ </Text>
337
+ ) }
246
338
 
247
- { ! renderConfirmDialog && ! selectedFont && (
248
- <Flex>
249
- <FlexItem>
250
- <InputControl
251
- value={ filters.search }
252
- placeholder={ __( 'Font name…' ) }
253
- label={ __( 'Search' ) }
254
- onChange={ debouncedUpdateSearchInput }
255
- prefix={ <Icon icon={ search } /> }
256
- suffix={
257
- filters?.search ? (
258
- <Icon
259
- icon={ closeSmall }
260
- onClick={ resetSearch }
261
- />
262
- ) : null
263
- }
339
+ <div className="font-library-modal__fonts-grid__main">
340
+ { items.map( ( font ) => (
341
+ <FontCard
342
+ key={ font.font_family_settings.slug }
343
+ font={ font.font_family_settings }
344
+ navigatorPath={ '/fontFamily' }
345
+ onClick={ () => {
346
+ setSelectedFont(
347
+ font.font_family_settings
348
+ );
349
+ } }
350
+ />
351
+ ) ) }
352
+ </div>
353
+ </NavigatorScreen>
354
+
355
+ <NavigatorScreen path="/fontFamily">
356
+ <Flex justify="flex-start">
357
+ <NavigatorToParentButton
358
+ icon={ chevronLeft }
359
+ isSmall
360
+ onClick={ () => {
361
+ setSelectedFont( null );
362
+ } }
363
+ aria-label={ __( 'Navigate to the previous view' ) }
264
364
  />
265
- </FlexItem>
266
- <FlexItem>
267
- <SelectControl
268
- label={ __( 'Category' ) }
269
- value={ filters.category }
270
- onChange={ handleCategoryFilter }
365
+ <Heading
366
+ level={ 2 }
367
+ size={ 13 }
368
+ className="edit-site-global-styles-header"
271
369
  >
272
- { categories &&
273
- categories.map( ( category ) => (
274
- <option
275
- value={ category.slug }
276
- key={ category.slug }
277
- >
278
- { category.name }
279
- </option>
280
- ) ) }
281
- </SelectControl>
282
- </FlexItem>
370
+ { selectedFont?.name }
371
+ </Heading>
372
+ </Flex>
373
+ { notice && (
374
+ <>
375
+ <Spacer margin={ 1 } />
376
+ <Notice
377
+ status={ notice.type }
378
+ onRemove={ () => setNotice( null ) }
379
+ >
380
+ { notice.message }
381
+ </Notice>
382
+ <Spacer margin={ 1 } />
383
+ </>
384
+ ) }
385
+ <Spacer margin={ 4 } />
386
+ <Text> { __( 'Select font variants to install.' ) } </Text>
387
+ <Spacer margin={ 4 } />
388
+ <VStack spacing={ 0 }>
389
+ <Spacer margin={ 8 } />
390
+ { getSortedFontFaces( selectedFont ).map(
391
+ ( face, i ) => (
392
+ <CollectionFontVariant
393
+ font={ selectedFont }
394
+ face={ face }
395
+ key={ `face${ i }` }
396
+ handleToggleVariant={ handleToggleVariant }
397
+ selected={ isFontFontFaceInOutline(
398
+ selectedFont.slug,
399
+ selectedFont.fontFace ? face : null, // If the font has no fontFace, we want to check if the font is in the outline
400
+ fontToInstallOutline
401
+ ) }
402
+ />
403
+ )
404
+ ) }
405
+ </VStack>
406
+ <Spacer margin={ 16 } />
407
+ </NavigatorScreen>
408
+ </NavigatorProvider>
409
+
410
+ { selectedFont && (
411
+ <Flex
412
+ justify="flex-end"
413
+ className="font-library-modal__tabpanel-layout__footer"
414
+ >
415
+ <Button
416
+ variant="primary"
417
+ onClick={ handleInstall }
418
+ isBusy={ isInstalling }
419
+ disabled={ fontsToInstall.length === 0 || isInstalling }
420
+ __experimentalIsFocusable
421
+ >
422
+ { __( 'Install' ) }
423
+ </Button>
283
424
  </Flex>
284
425
  ) }
285
426
 
286
- <Spacer margin={ 4 } />
287
- { ! renderConfirmDialog &&
288
- ! selectedCollection?.font_families &&
289
- ! notice && <Spinner /> }
290
-
291
- { ! renderConfirmDialog &&
292
- !! selectedCollection?.font_families?.length &&
293
- ! fonts.length && (
294
- <Text>
295
- { __(
296
- 'No fonts found. Try with a different search term'
427
+ { ! selectedFont && (
428
+ <Flex
429
+ justify="center"
430
+ className="font-library-modal__tabpanel-layout__footer"
431
+ >
432
+ <Button
433
+ label={ __( 'First page' ) }
434
+ size="compact"
435
+ onClick={ () => setPage( 1 ) }
436
+ disabled={ page === 1 }
437
+ __experimentalIsFocusable
438
+ >
439
+ <span>«</span>
440
+ </Button>
441
+ <Button
442
+ label={ __( 'Previous page' ) }
443
+ size="compact"
444
+ onClick={ () => setPage( page - 1 ) }
445
+ disabled={ page === 1 }
446
+ __experimentalIsFocusable
447
+ >
448
+ <span>‹</span>
449
+ </Button>
450
+ <HStack
451
+ justify="flex-start"
452
+ expanded={ false }
453
+ spacing={ 2 }
454
+ >
455
+ { createInterpolateElement(
456
+ sprintf(
457
+ // translators: %s: Total number of pages.
458
+ _x(
459
+ 'Page <CurrenPageControl /> of %s',
460
+ 'paging'
461
+ ),
462
+ totalPages
463
+ ),
464
+ {
465
+ CurrenPageControl: (
466
+ <SelectControl
467
+ aria-label={ __( 'Current page' ) }
468
+ value={ page }
469
+ options={ [
470
+ ...Array( totalPages ),
471
+ ].map( ( e, i ) => {
472
+ return {
473
+ label: i + 1,
474
+ value: i + 1,
475
+ };
476
+ } ) }
477
+ onChange={ ( newPage ) =>
478
+ setPage( parseInt( newPage ) )
479
+ }
480
+ size={ 'compact' }
481
+ __nextHasNoMarginBottom
482
+ />
483
+ ),
484
+ }
297
485
  ) }
298
- </Text>
299
- ) }
300
-
301
- { ! renderConfirmDialog && selectedFont && (
302
- <CollectionFontDetails
303
- font={ selectedFont }
304
- handleToggleVariant={ handleToggleVariant }
305
- fontToInstallOutline={ fontToInstallOutline }
306
- />
307
- ) }
308
-
309
- { ! renderConfirmDialog && ! selectedFont && (
310
- <div className="font-library-modal__fonts-grid__main">
311
- { items.map( ( font ) => (
312
- <FontCard
313
- key={ font.font_family_settings.slug }
314
- font={ font.font_family_settings }
315
- onClick={ () => {
316
- setSelectedFont( font.font_family_settings );
317
- } }
318
- />
319
- ) ) }
320
- </div>
486
+ </HStack>
487
+ <Button
488
+ label={ __( 'Next page' ) }
489
+ size="compact"
490
+ onClick={ () => setPage( page + 1 ) }
491
+ disabled={ page === totalPages }
492
+ __experimentalIsFocusable
493
+ >
494
+ <span>›</span>
495
+ </Button>
496
+ <Button
497
+ label={ __( 'Last page' ) }
498
+ size="compact"
499
+ onClick={ () => setPage( totalPages ) }
500
+ disabled={ page === totalPages }
501
+ __experimentalIsFocusable
502
+ >
503
+ <span>»</span>
504
+ </Button>
505
+ </Flex>
321
506
  ) }
322
- </TabPanelLayout>
323
- );
324
- }
325
-
326
- function PaginationFooter( { page, totalPages, setPage } ) {
327
- return (
328
- <Flex justify="center">
329
- <Button
330
- label={ __( 'First page' ) }
331
- size="compact"
332
- onClick={ () => setPage( 1 ) }
333
- disabled={ page === 1 }
334
- __experimentalIsFocusable
335
- >
336
- <span>«</span>
337
- </Button>
338
- <Button
339
- label={ __( 'Previous page' ) }
340
- size="compact"
341
- onClick={ () => setPage( page - 1 ) }
342
- disabled={ page === 1 }
343
- __experimentalIsFocusable
344
- >
345
- <span>‹</span>
346
- </Button>
347
- <HStack justify="flex-start" expanded={ false } spacing={ 2 }>
348
- { createInterpolateElement(
349
- sprintf(
350
- // translators: %s: Total number of pages.
351
- _x( 'Page <CurrenPageControl /> of %s', 'paging' ),
352
- totalPages
353
- ),
354
- {
355
- CurrenPageControl: (
356
- <SelectControl
357
- aria-label={ __( 'Current page' ) }
358
- value={ page }
359
- options={ [ ...Array( totalPages ) ].map(
360
- ( e, i ) => {
361
- return {
362
- label: i + 1,
363
- value: i + 1,
364
- };
365
- }
366
- ) }
367
- onChange={ ( newPage ) =>
368
- setPage( parseInt( newPage ) )
369
- }
370
- size={ 'compact' }
371
- __nextHasNoMarginBottom
372
- />
373
- ),
374
- }
375
- ) }
376
- </HStack>
377
- <Button
378
- label={ __( 'Next page' ) }
379
- size="compact"
380
- onClick={ () => setPage( page + 1 ) }
381
- disabled={ page === totalPages }
382
- __experimentalIsFocusable
383
- >
384
- <span>›</span>
385
- </Button>
386
- <Button
387
- label={ __( 'Last page' ) }
388
- size="compact"
389
- onClick={ () => setPage( totalPages ) }
390
- disabled={ page === totalPages }
391
- __experimentalIsFocusable
392
- >
393
- <span>»</span>
394
- </Button>
395
- </Flex>
396
- );
397
- }
398
-
399
- function InstallFooter( { handleInstall, isDisabled } ) {
400
- const { isInstalling } = useContext( FontLibraryContext );
401
-
402
- return (
403
- <Flex justify="flex-end">
404
- <Button
405
- variant="primary"
406
- onClick={ handleInstall }
407
- isBusy={ isInstalling }
408
- disabled={ isDisabled || isInstalling }
409
- __experimentalIsFocusable
410
- >
411
- { __( 'Install' ) }
412
- </Button>
413
- </Flex>
507
+ </div>
414
508
  );
415
509
  }
416
510
 
@@ -8,7 +8,10 @@ import { useContext, useEffect, useState, useRef } from '@wordpress/element';
8
8
  * Internal dependencies
9
9
  */
10
10
  import { FontLibraryContext } from './context';
11
- import { getFacePreviewStyle } from './utils/preview-styles';
11
+ import {
12
+ getFacePreviewStyle,
13
+ getFamilyPreviewStyle,
14
+ } from './utils/preview-styles';
12
15
 
13
16
  function getPreviewUrl( fontFace ) {
14
17
  if ( fontFace.preview ) {
@@ -19,8 +22,39 @@ function getPreviewUrl( fontFace ) {
19
22
  }
20
23
  }
21
24
 
22
- function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
25
+ function getDisplayFontFace( font ) {
26
+ // if this IS a font face return it
27
+ if ( font.fontStyle || font.fontWeight ) {
28
+ return font;
29
+ }
30
+ // if this is a font family with a collection of font faces
31
+ // return the first one that is normal and 400 OR just the first one
32
+ if ( font.fontFace && font.fontFace.length ) {
33
+ return (
34
+ font.fontFace.find(
35
+ ( face ) =>
36
+ face.fontStyle === 'normal' && face.fontWeight === '400'
37
+ ) || font.fontFace[ 0 ]
38
+ );
39
+ }
40
+ // This must be a font family with no font faces
41
+ // return a fake font face
42
+ return {
43
+ fontStyle: 'normal',
44
+ fontWeight: '400',
45
+ fontFamily: font.fontFamily,
46
+ fake: true,
47
+ };
48
+ }
49
+
50
+ function FontDemo( { font, text } ) {
23
51
  const ref = useRef( null );
52
+
53
+ const fontFace = getDisplayFontFace( font );
54
+ const style = getFamilyPreviewStyle( font );
55
+ text = text || font.name;
56
+ const customPreviewUrl = font.preview;
57
+
24
58
  const [ isIntersecting, setIsIntersecting ] = useState( false );
25
59
  const [ isAssetLoaded, setIsAssetLoaded ] = useState( false );
26
60
  const { loadFontFaceAsset } = useContext( FontLibraryContext );
@@ -34,8 +68,8 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
34
68
  fontSize: '18px',
35
69
  lineHeight: 1,
36
70
  opacity: isAssetLoaded ? '1' : '0',
37
- ...faceStyles,
38
71
  ...style,
72
+ ...faceStyles,
39
73
  };
40
74
 
41
75
  useEffect( () => {
@@ -79,4 +113,4 @@ function FontFaceDemo( { customPreviewUrl, fontFace, text, style = {} } ) {
79
113
  );
80
114
  }
81
115
 
82
- export default FontFaceDemo;
116
+ export default FontDemo;