/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/term-name/edit.js
87 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { __ } from '@wordpress/i18n'; import { useBlockProps, BlockControls, InspectorControls, HeadingLevelDropdown, } from '@wordpress/block-editor'; import { ToggleControl, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { decodeEntities } from '@wordpress/html-entities'; import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; import { useTermName } from './use-term-name'; export default function TermNameEdit( { attributes, setAttributes, context: { termId, taxonomy }, } ) { const { level = 0, isLink, levelOptions } = attributes; const { term } = useTermName( termId, taxonomy ); const termName = term?.name ? decodeEntities( term.name ) : __( 'Term Name' ); const blockProps = useBlockProps(); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const TagName = level === 0 ? 'p' : `h${ level }`; let termNameDisplay = termName; if ( isLink ) { termNameDisplay = ( <a href="#term-name-pseudo-link" onClick={ ( e ) => e.preventDefault() } > { termName } </a> ); } return ( <> <BlockControls group="block"> <HeadingLevelDropdown value={ level } options={ levelOptions } onChange={ ( newLevel ) => { setAttributes( { level: newLevel } ); } } /> </BlockControls> <InspectorControls> <ToolsPanel label={ __( 'Settings' ) } resetAll={ () => { setAttributes( { isLink: false, } ); } } dropdownMenuProps={ dropdownMenuProps } > <ToolsPanelItem hasValue={ () => !! isLink } label={ __( 'Make term name a link' ) } onDeselect={ () => setAttributes( { isLink: false } ) } isShownByDefault > <ToggleControl label={ __( 'Make term name a link' ) } onChange={ () => setAttributes( { isLink: ! isLink } ) } checked={ isLink } /> </ToolsPanelItem> </ToolsPanel> </InspectorControls> <TagName { ...blockProps }>{ termNameDisplay }</TagName> </> ); }