UNPKG

@wordpress/block-editor

Version:
54 lines (48 loc) 962 B
/** * External dependencies */ import { isEmpty } from 'lodash'; /** * WordPress dependencies */ import { SelectControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import useEditorFeature from '../use-editor-feature'; export default function FontFamilyControl( { value = '', onChange, fontFamilies, ...props } ) { const blockLevelFontFamilies = useEditorFeature( 'typography.fontFamilies' ); if ( ! fontFamilies ) { fontFamilies = blockLevelFontFamilies; } if ( isEmpty( fontFamilies ) ) { return null; } const options = [ { value: '', label: __( 'Default' ) }, ...fontFamilies.map( ( { fontFamily, name } ) => { return { value: fontFamily, label: name || fontFamily, }; } ), ]; return ( <SelectControl label={ __( 'Font family' ) } options={ options } value={ value } onChange={ onChange } labelPosition="top" { ...props } /> ); }