-
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
Site Editor: make close button replaceable #22001
Conversation
|
||
__experimentalSiteEditorCloseArea.Slot = Slot; | ||
|
||
export default __experimentalSiteEditorCloseArea; |
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 need to come up with a better name for this. :)
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.
Yeah thats a tough one... should we replace Area
with SlotFill
? or maybe there is a better term someone can suggest.
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 don't think it's bad.
But, since this is the "home button", maybe __experimentalSiteEditorHomeButton
?
Either one works IMO.
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.
Yes, I'd avoid referring to "close" or any implicit action and try to be a bit more semantic (something like MainDashboardButton
perhaps).
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.
Renamed to MainDashboardButton
in 555b399532aa0e2a02bbc07d24ce9c3f22d0d868.
Size Change: +105 B (0%) Total Size: 819 kB
ℹ️ View Unchanged
|
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.
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 don't think we should register a new plugin and filter for this.
It would be more straightforward just to use a Slot that renders FullscreenModeClose
if it doesn't have any fills.
I think @mtias and @youknowriad have more experience with this, so let's see what they think.
|
||
__experimentalSiteEditorCloseArea.Slot = Slot; | ||
|
||
export default __experimentalSiteEditorCloseArea; |
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 don't think it's bad.
But, since this is the "home button", maybe __experimentalSiteEditorHomeButton
?
Either one works IMO.
@@ -21,6 +22,10 @@ function FullscreenModeClose() { | |||
return null; | |||
} | |||
|
|||
if ( applyFilters( 'siteEditor.closeButton.remove', false ) ) { |
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 think the convention is to use the full function name.
siteEditor.fullscreenModeClose.remove
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 removed the filter in the latest refactor so this is no longer relevant.
packages/edit-site/src/index.js
Outdated
@@ -13,6 +13,7 @@ import { render } from '@wordpress/element'; | |||
*/ | |||
import './hooks'; | |||
import './store'; | |||
import './plugins'; |
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'm not sure it matters, but edit-post
imports hooks, then plugins, then the store. We should probably mirror that just to be safe since these have side effects.
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.
Also removed the plugins file in the refactor so this is no longer present.
I was trying that option too but couldn't quite get to a satisfactory state with it, because FullscreenModeClose is also a fill, so the slot is never empty by default. Is there an existing example of that somewhere in the codebase? Arguably the approach with optional removal is more versatile, because it also covers use-cases where someone might want to keep the button and add some other components next to it (not sure if this is desirable though?). Also in your case it's not clear what the expected behavior should be if multiple fills are provided by 3rd party plugins? Consistently with first operation, I'd expect only one fill will be shown, but that wouldn't be the case. And if we try to enforce it we end up needing something like priorities, which sounds very similar to a filters at that point. :) |
Use the render prop:
I don't even think the space is big enough for that, but they can always import the component and compose it themselves. Leaving it there is also assuming that whatever they "add" should come after and not before/between/etc. In rendering order.
They all render, like usually.
That's not consistent. Having a "default" fill does not imply that only one fill can show at a time. To cater to multiple plugins like that, you would need to filter the whole fill/button, but relying on that pattern and "priorities" doesn't scale well, and I think we try to avoid it where possible. |
Thanks! I'll look into this next. |
146717f
to
555b399
Compare
@epiqueras I removed the filter in the latest update, now it only relies on the presence of Fills. I also updated the PR summary and testing instructions to reflect this. |
555b399
to
566c91a
Compare
You could also use |
Thanks! We discussed the option of going with filters before and decided against it. From what I understood we are trying to limit their usage (@youknowriad might be able to provide more context here). From a developer experience standpoint, I think SlotFills are easier to use.
Based on my search through the codebase I don't think it has been used exactly in this form. Still, I think it is a cool pattern for replacing default components that we could use more in the future. It might even make sense to modify |
Would we want to make |
I don't think its warranted, but it doesn't hurt to be careful.
Great idea! @vindl do you want to follow up with that? |
Documentation is highly appreciated as well. |
@epiqueras @mtias sure, I'll handle both of these items in a follow-up. |
@@ -62,7 +62,7 @@ export default function Header( { openEntitiesSavedStates } ) { | |||
|
|||
return ( | |||
<div className="edit-site-header"> | |||
<FullscreenModeClose /> | |||
<MainDashboardButton.Slot /> |
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.
see #22027
We're moving away from regular slots. Would you mind doing a small refactor here (bubblesVirtually slots don't support children render function
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.
@youknowriad Actually I'm not sure how to achieve the same effect with this, given that it relies on children render function to handle the default case when no fills are provided?
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.
There are examples of the same use-case in the code base. See here https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/block-inspector/index.js#L89-L90
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.
Thanks, refactored this in #22179.
return <FullscreenModeClose />; | ||
} | ||
|
||
return <> { fills } </>; |
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.
These spaces are significant, and cause React to create two additional text node children.
https://codepen.io/aduth/pen/ZEbrOYY
return <> { fills } </>; | |
return <>{ fills }</>; |
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.
Good catch
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.
Thanks for pointing it out! I removed this code in #22179.
Refactored this in #22179 according to the suggestions above. |
Description
The aim of this is to address the first part of #20929, namely making it easy to extend and replace the existing close button (W Icon) in site and post editor. Currently the code is contained to site editor only, but if it makes sense I will extend this approach to post editor too.
In order to allow for adding custom components the slot area was added in place of the existing close button. If no fills are provided it will render the default Close button, otherwise it will replace it with available fills.
For example, that could be achieved with the following code in the plugins:
How has this been tested?
Screenshots
Types of changes
Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist: