@wordpress/block-library
Version:
Block library for the WordPress editor.
66 lines (60 loc) • 2.35 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps, __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles, __experimentalGetElementClassName } from '@wordpress/block-editor';
export default function save(_ref) {
var _style$border, _style$typography;
let {
attributes,
className
} = _ref;
const {
fontSize,
linkTarget,
rel,
style,
text,
title,
url,
width
} = attributes;
if (!text) {
return null;
}
const borderProps = getBorderClassesAndStyles(attributes);
const colorProps = getColorClassesAndStyles(attributes);
const spacingProps = getSpacingClassesAndStyles(attributes);
const buttonClasses = classnames('wp-block-button__link', colorProps.className, borderProps.className, {
// For backwards compatibility add style that isn't provided via
// block support.
'no-border-radius': (style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border.radius) === 0
}, __experimentalGetElementClassName('button'));
const buttonStyle = { ...borderProps.style,
...colorProps.style,
...spacingProps.style
}; // 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.
const wrapperClasses = classnames(className, {
[`has-custom-width wp-block-button__width-${width}`]: width,
[`has-custom-font-size`]: fontSize || (style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.fontSize)
});
return createElement("div", useBlockProps.save({
className: wrapperClasses
}), createElement(RichText.Content, {
tagName: "a",
className: buttonClasses,
href: url,
title: title,
style: buttonStyle,
value: text,
target: linkTarget,
rel: rel
}));
}
//# sourceMappingURL=save.js.map