@wordpress/block-library
Version:
Block library for the WordPress editor.
62 lines (54 loc) • 2.03 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useBlockProps, useInnerBlocksProps, store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { name as buttonBlockName } from '../button';
const ALLOWED_BLOCKS = [buttonBlockName];
const DEFAULT_BLOCK = {
name: buttonBlockName,
attributesToCopy: ['backgroundColor', 'border', 'className', 'fontFamily', 'fontSize', 'gradient', 'style', 'textColor', 'width']
};
function ButtonsEdit(_ref) {
var _style$typography;
let {
attributes,
className
} = _ref;
const {
fontSize,
layout = {},
style
} = attributes;
const blockProps = useBlockProps({
className: classnames(className, {
'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)
})
});
const preferredStyle = useSelect(select => {
var _preferredStyleVariat;
const preferredStyleVariations = select(blockEditorStore).getSettings().__experimentalPreferredStyleVariations;
return preferredStyleVariations === null || preferredStyleVariations === void 0 ? void 0 : (_preferredStyleVariat = preferredStyleVariations.value) === null || _preferredStyleVariat === void 0 ? void 0 : _preferredStyleVariat[buttonBlockName];
}, []);
const innerBlocksProps = useInnerBlocksProps(blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
__experimentalDefaultBlock: DEFAULT_BLOCK,
__experimentalDirectInsert: true,
template: [[buttonBlockName, {
className: preferredStyle && `is-style-${preferredStyle}`
}]],
__experimentalLayout: layout,
templateInsertUpdatesSelection: true
});
return createElement("div", innerBlocksProps);
}
export default ButtonsEdit;
//# sourceMappingURL=edit.js.map