UNPKG

@wordpress/edit-post

Version:
65 lines (54 loc) 1.9 kB
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'; /** * Module Constants */ var PANEL_NAME = 'featured-image'; function FeaturedImage(_ref) { var isEnabled = _ref.isEnabled, isOpened = _ref.isOpened, postType = _ref.postType, onTogglePanel = _ref.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))); } var applyWithSelect = withSelect(function (select) { var _select = select('core/editor'), getEditedPostAttribute = _select.getEditedPostAttribute; var _select2 = select('core'), getPostType = _select2.getPostType; var _select3 = select('core/edit-post'), isEditorPanelEnabled = _select3.isEditorPanelEnabled, isEditorPanelOpened = _select3.isEditorPanelOpened; return { postType: getPostType(getEditedPostAttribute('type')), isEnabled: isEditorPanelEnabled(PANEL_NAME), isOpened: isEditorPanelOpened(PANEL_NAME) }; }); var applyWithDispatch = withDispatch(function (dispatch) { var _dispatch = dispatch('core/edit-post'), toggleEditorPanelOpened = _dispatch.toggleEditorPanelOpened; return { onTogglePanel: partial(toggleEditorPanelOpened, PANEL_NAME) }; }); export default compose(applyWithSelect, applyWithDispatch)(FeaturedImage); //# sourceMappingURL=index.js.map