UNPKG

@wordpress/block-editor

Version:
47 lines (42 loc) 885 B
/** * WordPress dependencies */ import { SelectControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import useSetting from '../use-setting'; export default function FontFamilyControl( { value = '', onChange, fontFamilies, ...props } ) { const blockLevelFontFamilies = useSetting( 'typography.fontFamilies' ); if ( ! fontFamilies ) { fontFamilies = blockLevelFontFamilies; } if ( ! fontFamilies || fontFamilies.length === 0 ) { return null; } const options = [ { value: '', label: __( 'Default' ) }, ...fontFamilies.map( ( { fontFamily, name } ) => { return { value: fontFamily, label: name || fontFamily, }; } ), ]; return ( <SelectControl label={ __( 'Font' ) } options={ options } value={ value } onChange={ onChange } labelPosition="top" { ...props } /> ); }