@wordpress/block-editor
Version:
61 lines (58 loc) • 1.56 kB
JavaScript
/**
* WordPress dependencies
*/
import { hasBlockSupport } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import LineHeightControl from '../components/line-height-control';
import { cleanEmptyObject } from './utils';
import { useSettings } from '../components/use-settings';
import { jsx as _jsx } from "react/jsx-runtime";
export const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
/**
* Inspector control panel containing the line height related configuration
*
* @param {Object} props
*
* @return {Element} Line height edit element.
*/
export function LineHeightEdit(props) {
const {
attributes: {
style
},
setAttributes
} = props;
const onChange = newLineHeightValue => {
const newStyle = {
...style,
typography: {
...style?.typography,
lineHeight: newLineHeightValue
}
};
setAttributes({
style: cleanEmptyObject(newStyle)
});
};
return /*#__PURE__*/_jsx(LineHeightControl, {
__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.
*/
export function useIsLineHeightDisabled({
name: blockName
} = {}) {
const [isEnabled] = useSettings('typography.lineHeight');
return !isEnabled || !hasBlockSupport(blockName, LINE_HEIGHT_SUPPORT_KEY);
}
//# sourceMappingURL=line-height.js.map