/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/button/save.js
74 строки
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import clsx from 'clsx'; import { RichText, useBlockProps, __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles, __experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles, __experimentalGetElementClassName, getTypographyClassesAndStyles, } from '@wordpress/block-editor'; export default function save( { attributes } ) { const { tagName, type, fontSize, linkTarget, rel, style, text, title, url, } = attributes; const TagName = tagName || 'a'; const isButtonTag = 'button' === TagName; const buttonType = type || 'button'; const borderProps = getBorderClassesAndStyles( attributes ); const colorProps = getColorClassesAndStyles( attributes ); const spacingProps = getSpacingClassesAndStyles( attributes ); const shadowProps = getShadowClassesAndStyles( attributes ); const typographyProps = getTypographyClassesAndStyles( attributes ); const buttonClasses = clsx( 'wp-block-button__link', colorProps.className, borderProps.className, typographyProps.className, { // For backwards compatibility add style that isn't provided via // block support. 'no-border-radius': style?.border?.radius === 0, [ `has-custom-font-size` ]: fontSize || style?.typography?.fontSize, }, __experimentalGetElementClassName( 'button' ) ); const buttonStyle = { ...borderProps.style, ...colorProps.style, ...spacingProps.style, ...shadowProps.style, ...typographyProps.style, writingMode: undefined, }; // The use of a `title` attribute here is soft-deprecated, but still applied // if it had already been assigned, for the sake of backward-compatibility. // A title will no longer be assigned for new or updated button block links. return ( <div { ...useBlockProps.save() }> <RichText.Content tagName={ TagName } type={ isButtonTag ? buttonType : null } className={ buttonClasses } href={ isButtonTag ? null : url } title={ title } style={ buttonStyle } value={ text } target={ isButtonTag ? null : linkTarget } rel={ isButtonTag ? null : rel } /> </div> ); }