@wordpress/block-editor
Version:
71 lines (62 loc) • 2.02 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { hasBlockSupport } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import TextDecorationControl from '../components/text-decoration-control';
import useEditorFeature from '../components/use-editor-feature';
import { cleanEmptyObject } from './utils';
/**
* Key within block settings' supports array indicating support for text
* decorations e.g. settings found in `block.json`.
*/
export const TEXT_DECORATION_SUPPORT_KEY = '__experimentalTextDecoration';
/**
* Inspector control panel containing the text decoration options.
*
* @param {Object} props Block properties.
* @return {WPElement} Text decoration edit element.
*/
export function TextDecorationEdit(props) {
var _style$typography;
const {
attributes: {
style
},
setAttributes
} = props;
const isDisabled = useIsTextDecorationDisabled(props);
if (isDisabled) {
return null;
}
function onChange(newDecoration) {
setAttributes({
style: cleanEmptyObject({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
textDecoration: newDecoration
}
})
});
}
return createElement(TextDecorationControl, {
value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.textDecoration,
onChange: onChange
});
}
/**
* Checks if text-decoration settings have been disabled.
*
* @param {string} name Name of the block.
* @return {boolean} Whether or not the setting is disabled.
*/
export function useIsTextDecorationDisabled({
name: blockName
} = {}) {
const notSupported = !hasBlockSupport(blockName, TEXT_DECORATION_SUPPORT_KEY);
const hasTextDecoration = useEditorFeature('typography.customTextDecorations');
return notSupported || !hasTextDecoration;
}
//# sourceMappingURL=text-decoration.js.map