UNPKG

@wordpress/block-editor

Version:
81 lines (66 loc) 2.02 kB
"use strict"; 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 _element = require("@wordpress/element"); var _blocks = require("@wordpress/blocks"); var _lineHeightControl = _interopRequireDefault(require("../components/line-height-control")); var _utils = require("./utils"); var _useSetting = _interopRequireDefault(require("../components/use-setting")); /** * WordPress dependencies */ /** * Internal dependencies */ const LINE_HEIGHT_SUPPORT_KEY = 'typography.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) { const { attributes: { style }, setAttributes } = props; const onChange = newLineHeightValue => { const newStyle = { ...style, typography: { ...style?.typography, lineHeight: newLineHeightValue } }; setAttributes({ style: (0, _utils.cleanEmptyObject)(newStyle) }); }; return (0, _element.createElement)(_lineHeightControl.default, { __unstableInputWidth: "100%", __nextHasNoMarginBottom: true, 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 isDisabled = !(0, _useSetting.default)('typography.lineHeight'); return !(0, _blocks.hasBlockSupport)(blockName, LINE_HEIGHT_SUPPORT_KEY) || isDisabled; } //# sourceMappingURL=line-height.js.map