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

Replace the renderBlockMenu prop with a Slot #7199

Merged
merged 2 commits into from
Jun 11, 2018
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
16 changes: 5 additions & 11 deletions edit-post/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,15 @@ import {
EditorGlobalKeyboardShortcuts,
BlockSelectionClearer,
MultiSelectScrollIntoView,
_BlockSettingsMenuFirstItem,
} from '@wordpress/editor';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import './style.scss';
import BlockInspectorButton from './block-inspector-button';

function VisualEditorBlockMenu( { children, onClose } ) {
return (
<Fragment>
<BlockInspectorButton onClick={ onClose } role="menuitem" />
{ children }
</Fragment>
);
}

function VisualEditor() {
return (
<BlockSelectionClearer className="edit-post-visual-editor">
Expand All @@ -37,9 +28,12 @@ function VisualEditor() {
<WritingFlow>
<ObserveTyping>
<PostTitle />
<BlockList renderBlockMenu={ VisualEditorBlockMenu } />
<BlockList />
</ObserveTyping>
</WritingFlow>
<_BlockSettingsMenuFirstItem>
{ ( { onClose } ) => <BlockInspectorButton onClick={ onClose } role="menuitem" /> }
</_BlockSettingsMenuFirstItem>
</BlockSelectionClearer>
);
}
Expand Down
4 changes: 2 additions & 2 deletions editor/components/block-list/block-mobile-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import BlockMover from '../block-mover';
import BlockSettingsMenu from '../block-settings-menu';
import VisualEditorInserter from '../inserter';

function BlockMobileToolbar( { rootUID, uid, renderBlockMenu } ) {
function BlockMobileToolbar( { rootUID, uid } ) {
return (
<div className="editor-block-list__block-mobile-toolbar">
<VisualEditorInserter />
<BlockMover uids={ [ uid ] } />
<BlockSettingsMenu rootUID={ rootUID } uids={ [ uid ] } renderBlockMenu={ renderBlockMenu } />
<BlockSettingsMenu rootUID={ rootUID } uids={ [ uid ] } />
</div>
);
}
Expand Down
6 changes: 1 addition & 5 deletions editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class BlockListBlock extends Component {
}

createInnerBlockList( uid ) {
const { renderBlockMenu } = this.props;
return createInnerBlockList( uid, renderBlockMenu );
return createInnerBlockList( uid );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to refactor further here because it's taken care of in #7192

Copy link
Member

Choose a reason for hiding this comment

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

I didn't want to refactor further here because it's taken care of in #7192

By refactoring, do you include removal of the unused-as-of-these-changes renderBlockMenu argument of createInnerBlockList?

}

/**
Expand Down Expand Up @@ -403,7 +402,6 @@ export class BlockListBlock extends Component {
uid,
rootUID,
layout,
renderBlockMenu,
isSelected,
isMultiSelected,
isFirstMultiSelected,
Expand Down Expand Up @@ -533,7 +531,6 @@ export class BlockListBlock extends Component {
<BlockSettingsMenu
uids={ uid }
rootUID={ rootUID }
renderBlockMenu={ renderBlockMenu }
isHidden={ ! ( isHovered || isSelected ) || hoverArea !== 'right' }
/>
) }
Expand Down Expand Up @@ -581,7 +578,6 @@ export class BlockListBlock extends Component {
<BlockMobileToolbar
rootUID={ rootUID }
uid={ uid }
renderBlockMenu={ renderBlockMenu }
/>
) }
</IgnoreNestedEvents>
Expand Down
2 changes: 0 additions & 2 deletions editor/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class BlockListLayout extends Component {
layout,
isGroupedByLayout,
rootUID,
renderBlockMenu,
} = this.props;

let defaultLayout;
Expand All @@ -219,7 +218,6 @@ class BlockListLayout extends Component {
layout={ defaultLayout }
isFirst={ blockIndex === 0 }
isLast={ blockIndex === blockUIDs.length - 1 }
renderBlockMenu={ renderBlockMenu }
/>
) ) }
<IgnoreNestedEvents childHandledEvents={ [ 'onFocus', 'onClick', 'onKeyDown' ] }>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

const { Fill: _BlockSettingsMenuFirstItem, Slot } = createSlotFill( '_BlockSettingsMenuFirstItem' );

_BlockSettingsMenuFirstItem.Slot = Slot;

export default _BlockSettingsMenuFirstItem;
15 changes: 7 additions & 8 deletions editor/components/block-settings-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import BlockDuplicateButton from './block-duplicate-button';
import BlockTransformations from './block-transformations';
import SharedBlockSettings from './shared-block-settings';
import UnknownConverter from './unknown-converter';
import _BlockSettingsMenuFirstItem from './block-settings-menu-first-item';

export class BlockSettingsMenu extends Component {
constructor() {
Expand Down Expand Up @@ -51,7 +52,6 @@ export class BlockSettingsMenu extends Component {
onSelect,
focus,
rootUID,
renderBlockMenu = ( { children } ) => children,
isHidden,
} = this.props;
const { isFocused } = this.state;
Expand Down Expand Up @@ -94,13 +94,12 @@ export class BlockSettingsMenu extends Component {
renderContent={ ( { onClose } ) => (
// Should this just use a DropdownMenu instead of a DropDown ?
<NavigableMenu className="editor-block-settings-menu__content">
{ renderBlockMenu( { onClose, children: [
count === 1 && <BlockModeToggle key="mode-toggle" uid={ firstBlockUID } onToggle={ onClose } role="menuitem" />,
count === 1 && <UnknownConverter key="unknown-converter" uid={ firstBlockUID } role="menuitem" />,
<BlockDuplicateButton key="duplicate" uids={ uids } rootUID={ rootUID } role="menuitem" />,
count === 1 && <SharedBlockSettings key="shared-block" uid={ firstBlockUID } onToggle={ onClose } itemsRole="menuitem" />,
<BlockTransformations key="transformations" uids={ uids } onClick={ onClose } itemsRole="menuitem" />,
] } ) }
<_BlockSettingsMenuFirstItem.Slot fillProps={ { onClose } } />
{ count === 1 && <BlockModeToggle uid={ firstBlockUID } onToggle={ onClose } role="menuitem" /> }
{ count === 1 && <UnknownConverter uid={ firstBlockUID } role="menuitem" /> }
<BlockDuplicateButton uids={ uids } rootUID={ rootUID } role="menuitem" />
{ count === 1 && <SharedBlockSettings uid={ firstBlockUID } onToggle={ onClose } itemsRole="menuitem" /> }
<BlockTransformations uids={ uids } onClick={ onClose } itemsRole="menuitem" />
</NavigableMenu>
) }
/>
Expand Down
1 change: 1 addition & 0 deletions editor/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export { default as BlockList } from './block-list';
export { default as BlockMover } from './block-mover';
export { default as BlockSelectionClearer } from './block-selection-clearer';
export { default as BlockSettingsMenu } from './block-settings-menu';
export { default as _BlockSettingsMenuFirstItem } from './block-settings-menu/block-settings-menu-first-item';
export { default as BlockTitle } from './block-title';
export { default as BlockToolbar } from './block-toolbar';
export { default as CopyHandler } from './copy-handler';
Expand Down