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

Site Editor: make close button replaceable #22001

Merged
merged 3 commits into from
May 4, 2020
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
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useViewportMatch } from '@wordpress/compose';
import { FullscreenMode, InterfaceSkeleton } from '@wordpress/interface';
import { EntitiesSavedStates } from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { PluginArea } from '@wordpress/plugins';

/**
* Internal dependencies
Expand Down Expand Up @@ -151,6 +152,7 @@ function Editor( { settings: _settings } ) {
footer={ <BlockBreadcrumb /> }
/>
<Popover.Slot />
<PluginArea />
</FocusReturnProvider>
</Context.Provider>
</EntityProvider>
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PinnedItems } from '@wordpress/interface';
* Internal dependencies
*/
import { useEditorContext } from '../editor';
import FullscreenModeClose from './fullscreen-mode-close';
import MainDashboardButton from './main-dashboard-button';
import MoreMenu from './more-menu';
import TemplateSwitcher from '../template-switcher';
import SaveButton from '../save-button';
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function Header( { openEntitiesSavedStates } ) {

return (
<div className="edit-site-header">
<FullscreenModeClose />
<MainDashboardButton.Slot />
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

<div className="edit-site-header__toolbar">
<Inserter
position="bottom right"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import { 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 } </>;
Copy link
Member

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

Suggested change
return <> { fills } </>;
return <>{ fills }</>;

Copy link
Member

Choose a reason for hiding this comment

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

Good catch

Copy link
Member Author

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.

} }
</Slot>
);

export default MainDashboardButton;
2 changes: 2 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export function initialize( id, settings ) {
}
render( <Editor settings={ settings } />, document.getElementById( id ) );
}

export { default as MainDashboardButton } from './components/header/main-dashboard-button';