@wordpress/block-library
Version:
Block library for the WordPress editor.
53 lines (52 loc) • 1.64 kB
JavaScript
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';
import { jsx as _jsx } from "react/jsx-runtime";
const DEFAULT_BLOCK = {
name: 'core/button',
attributesToCopy: ['backgroundColor', 'border', 'className', 'fontFamily', 'fontSize', 'gradient', 'style', 'textColor', 'width']
};
function ButtonsEdit({
attributes,
className
}) {
var _layout$orientation;
const {
fontSize,
layout,
style
} = attributes;
const blockProps = useBlockProps({
className: clsx(className, {
'has-custom-font-size': fontSize || style?.typography?.fontSize
})
});
const {
hasButtonVariations
} = useSelect(select => {
const buttonVariations = select(blocksStore).getBlockVariations('core/button', 'inserter');
return {
hasButtonVariations: buttonVariations.length > 0
};
}, []);
const innerBlocksProps = useInnerBlocksProps(blockProps, {
defaultBlock: DEFAULT_BLOCK,
// This check should be handled by the `Inserter` internally to be consistent across all blocks that use it.
directInsert: !hasButtonVariations,
template: [['core/button']],
templateInsertUpdatesSelection: true,
orientation: (_layout$orientation = layout?.orientation) !== null && _layout$orientation !== void 0 ? _layout$orientation : 'horizontal'
});
return /*#__PURE__*/_jsx("div", {
...innerBlocksProps
});
}
export default ButtonsEdit;
//# sourceMappingURL=edit.js.map