UNPKG

@wordpress/block-editor

Version:
66 lines (58 loc) 1.78 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { hasBlockSupport } from '@wordpress/blocks'; /** * Internal dependencies */ import LineHeightControl from '../components/line-height-control'; import { cleanEmptyObject } from './utils'; import useEditorFeature from '../components/use-editor-feature'; export const LINE_HEIGHT_SUPPORT_KEY = 'lineHeight'; /** * Inspector control panel containing the line height related configuration * * @param {Object} props * * @return {WPElement} Line height edit element. */ export 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: cleanEmptyObject(newStyle) }); }; return createElement(LineHeightControl, { 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. */ export function useIsLineHeightDisabled({ name: blockName } = {}) { const isDisabled = !useEditorFeature('typography.customLineHeight'); return !hasBlockSupport(blockName, LINE_HEIGHT_SUPPORT_KEY) || isDisabled; } //# sourceMappingURL=line-height.js.map