@wordpress/block-editor
Version:
105 lines (82 loc) • 2.81 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SpacingPanel = SpacingPanel;
exports.hasSpacingSupport = hasSpacingSupport;
exports.useCustomSides = useCustomSides;
exports.SPACING_SUPPORT_KEY = void 0;
var _element = require("@wordpress/element");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _blocks = require("@wordpress/blocks");
var _inspectorControls = _interopRequireDefault(require("../components/inspector-controls"));
var _padding = require("./padding");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const SPACING_SUPPORT_KEY = 'spacing';
/**
* Inspector controls for spacing support.
*
* @param {Object} props Block props.
* @return {WPElement} Inspector controls for spacing support features.
*/
exports.SPACING_SUPPORT_KEY = SPACING_SUPPORT_KEY;
function SpacingPanel(props) {
const isDisabled = useIsSpacingDisabled(props);
const isSupported = hasSpacingSupport(props.name);
if (isDisabled || !isSupported) {
return null;
}
return (0, _element.createElement)(_inspectorControls.default, {
key: "spacing"
}, (0, _element.createElement)(_components.PanelBody, {
title: (0, _i18n.__)('Spacing')
}, (0, _element.createElement)(_padding.PaddingEdit, props)));
}
/**
* Determine whether there is block support for padding.
*
* @param {string} blockName Block name.
* @return {boolean} Whether there is support.
*/
function hasSpacingSupport(blockName) {
if (_element.Platform.OS !== 'web') {
return false;
}
return (0, _padding.hasPaddingSupport)(blockName);
}
/**
* Determines whether spacing support has been disabled.
*
* @param {Object} props Block properties.
* @return {boolean} If spacing support is completely disabled.
*/
const useIsSpacingDisabled = (props = {}) => {
const paddingDisabled = (0, _padding.useIsPaddingDisabled)(props);
return paddingDisabled;
};
/**
* Custom hook to retrieve which padding/margin is supported
* e.g. top, right, bottom or left.
*
* Sides are opted into by default. It is only if a specific side is set to
* false that it is omitted.
*
* @param {string} blockName Block name.
* @param {string} feature The feature custom sides relate to e.g. padding or margins.
* @return {Object} Sides supporting custom margin.
*/
function useCustomSides(blockName, feature) {
const support = (0, _blocks.getBlockSupport)(blockName, SPACING_SUPPORT_KEY); // Skip when setting is boolean as theme isn't setting arbitrary sides.
if (typeof support[feature] === 'boolean') {
return;
}
return support[feature];
}
//# sourceMappingURL=spacing.js.map