Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Post: Replace 'withPluginContext' in the 'PluginPostPublishPanel' #53302

Merged
merged 3 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,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
@@ -1,30 +1,11 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { usePluginContext } from '@wordpress/plugins';
import { createSlotFill, PanelBody } from '@wordpress/components';

const { Fill, Slot } = createSlotFill( 'PluginPostPublishPanel' );

const PluginPostPublishPanelFill = ( {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was indeed no need to have this as a separate component 👍

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 post-publish panel in the publish flow
* (side panel that opens after a user publishes the post).
Expand All @@ -34,6 +15,7 @@ const PluginPostPublishPanelFill = ( {
* @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 {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 @@ -73,14 +55,28 @@ const PluginPostPublishPanelFill = ( {
*
* @return {WPComponent} The component to be rendered.
*/
const PluginPostPublishPanel = ( {
children,
className,
title,
initialOpen = false,
icon,
} ) => {
const { icon: pluginIcon } = usePluginContext();

const PluginPostPublishPanel = compose(
withPluginContext( ( context, ownProps ) => {
return {
icon: ownProps.icon || context.icon,
};
} )
)( PluginPostPublishPanelFill );
return (
<Fill>
<PanelBody
className={ className }
initialOpen={ initialOpen || ! title }
title={ title }
icon={ icon ?? pluginIcon }
>
{ children }
</PanelBody>
</Fill>
);
};

PluginPostPublishPanel.Slot = Slot;

Expand Down