@wordpress/block-editor
Version:
89 lines (71 loc) • 2.47 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TextTransformEdit = TextTransformEdit;
exports.useIsTextTransformDisabled = useIsTextTransformDisabled;
exports.TEXT_TRANSFORM_SUPPORT_KEY = void 0;
var _element = require("@wordpress/element");
var _blocks = require("@wordpress/blocks");
var _textTransformControl = _interopRequireDefault(require("../components/text-transform-control"));
var _useEditorFeature = _interopRequireDefault(require("../components/use-editor-feature"));
var _utils = require("./utils");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Key within block settings' supports array indicating support for text
* transforms e.g. settings found in `block.json`.
*/
const TEXT_TRANSFORM_SUPPORT_KEY = '__experimentalTextTransform';
/**
* Inspector control panel containing the text transform options.
*
* @param {Object} props Block properties.
* @return {WPElement} Text transform edit element.
*/
exports.TEXT_TRANSFORM_SUPPORT_KEY = TEXT_TRANSFORM_SUPPORT_KEY;
function TextTransformEdit(props) {
var _style$typography;
const {
attributes: {
style
},
setAttributes
} = props;
const isDisabled = useIsTextTransformDisabled(props);
if (isDisabled) {
return null;
}
function onChange(newTransform) {
setAttributes({
style: (0, _utils.cleanEmptyObject)({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
textTransform: newTransform
}
})
});
}
return (0, _element.createElement)(_textTransformControl.default, {
value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.textTransform,
onChange: onChange
});
}
/**
* Checks if text-transform settings have been disabled.
*
* @param {string} name Name of the block.
* @return {boolean} Whether or not the setting is disabled.
*/
function useIsTextTransformDisabled({
name: blockName
} = {}) {
const notSupported = !(0, _blocks.hasBlockSupport)(blockName, TEXT_TRANSFORM_SUPPORT_KEY);
const hasTextTransforms = (0, _useEditorFeature.default)('typography.customTextTransforms');
return notSupported || !hasTextTransforms;
}
//# sourceMappingURL=text-transform.js.map