@wordpress/block-library
Version:
Block library for the WordPress editor.
66 lines (64 loc) • 1.73 kB
JavaScript
import { createElement, Fragment } from "@wordpress/element";
/**
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps, __experimentalGetElementClassName, __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles } from '@wordpress/block-editor';
export default function save(_ref) {
let {
attributes
} = _ref;
const {
url,
alt,
caption,
align,
href,
rel,
linkClass,
width,
height,
id,
linkTarget,
sizeSlug,
title
} = attributes;
const newRel = isEmpty(rel) ? undefined : rel;
const borderProps = getBorderClassesAndStyles(attributes);
const classes = classnames({
[`align${align}`]: align,
[`size-${sizeSlug}`]: sizeSlug,
'is-resized': width || height,
'has-custom-border': !!borderProps.className || !isEmpty(borderProps.style)
});
const imageClasses = classnames(borderProps.className, {
[`wp-image-${id}`]: !!id
});
const image = createElement("img", {
src: url,
alt: alt,
className: imageClasses || undefined,
style: borderProps.style,
width: width,
height: height,
title: title
});
const figure = createElement(Fragment, null, href ? createElement("a", {
className: linkClass,
href: href,
target: linkTarget,
rel: newRel
}, image) : image, !RichText.isEmpty(caption) && createElement(RichText.Content, {
className: __experimentalGetElementClassName('caption'),
tagName: "figcaption",
value: caption
}));
return createElement("figure", useBlockProps.save({
className: classes
}), figure);
}
//# sourceMappingURL=save.js.map