-
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: refactor close button slot #22179
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
docs/designers-developers/developers/slotfills/main-dashboard-button.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# MainDashboardButton | ||
|
||
This slot allows replacing the default main dashboard button that's used for closing | ||
the editor in fullscreen mode. | ||
|
||
## Example | ||
|
||
```js | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import { __experimentalMainDashboardButton } from '@wordpress/edit-site'; | ||
|
||
const MainDashboardButtonTest = () => ( | ||
<__experimentalMainDashboardButton> | ||
Custom main dashboard button content | ||
</__experimentalMainDashboardButton> | ||
); | ||
|
||
registerPlugin( 'main-dashboard-button-test', { | ||
render: MainDashboardButtonTest, | ||
} ); | ||
``` | ||
|
||
If your goal is just to replace the icon of the existing button, that can be achieved | ||
in the following way: | ||
|
||
```js | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import { | ||
__experimentalMainDashboardButton, | ||
__experimentalFullscrenModeClose | ||
} from '@wordpress/edit-site'; | ||
import { close } from '@wordpress/icons'; | ||
|
||
|
||
const MainDashboardButtonIconTest = () => ( | ||
<__experimentalMainDashboardButton> | ||
<__experimentalFullscrenModeClose icon={ close } /> | ||
</__experimentalMainDashboardButton> | ||
); | ||
|
||
registerPlugin( 'main-dashboard-button-icon-test', { | ||
render: MainDashboardButtonIconTest, | ||
} ); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 22 additions & 22 deletions
44
packages/edit-site/src/components/header/main-dashboard-button/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
import { | ||
__experimentalUseSlot as useSlot, | ||
createSlotFill, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FullscreenModeClose from '../fullscreen-mode-close'; | ||
|
||
const { Fill: MainDashboardButton, Slot } = createSlotFill( | ||
'SiteEditorMainDashboardButton' | ||
); | ||
|
||
MainDashboardButton.Slot = () => ( | ||
<Slot> | ||
{ ( fills ) => { | ||
// Return default Close button if no fills are provided, otherwise replace it with available fills. | ||
if ( isEmpty( fills ) ) { | ||
return <FullscreenModeClose />; | ||
} | ||
|
||
return <> { fills } </>; | ||
} } | ||
</Slot> | ||
); | ||
const name = '__experimentalSiteEditorMainDashboardButton'; | ||
|
||
const { Fill, Slot } = createSlotFill( name ); | ||
|
||
const MainDashboardButton = Fill; | ||
MainDashboardButton.Slot = Slot; | ||
MainDashboardButton.slotName = name; | ||
|
||
export const CloseButton = () => { | ||
const slot = useSlot( MainDashboardButton.slotName ); | ||
const hasFills = Boolean( slot.fills && slot.fills.length ); | ||
|
||
if ( ! hasFills ) { | ||
return <FullscreenModeClose />; | ||
} | ||
|
||
return <MainDashboardButton.Slot bubblesVirtually />; | ||
}; | ||
|
||
export default MainDashboardButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so this slot is just an edit-site slot? Would we need to offer the same for the other screens. Also, if the fallback button is the same across screens, should the slot be the same across screens too?
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.
This shouldn't block this PR. I think it's ready.
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 was planning to make a separate slot for post editor. The rationale being that someone might want to provide a different component in other screens. Or it might look the same but we might want it to behave differently.
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 100% certain we need a separate component especially if we add support to more and more screens (widgets...). Also it seems possible to enqueue the extension based on the screen or check the screen and change the behavior.
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.
That's true. Since I was planning on starting a separate PR for post editor, would it be fine if I consolidate this to use the same slot in it and merge this as is for now?
Or I could expand this PR to take care of both. 🤔I generally prefer to keep them smaller.
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, we should merge this and see in a separate PR if we can have the same slot.