-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add extensibility to PreviewOptions #36119
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @arcangelini! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
{ coreDeviceTypes.map( ( device ) => ( | ||
<MenuItem | ||
key={ device } | ||
className="block-editor-post-preview__button-resize" | ||
onClick={ () => setDeviceType( device ) } | ||
icon={ deviceType === device && check } | ||
> | ||
{ device } | ||
</MenuItem> | ||
) ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you introduced the coreDeviceTypes
array and then streamlined the way the
MenuItem
components are being rendered using map()
.
One thing I think we could consider is to make the output of device labels
translatable.
An idea I have on my mind is to turn the array of strings into the array of objects
and let the label have its own translatable value that isn't used for any logic:
diff --git a/packages/block-editor/src/components/preview-options/index.js b/packages/block-editor/src/components/preview-options/index.js
index 03b3f3cea9..c3e67ab580 100644
--- a/packages/block-editor/src/components/preview-options/index.js
+++ b/packages/block-editor/src/components/preview-options/index.js
@@ -19,7 +19,11 @@ export default function PreviewOptions( {
deviceType,
setDeviceType,
} ) {
- const coreDeviceTypes = [ 'Desktop', 'Tablet', 'Mobile' ];
+ const coreDeviceTypes = [
+ { type: 'Desktop', label: __( 'Desktop' ) },
+ { type: 'Tablet', label: __( 'Tablet' ) },
+ { type: 'Mobile', label: __( 'Mobile' ) },
+ ];
const isMobile = useViewportMatch( 'small', '<' );
if ( isMobile ) return null;
@@ -50,12 +54,12 @@ export default function PreviewOptions( {
<MenuGroup>
{ coreDeviceTypes.map( ( device ) => (
<MenuItem
- key={ device }
+ key={ device.type }
className="block-editor-post-preview__button-resize"
- onClick={ () => setDeviceType( device ) }
- icon={ deviceType === device && check }
+ onClick={ () => setDeviceType( device.type ) }
+ icon={ deviceType === device.type && check }
>
- { device }
+ { device.label }
</MenuItem>
) ) }
</MenuGroup>
Thank you for adding the plugin download link to the PR. It made it much easier to test your code. 👍🏼 👍🏼 |
e21eb3a
to
d010e05
Compare
I rebased this PR. I realize this is still a rough draft, but would love feedback to potentially get this moving forward if possible 😄 |
I get this error export 'PluginPreview' (imported as 'PluginPreview') was not found in '@wordpress/interface' (possible exports: ActionItem, ComplementaryArea, ComplementaryAreaMoreMenuItem, FullscreenMode, InterfaceSkeleton, MoreMenuDropdown, MoreMenuFeatureToggle, PinnedItems, PreferencesModal, PreferencesModalSection, PreferencesModalTabs, ___unstablePreferencesModalBaseOption, store) |
Yea me too, did you manage to work this out? |
It has been a little while since I have worked on this. I would be happy to clean it up this week and see what is going on. I will let y'all know when it is ready to test again @UranymusDev and @tomektomczuk |
Is there any update on this please? This is a much-needed feature and I know a lot of people are keen to see this happen. |
First pass at continuing work on extending preview menu in editors. The work is entirely copied from #36119, which includes work from #31984 Tony Arcangelini <[email protected]> Piotr Delawski <[email protected]>
This is no longer relevant it seems. Closing. |
Implemented with #64644. |
Description
This is a continuation of the following PR #31984
The overall goal of this PR is to make the Preview menu extensible using SlotFill similarly to
PinnedItems
andPluginSidebar
.The menu is extended using the
<PluginPreview>
component built into@wordpress/interface package
. It allows for defining a custom "Preview" menu item. There are then two ways to manipulate the preview.children
will completely replace theVisualEditor
component. In my example, I used an iframe and grabbed the preview URL to display a full site preview in iPhone resolution.wrapper
component, theVisualEditor
iframe is passed in as a prop and allows you to control how the preview is displayed. In my example, I added a basic div, but this could be more robust if desired.In absence of both of these the view will default back to 'Desktop' allowing for only adding an
onClick
event with no change to the display. Along with the addition of the SlotFill, this PR also refactors the<PreviewOptions>
component to consolidate the device type names.How has this been tested?
I created a test plugin to allow for easy testing, download here (updated). Once you install the plugin you should see three new items added to your previews dropdown.
Likewise, you can use the following code to create your own plugin and test as you like:
Updated with wrapper prop
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Fixes #25309
Relates to Automattic/wp-calypso#42896
Relates to ampproject/amp-wp#5943
Checklist:
*.native.js
files for terms that need renaming or removal).