/** * Font Library — fonts a site owner has explicitly added, either picked from * the curated Google Fonts catalog or uploaded as a custom file. Nothing is * bulk-loaded: the table starts empty and only ever gains rows through the * "Add Font" modal. Only fonts listed here (plus system stacks) are offered * in the Font Pairings dropdowns above (see * Aureon\Modules\Font_Pairings\Font_Pairings::font_choices()). */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { CaseSensitive, FolderOpen } from '../../icons'; import AddFontModal from './add-font-modal'; import FontLibraryRow from './font-library-row'; import type { FontLibraryEntry, FontLibrarySchema, FontLibrarySettings, SetPath, } from '../../types'; interface FontLibrarySectionProps { schema?: FontLibrarySchema; value: FontLibrarySettings; setPath: SetPath; } export default function FontLibrarySection( { schema, value, setPath, }: FontLibrarySectionProps ) { const [ addingFont, setAddingFont ] = useState( false ); if ( ! schema ) { return null; } const items = value?.items ?? []; const atMax = items.length >= schema.maxFonts; // Fonts only ever load from this site, so adding one needs a companion // plugin that can store the files (Google download or custom upload). const canAddFonts = Boolean( schema.selfHostEnabled || schema.customUploadsAllowed ); const writeItems = ( next: FontLibraryEntry[] ) => setPath( `${ schema.path }.items`, next ); const addFont = ( entry: FontLibraryEntry ) => { writeItems( [ ...items, entry ] ); setAddingFont( false ); }; const updateFont = ( id: string, patch: FontLibraryEntry ) => writeItems( items.map( ( item ) => ( item.id === id ? patch : item ) ) ); const deleteFont = ( id: string ) => writeItems( items.filter( ( item ) => item.id !== id ) ); const existingSlugs = items .filter( ( item ) => 'google' === item.source && item.slug ) .map( ( item ) => item.slug as string ); const addFontButton = ( ); return (

{ __( 'Font Library', 'aureon' ) }

{ __( 'Manage the fonts you’ve added to your library.', 'aureon' ) }

{ canAddFonts && items.length > 0 && addFontButton }
{ 0 === items.length ? (

{ __( 'No fonts added yet', 'aureon' ) }

{ canAddFonts ? __( 'Add fonts here to use them in your typography settings. They are served from your own site.', 'aureon' ) : __( 'Your typography settings use system and bundled fonts. Adding more fonts needs a plugin that can store the files on your site.', 'aureon' ) }

{ canAddFonts && addFontButton }
) : ( { items.map( ( item ) => ( updateFont( item.id, next ) } onDelete={ () => deleteFont( item.id ) } /> ) ) }
{ __( 'Font Family', 'aureon' ) } { __( 'Source', 'aureon' ) } { __( 'Styles', 'aureon' ) } { __( 'Status', 'aureon' ) } { __( 'Added On', 'aureon' ) } { __( 'Actions', 'aureon' ) }
) } { atMax && (

{ __( 'You’ve reached the maximum number of library fonts.', 'aureon' ) }

) } { addingFont && ( setAddingFont( false ) } /> ) }
); }