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

Add block navigator to sidebar panel for nav block #18202

Merged
merged 2 commits into from
Oct 31, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
import {
__experimentalBlockNavigationList,
} from '@wordpress/block-editor';
import {
useSelect,
useDispatch,
} from '@wordpress/data';

export default function BlockNavigationList( { clientId } ) {
const {
block,
selectedBlockClientId,
} = useSelect( ( select ) => {
const {
getSelectedBlockClientId,
getBlock,
} = select( 'core/block-editor' );

return {
block: getBlock( clientId ),
selectedBlockClientId: getSelectedBlockClientId(),
};
}, [ clientId ] );

const {
selectBlock,
} = useDispatch( 'core/block-editor' );

return (
<__experimentalBlockNavigationList
blocks={ [ block ] }
selectedBlockClientId={ selectedBlockClientId }
selectBlock={ selectBlock }
showNestedBlocks
/>
);
}
6 changes: 6 additions & 0 deletions packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import useBlockNavigator from './use-block-navigator';
import BlockNavigationList from './block-navigation-list';
import BlockColorsStyleSelector from './block-colors-selector';

function NavigationMenu( {
Expand Down Expand Up @@ -133,6 +134,11 @@ function NavigationMenu( {
help={ __( 'Automatically add new top level pages to this menu.' ) }
/>
</PanelBody>
<PanelBody
title={ __( 'Navigation Structure' ) }
>
<BlockNavigationList clientId={ clientId } />
</PanelBody>
</InspectorControls>

<div className={ navigationMenuClasses } style={ navigationMenuStyles }>
Expand Down
38 changes: 6 additions & 32 deletions packages/block-library/src/navigation-menu/use-block-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
import {
useState,
} from '@wordpress/element';
import {
useSelect,
useDispatch,
} from '@wordpress/data';
import {
__experimentalBlockNavigationList,
} from '@wordpress/block-editor';
import {
IconButton,
SVG,
Expand All @@ -19,6 +12,11 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockNavigationList from './block-navigation-list';

const NavigatorIcon = (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20">
<Path d="M5 5H3v2h2V5zm3 8h11v-2H8v2zm9-8H6v2h11V5zM7 11H5v2h2v-2zm0 8h2v-2H7v2zm3-2v2h11v-2H10z" />
Expand All @@ -28,25 +26,6 @@ const NavigatorIcon = (
export default function useBlockNavigator( clientId ) {
const [ isNavigationListOpen, setIsNavigationListOpen ] = useState( false );

const {
block,
selectedBlockClientId,
} = useSelect( ( select ) => {
const {
getSelectedBlockClientId,
getBlock,
} = select( 'core/block-editor' );

return {
block: getBlock( clientId ),
selectedBlockClientId: getSelectedBlockClientId(),
};
}, [ clientId ] );

const {
selectBlock,
} = useDispatch( 'core/block-editor' );

const navigatorToolbarButton = (
<IconButton
className="components-toolbar__control"
Expand All @@ -64,12 +43,7 @@ export default function useBlockNavigator( clientId ) {
setIsNavigationListOpen( false );
} }
>
<__experimentalBlockNavigationList
blocks={ [ block ] }
selectedBlockClientId={ selectedBlockClientId }
selectBlock={ selectBlock }
showNestedBlocks
/>
<BlockNavigationList clientId={ clientId } />
</Modal>
);

Expand Down