Skip to content

Commit

Permalink
Edit Post: Replace 'withPluginContext' in the 'PluginPrePublishPanel' (
Browse files Browse the repository at this point in the history
…WordPress#53304)

* Edit Post: Replace 'withPluginContext' in the 'PluginPrePublishPanel'

* Update packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js

Co-authored-by: Marin Atanasov <[email protected]>

* Update packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js

Co-authored-by: Marin Atanasov <[email protected]>

---------

Co-authored-by: Marin Atanasov <[email protected]>
  • Loading branch information
Mamaduka and tyxla authored Aug 5, 2023
1 parent b4d1a76 commit 25215a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ _Parameters_
- _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_ `[WPBlockTypeIconRender]`: 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.
- _props.children_ `WPElement`: Children to be rendered

_Returns_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,9 @@
* WordPress dependencies
*/
import { createSlotFill, PanelBody } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );
import { usePluginContext } from '@wordpress/plugins';

const PluginPrePublishPanelFill = ( {
children,
className,
title,
initialOpen = false,
icon,
} ) => (
<Fill>
<PanelBody
className={ className }
initialOpen={ initialOpen || ! title }
title={ title }
icon={ icon }
>
{ children }
</PanelBody>
</Fill>
);
const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );

/**
* Renders provided content to the pre-publish side panel in the publish flow
Expand All @@ -37,6 +18,7 @@ const PluginPrePublishPanelFill = ( {
* @param {WPBlockTypeIconRender} [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.
* @param {WPElement} props.children Children to be rendered
*
* @example
* ```js
Expand Down Expand Up @@ -76,13 +58,28 @@ const PluginPrePublishPanelFill = ( {
*
* @return {WPComponent} The component to be rendered.
*/
const PluginPrePublishPanel = compose(
withPluginContext( ( context, ownProps ) => {
return {
icon: ownProps.icon || context.icon,
};
} )
)( PluginPrePublishPanelFill );
const PluginPrePublishPanel = ( {
children,
className,
title,
initialOpen = false,
icon,
} ) => {
const { icon: pluginIcon } = usePluginContext();

return (
<Fill>
<PanelBody
className={ className }
initialOpen={ initialOpen || ! title }
title={ title }
icon={ icon ?? pluginIcon }
>
{ children }
</PanelBody>
</Fill>
);
};

PluginPrePublishPanel.Slot = Slot;

Expand Down

0 comments on commit 25215a9

Please sign in to comment.