From 25215a997e23b8b4b05b122ccb1c2778dcd4cfa7 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Sat, 5 Aug 2023 10:17:43 +0400 Subject: [PATCH] Edit Post: Replace 'withPluginContext' in the 'PluginPrePublishPanel' (#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 <8436925+tyxla@users.noreply.github.com> * Update packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com> --------- Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com> --- packages/edit-post/README.md | 1 + .../sidebar/plugin-pre-publish-panel/index.js | 53 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/packages/edit-post/README.md b/packages/edit-post/README.md index d6ad06e8e89992..e6a652975aa280 100644 --- a/packages/edit-post/README.md +++ b/packages/edit-post/README.md @@ -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_ diff --git a/packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js b/packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js index b5912df3d498c9..91392ab7883ed5 100644 --- a/packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js +++ b/packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/index.js @@ -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, -} ) => ( - - - { children } - - -); +const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' ); /** * Renders provided content to the pre-publish side panel in the publish flow @@ -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 @@ -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 ( + + + { children } + + + ); +}; PluginPrePublishPanel.Slot = Slot;