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

Editor: Use plugin context hook in 'PluginPreviewMenuItem' #66350

Merged
merged 1 commit into from
Oct 23, 2024
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
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
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes a typo in the original example.

* 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 }
/>
);
}
Loading