Skip to content

Commit

Permalink
Refactor slot
Browse files Browse the repository at this point in the history
  • Loading branch information
vindl committed May 13, 2020
1 parent 0348ba7 commit 7d1b948
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { cog } from '@wordpress/icons';
import {
PinnedItems,
__experimentalCloseButtonSlot as CloseButtonSlot,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/interface';

/**
Expand Down Expand Up @@ -69,9 +69,9 @@ function Header( {

return (
<div className="edit-post-header">
<CloseButtonSlot>
<MainDashboardButton.Slot>
<FullscreenModeClose />
</CloseButtonSlot>
</MainDashboardButton.Slot>
<div className="edit-post-header__toolbar">
<HeaderToolbar
onToggleInserter={ onToggleInserter }
Expand Down
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import {
PinnedItems,
__experimentalCloseButtonSlot as CloseButtonSlot,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/interface';

/**
Expand Down Expand Up @@ -67,9 +67,9 @@ export default function Header( { openEntitiesSavedStates } ) {

return (
<div className="edit-site-header">
<CloseButtonSlot>
<MainDashboardButton.Slot>
<FullscreenModeClose />
</CloseButtonSlot>
</MainDashboardButton.Slot>
<div className="edit-site-header__toolbar">
<Inserter
position="bottom right"
Expand Down
5 changes: 1 addition & 4 deletions packages/interface/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ export { default as ComplementaryArea } from './complementary-area';
export { default as FullscreenMode } from './fullscreen-mode';
export { default as InterfaceSkeleton } from './interface-skeleton';
export { default as PinnedItems } from './pinned-items';
export {
default as __experimentalMainDashboardButton,
CloseButtonSlot as __experimentalCloseButtonSlot,
} from './main-dashboard-button';
export { default as __experimentalMainDashboardButton } from './main-dashboard-button';
14 changes: 7 additions & 7 deletions packages/interface/src/components/main-dashboard-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import {
createSlotFill,
} from '@wordpress/components';

const name = '__experimentalMainDashboardButton';
const slotName = '__experimentalMainDashboardButton';

const { Fill, Slot } = createSlotFill( name );
const { Fill, Slot: MainDashboardButtonSlot } = createSlotFill( slotName );

const MainDashboardButton = Fill;
MainDashboardButton.Slot = Slot;
MainDashboardButton.slotName = name;

export const CloseButtonSlot = ( { children } ) => {
const slot = useSlot( MainDashboardButton.slotName );
const Slot = ( { children } ) => {
const slot = useSlot( slotName );
const hasFills = Boolean( slot.fills && slot.fills.length );

if ( ! hasFills ) {
return children;
}

return <MainDashboardButton.Slot bubblesVirtually />;
return <MainDashboardButtonSlot bubblesVirtually />;
};

MainDashboardButton.Slot = Slot;

export default MainDashboardButton;

0 comments on commit 7d1b948

Please sign in to comment.