/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/button/index.js
80 строк
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 { button as icon } from '@wordpress/icons'; import { privateApis as blocksPrivateApis } from '@wordpress/blocks'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; import save from './save'; import { unlock } from '../lock-unlock'; const { fieldsKey, formKey } = unlock( blocksPrivateApis ); const { name } = metadata; export { metadata, name }; export const settings = { icon, example: { attributes: { className: 'is-style-fill', text: __( 'Call to action' ), }, }, edit, save, deprecated, merge: ( a, { text = '' } ) => ( { ...a, text: ( a.text || '' ) + text, } ), __experimentalLabel( attributes, { context } ) { const { text } = attributes; const customName = attributes?.metadata?.name; const hasContent = text?.trim().length > 0; // In the list view, use the block's text as the label. // If the text is empty, fall back to the default label. if ( context === 'list-view' && ( customName || hasContent ) ) { return customName || text; } if ( context === 'breadcrumb' && customName ) { return customName; } }, }; if ( window.__experimentalContentOnlyInspectorFields ) { settings[ fieldsKey ] = [ { id: 'text', label: __( 'Content' ), type: 'text', Edit: 'rich-text', // TODO: replace with custom component }, { id: 'link', label: __( 'Link' ), type: 'url', Edit: 'link', // TODO: replace with custom component getValue: ( { item } ) => ( { url: item.url, rel: item.rel, linkTarget: item.linkTarget, } ), setValue: ( { value } ) => ( { url: value.url, rel: value.rel, linkTarget: value.linkTarget, } ), }, ]; settings[ formKey ] = { fields: [ 'text', 'link' ], }; } export const init = () => initBlock( { name, metadata, settings } );