/** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { __experimentalText as WCText, __experimentalItemGroup as ItemGroup, __experimentalVStack as VStack, __experimentalHStack as HStack, Button, } from '@wordpress/components'; import { settings } from '@wordpress/icons'; import { useContext } from '@wordpress/element'; /** * Internal dependencies */ import { Subtitle } from './subtitle'; import { useSetting } from './hooks'; import FontLibraryProvider, { FontLibraryContext, } from './font-library/context'; import FontLibraryModal from './font-library/modal'; import FontFamilyItem from './font-family-item'; import { setUIValuesNeeded } from './font-library/utils'; /** * Maps the fonts with the source, if available. * * @param {Array} fonts The fonts to map. * @param {string} source The source of the fonts. * @return {Array} The mapped fonts. */ function mapFontsWithSource( fonts: any[], source: string ) { return fonts ? fonts.map( ( f ) => setUIValuesNeeded( f, { source } ) ) : []; } function FontFamiliesInner() { const { baseCustomFonts, modalTabOpen, setModalTabOpen } = useContext( FontLibraryContext ); const [ fontFamilies ] = useSetting( 'typography.fontFamilies' ); const [ baseFontFamilies ] = useSetting( 'typography.fontFamilies', undefined, 'base' ); const themeFonts = mapFontsWithSource( fontFamilies?.theme, 'theme' ); const customFonts = mapFontsWithSource( fontFamilies?.custom, 'custom' ); const activeFonts = [ ...themeFonts, ...customFonts ].sort( ( a, b ) => a.name.localeCompare( b.name ) ); const hasFonts = 0 < activeFonts.length; const hasInstalledFonts = hasFonts || baseFontFamilies?.theme?.length > 0 || ( baseCustomFonts?.length ?? 0 ) > 0; return ( <> { !! modalTabOpen && ( setModalTabOpen?.( '' ) } defaultTabId={ modalTabOpen } /> ) } { __( 'Fonts' ) } ) } ); } export default function FontFamilies( { ...props } ) { return ( ); }