UNPKG

@gechiui/block-editor

Version:
65 lines (55 loc) 1.49 kB
/** * GeChiUI dependencies */ import { hasBlockSupport } from '@gechiui/blocks'; /** * External dependencies */ import { PanelBody } from '@gechiui/components'; import { __ } from '@gechiui/i18n'; /** * Internal dependencies */ import InspectorControls from '../components/inspector-controls'; import { LINE_HEIGHT_SUPPORT_KEY, LineHeightEdit, useIsLineHeightDisabled, } from './line-height'; import { FONT_SIZE_SUPPORT_KEY, FontSizeEdit, useIsFontSizeDisabled, } from './font-size'; export const TYPOGRAPHY_SUPPORT_KEY = 'typography'; export const TYPOGRAPHY_SUPPORT_KEYS = [ LINE_HEIGHT_SUPPORT_KEY, FONT_SIZE_SUPPORT_KEY, ]; export function TypographyPanel( props ) { const isDisabled = useIsTypographyDisabled( props ); const isSupported = hasTypographySupport( props.name ); // only enable TypographyPanel for development // eslint-disable-next-line no-undef if ( isDisabled || ! isSupported || ! __DEV__ ) return null; return ( <InspectorControls> <PanelBody title={ __( '排版' ) }> <FontSizeEdit { ...props } /> <LineHeightEdit { ...props } /> </PanelBody> </InspectorControls> ); } const hasTypographySupport = ( blockName ) => { return TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) => hasBlockSupport( blockName, key ) ); }; function useIsTypographyDisabled( props = {} ) { const configs = [ useIsFontSizeDisabled( props ), useIsLineHeightDisabled( props ), ]; return configs.filter( Boolean ).length === configs.length; }