UNPKG

@wordpress/block-editor

Version:
84 lines (67 loc) 2.23 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.LineHeightEdit = LineHeightEdit; exports.useIsLineHeightDisabled = useIsLineHeightDisabled; exports.LINE_HEIGHT_SUPPORT_KEY = void 0; var _element = require("@wordpress/element"); var _blocks = require("@wordpress/blocks"); var _lineHeightControl = _interopRequireDefault(require("../components/line-height-control")); var _utils = require("./utils"); var _useEditorFeature = _interopRequireDefault(require("../components/use-editor-feature")); /** * WordPress dependencies */ /** * Internal dependencies */ const LINE_HEIGHT_SUPPORT_KEY = 'lineHeight'; /** * Inspector control panel containing the line height related configuration * * @param {Object} props * * @return {WPElement} Line height edit element. */ exports.LINE_HEIGHT_SUPPORT_KEY = LINE_HEIGHT_SUPPORT_KEY; function LineHeightEdit(props) { var _style$typography; const { attributes: { style } } = props; const isDisabled = useIsLineHeightDisabled(props); if (isDisabled) { return null; } const onChange = newLineHeightValue => { const newStyle = { ...style, typography: { ...(style === null || style === void 0 ? void 0 : style.typography), lineHeight: newLineHeightValue } }; props.setAttributes({ style: (0, _utils.cleanEmptyObject)(newStyle) }); }; return (0, _element.createElement)(_lineHeightControl.default, { value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.lineHeight, onChange: onChange }); } /** * 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 isDisabled = !(0, _useEditorFeature.default)('typography.customLineHeight'); return !(0, _blocks.hasBlockSupport)(blockName, LINE_HEIGHT_SUPPORT_KEY) || isDisabled; } //# sourceMappingURL=line-height.js.map