Skip to content

Commit

Permalink
PluginPrePublishPanel uses icon property and inherits from registerPl…
Browse files Browse the repository at this point in the history
…ugin (#16378)

* Adds withPluginContext to PluginPrePublishPanel so that the icon is inherited from the registerPlugin call

* Docs rebuild
  • Loading branch information
Ryan Welcher authored Sep 6, 2019
1 parent 64e88c4 commit 0f59a72
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ _Parameters_
- _props.className_ `[string]`: An optional class name added to the panel.
- _props.title_ `[string]`: Title displayed at the top of the panel.
- _props.initialOpen_ `[boolean]`: Whether to have the panel initially opened. When no title is provided it is always opened.
- _props.icon_ `[(string|Element)]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.

_Returns_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
* WordPress dependencies
*/
import { createSlotFill, PanelBody } from '@wordpress/components';

import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );

const PluginPrePublishPanelFill = ( { children, className, title, initialOpen = false, icon } ) => (
<Fill>
<PanelBody
className={ className }
initialOpen={ initialOpen || ! title }
title={ title }
icon={ icon }
>
{ children }
</PanelBody>
</Fill>
);
/**
* Renders provided content to the pre-publish side panel in the publish flow
* (side panel that opens when a user first pushes "Publish" from the main editor).
Expand All @@ -13,6 +26,8 @@ const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );
* @param {string} [props.className] An optional class name added to the panel.
* @param {string} [props.title] Title displayed at the top of the panel.
* @param {boolean} [props.initialOpen=false] Whether to have the panel initially opened. When no title is provided it is always opened.
* @param {string|Element} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.
*
* @example <caption>ES5</caption>
* ```js
Expand Down Expand Up @@ -52,17 +67,13 @@ const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );
*
* @return {WPElement} The WPElement to be rendered.
*/
const PluginPrePublishPanel = ( { children, className, title, initialOpen = false } ) => (
<Fill>
<PanelBody
className={ className }
initialOpen={ initialOpen || ! title }
title={ title }
>
{ children }
</PanelBody>
</Fill>
);
const PluginPrePublishPanel = compose(
withPluginContext( ( context, ownProps ) => {
return {
icon: ownProps.icon || context.icon,
};
} ),
)( PluginPrePublishPanelFill );

PluginPrePublishPanel.Slot = Slot;

Expand Down

0 comments on commit 0f59a72

Please sign in to comment.