Skip to content

Commit

Permalink
Editor: Use plugin context hook in 'PluginPreviewMenuItem' (WordPress…
Browse files Browse the repository at this point in the history
…#66350)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 6184562 commit 9421bc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ function onPreviewClick() {
}

const ExternalPreviewMenuItem = () => (
<PreviewDropdownMenuItem icon={ external } onClick={ onPreviewClick }>
<PluginPreviewMenuItem icon={ external } onClick={ onPreviewClick }>
{ __( 'Preview in new tab' ) }
</PreviewDropdownMenuItem>
</PluginPreviewMenuItem>
);
registerPlugin( 'external-preview-menu-item', {
render: ExternalPreviewMenuItem,
Expand Down
27 changes: 14 additions & 13 deletions packages/editor/src/components/plugin-preview-menu-item/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { MenuItem } from '@wordpress/components';
import { withPluginContext } from '@wordpress/plugins';
import { usePluginContext } from '@wordpress/plugins';
import { ActionItem } from '@wordpress/interface';

/**
Expand All @@ -27,12 +26,12 @@ import { ActionItem } from '@wordpress/interface';
* }
*
* const ExternalPreviewMenuItem = () => (
* <PreviewDropdownMenuItem
* <PluginPreviewMenuItem
* icon={ external }
* onClick={ onPreviewClick }
* >
* { __( 'Preview in new tab' ) }
* </PreviewDropdownMenuItem>
* </PluginPreviewMenuItem>
* );
* registerPlugin( 'external-preview-menu-item', {
* render: ExternalPreviewMenuItem,
Expand All @@ -41,12 +40,14 @@ import { ActionItem } from '@wordpress/interface';
*
* @return {Component} The rendered menu item component.
*/
export default compose(
withPluginContext( ( context, ownProps ) => {
return {
as: ownProps.as ?? MenuItem,
icon: ownProps.icon || context.icon,
name: 'core/plugin-preview-menu',
};
} )
)( ActionItem );
export default function PluginPreviewMenuItem( props ) {
const context = usePluginContext();
return (
<ActionItem
name="core/plugin-preview-menu"
as={ props.as ?? MenuItem }
icon={ props.icon || context.icon }
{ ...props }
/>
);
}

0 comments on commit 9421bc9

Please sign in to comment.