@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
57 lines (54 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = ThemeSupportCheck;
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Checks if the current theme supports specific features and renders the children if supported.
*
* @param {Object} props The component props.
* @param {Element} props.children The children to render if the theme supports the specified features.
* @param {string|string[]} props.supportKeys The key(s) of the theme support(s) to check.
*
* @return {JSX.Element|null} The rendered children if the theme supports the specified features, otherwise null.
*/
function ThemeSupportCheck({
children,
supportKeys
}) {
const {
postType,
themeSupports
} = (0, _data.useSelect)(select => {
return {
postType: select(_store.store).getEditedPostAttribute('type'),
themeSupports: select(_coreData.store).getThemeSupports()
};
}, []);
const isSupported = (Array.isArray(supportKeys) ? supportKeys : [supportKeys]).some(key => {
var _themeSupports$key;
const supported = (_themeSupports$key = themeSupports?.[key]) !== null && _themeSupports$key !== void 0 ? _themeSupports$key : false;
// 'post-thumbnails' can be boolean or an array of post types.
// In the latter case, we need to verify `postType` exists
// within `supported`. If `postType` isn't passed, then the check
// should fail.
if ('post-thumbnails' === key && Array.isArray(supported)) {
return supported.includes(postType);
}
return supported;
});
if (!isSupported) {
return null;
}
return children;
}
//# sourceMappingURL=index.js.map