@wordpress/edit-post
Version:
Edit Post module for WordPress.
70 lines (63 loc) • 1.71 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
import { get, partial } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import { PostFeaturedImage, PostFeaturedImageCheck } from '@wordpress/editor';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
/**
* Module Constants
*/
const PANEL_NAME = 'featured-image';
function FeaturedImage({
isEnabled,
isOpened,
postType,
onTogglePanel
}) {
if (!isEnabled) {
return null;
}
return createElement(PostFeaturedImageCheck, null, createElement(PanelBody, {
title: get(postType, ['labels', 'featured_image'], __('Featured image')),
opened: isOpened,
onToggle: onTogglePanel
}, createElement(PostFeaturedImage, null)));
}
const applyWithSelect = withSelect(select => {
const {
getEditedPostAttribute
} = select('core/editor');
const {
getPostType
} = select('core');
const {
isEditorPanelEnabled,
isEditorPanelOpened
} = select(editPostStore);
return {
postType: getPostType(getEditedPostAttribute('type')),
isEnabled: isEditorPanelEnabled(PANEL_NAME),
isOpened: isEditorPanelOpened(PANEL_NAME)
};
});
const applyWithDispatch = withDispatch(dispatch => {
const {
toggleEditorPanelOpened
} = dispatch(editPostStore);
return {
onTogglePanel: partial(toggleEditorPanelOpened, PANEL_NAME)
};
});
export default compose(applyWithSelect, applyWithDispatch)(FeaturedImage);
//# sourceMappingURL=index.js.map