@wordpress/block-editor
Version:
71 lines (66 loc) • 1.95 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LINE_HEIGHT_SUPPORT_KEY = void 0;
exports.LineHeightEdit = LineHeightEdit;
exports.useIsLineHeightDisabled = useIsLineHeightDisabled;
var _blocks = require("@wordpress/blocks");
var _lineHeightControl = _interopRequireDefault(require("../components/line-height-control"));
var _utils = require("./utils");
var _useSettings = require("../components/use-settings");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const LINE_HEIGHT_SUPPORT_KEY = exports.LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
/**
* Inspector control panel containing the line height related configuration
*
* @param {Object} props
*
* @return {Element} Line height edit element.
*/
function LineHeightEdit(props) {
const {
attributes: {
style
},
setAttributes
} = props;
const onChange = newLineHeightValue => {
const newStyle = {
...style,
typography: {
...style?.typography,
lineHeight: newLineHeightValue
}
};
setAttributes({
style: (0, _utils.cleanEmptyObject)(newStyle)
});
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lineHeightControl.default, {
__unstableInputWidth: "100%",
value: style?.typography?.lineHeight,
onChange: onChange,
size: "__unstable-large"
});
}
/**
* Custom hook that checks if line-height settings have been disabled.
*
* @param {string} name The name of the block.
* @return {boolean} Whether setting is disabled.
*/
function useIsLineHeightDisabled({
name: blockName
} = {}) {
const [isEnabled] = (0, _useSettings.useSettings)('typography.lineHeight');
return !isEnabled || !(0, _blocks.hasBlockSupport)(blockName, LINE_HEIGHT_SUPPORT_KEY);
}
//# sourceMappingURL=line-height.js.map
;