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

Navigation: add dedicated sidebar for managing layout of navigation menus #39290

Merged
merged 19 commits into from
Mar 28, 2022
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,8 @@
/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';

const __unstableBlockNameContext = createContext( '' );

export default __unstableBlockNameContext;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

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

__unstableBlockToolbarLastItem.Slot = Slot;

export default __unstableBlockToolbarLastItem;
7 changes: 7 additions & 0 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import BlockMover from '../block-mover';
import BlockParentSelector from '../block-parent-selector';
import BlockSwitcher from '../block-switcher';
import BlockControls from '../block-controls';
import __unstableBlockToolbarLastItem from './block-toolbar-last-item';
import BlockSettingsMenu from '../block-settings-menu';
import { BlockLockToolbar } from '../block-lock';
import { BlockGroupToolbar } from '../convert-to-group-buttons';
import { useShowMoversGestures } from './utils';
import { store as blockEditorStore } from '../../store';
import __unstableBlockNameContext from './block-name-context';

export default function BlockToolbar( { hideDragHandle } ) {
const {
Expand Down Expand Up @@ -150,6 +152,11 @@ export default function BlockToolbar( { hideDragHandle } ) {
group="other"
className="block-editor-block-toolbar__slot"
/>
<__unstableBlockNameContext.Provider
Copy link
Contributor

Choose a reason for hiding this comment

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

This is used to provide a toggle to open the Navigation sidebar for the currently selected Navigation block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a picture for folks too. In trunk clicking this opens a list-view modal, but on this branch it should open the new sidebar.

list view

value={ blockType?.name }
>
<__unstableBlockToolbarLastItem.Slot />
</__unstableBlockNameContext.Provider>
</>
) }
<BlockSettingsMenu clientIds={ blockClientIds } />
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export { default as withColorContext } from './color-palette/with-color-context'
*/

export { default as __unstableBlockSettingsMenuFirstItem } from './block-settings-menu/block-settings-menu-first-item';
export { default as __unstableBlockToolbarLastItem } from './block-toolbar/block-toolbar-last-item';
export { default as __unstableBlockNameContext } from './block-toolbar/block-name-context';
export { default as __unstableInserterMenuExtension } from './inserter-menu-extension';
export { default as __experimentalPreviewOptions } from './preview-options';
export { default as __experimentalUseResizeCanvas } from './use-resize-canvas';
Expand Down
7 changes: 0 additions & 7 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { speak } from '@wordpress/a11y';
/**
* Internal dependencies
*/
import useListViewModal from './use-list-view-modal';
import useNavigationMenu from '../use-navigation-menu';
import useNavigationEntities from '../use-navigation-entities';
import Placeholder from './placeholder';
Expand Down Expand Up @@ -283,10 +282,6 @@ function Navigation( {
const navRef = useRef();
const isDraftNavigationMenu = navigationMenu?.status === 'draft';

const { listViewToolbarButton, listViewModal } = useListViewModal(
clientId
);

const {
convert,
status: classicMenuConversionStatus,
Expand Down Expand Up @@ -646,9 +641,7 @@ function Navigation( {
/>
</ToolbarGroup>
) }
<ToolbarGroup>{ listViewToolbarButton }</ToolbarGroup>
</BlockControls>
{ listViewModal }
<InspectorControls>
{ hasSubmenuIndicatorSetting && (
<PanelBody title={ __( 'Display' ) }>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function getCustomFontSizeValue() {
async function getColorValue( colorType ) {
return page.evaluate( ( _colorType ) => {
return document.evaluate(
`substring-before(substring-after(//div[@aria-label="Settings"]//button[.//*[text()="${ _colorType }"]]//*[contains(@class,"component-color-indicator")]/@style, "background: "), ";")`,
`substring-before(substring-after(//div[contains(@class, "edit-site-global-styles-sidebar__panel")]//button[.//*[text()="${ _colorType }"]]//*[contains(@class,"component-color-indicator")]/@style, "background: "), ";")`,
document,
null,
XPathResult.ANY_TYPE,
Expand Down
29 changes: 29 additions & 0 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ import {
__experimentalLinkControl,
BlockInspector,
BlockTools,
__unstableBlockToolbarLastItem,
__unstableBlockSettingsMenuFirstItem,
__unstableUseTypingObserver as useTypingObserver,
BlockEditorKeyboardShortcuts,
store as blockEditorStore,
__unstableBlockNameContext,
} from '@wordpress/block-editor';
import { useMergeRefs, useViewportMatch } from '@wordpress/compose';
import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
import { listView } from '@wordpress/icons';
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand Down Expand Up @@ -65,6 +71,13 @@ export default function BlockEditor( { setIsInserterOpen } ) {
templateType
);
const { setPage } = useDispatch( editSiteStore );
const { enableComplementaryArea } = useDispatch( interfaceStore );
const openNavigationSidebar = useCallback( () => {
enableComplementaryArea(
'core/edit-site',
'edit-site/navigation-menu'
);
}, [ enableComplementaryArea ] );
const contentRef = useRef();
const mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );
const isMobileViewport = useViewportMatch( 'small', '<' );
Expand Down Expand Up @@ -133,6 +146,22 @@ export default function BlockEditor( { setIsInserterOpen } ) {
<BlockInspectorButton onClick={ onClose } />
) }
</__unstableBlockSettingsMenuFirstItem>
<__unstableBlockToolbarLastItem>
<__unstableBlockNameContext.Consumer>
{ ( blockName ) =>
blockName === 'core/navigation' && (
<ToolbarGroup>
<ToolbarButton
className="components-toolbar__control"
label={ __( 'Open list view' ) }
onClick={ openNavigationSidebar }
icon={ listView }
/>
</ToolbarGroup>
)
}
</__unstableBlockNameContext.Consumer>
</__unstableBlockToolbarLastItem>
</BlockTools>
<ReusableBlocksMenuItems />
</BlockEditorProvider>
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
*/
import DefaultSidebar from './default-sidebar';
import GlobalStylesSidebar from './global-styles-sidebar';
import NavigationMenuSidebar from './navigation-menu-sidebar';
import { STORE_NAME } from '../../store/constants';
import SettingsHeader from './settings-header';
import TemplateCard from './template-card';
Expand Down Expand Up @@ -77,6 +78,7 @@ export function SidebarComplementaryAreaFills() {
) }
</DefaultSidebar>
<GlobalStylesSidebar />
<NavigationMenuSidebar />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* WordPress dependencies
*/
import { FlexBlock, Flex } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { navigation } from '@wordpress/icons';

/**
* Internal dependencies
*/
import DefaultSidebar from '../default-sidebar';
import NavigationInspector from './navigation-inspector';

export default function NavigationMenuSidebar() {
return (
<DefaultSidebar
className="edit-site-navigation-menu-sidebar"
identifier="edit-site/navigation-menu"
title={ __( 'Navigation Menus' ) }
icon={ navigation }
closeLabel={ __( 'Close navigation menu sidebar' ) }
panelClassName="edit-site-navigation-menu-sidebar__panel"
header={
<Flex>
<FlexBlock>
<strong>{ __( 'Navigation Menus' ) }</strong>
</FlexBlock>
</Flex>
}
>
<NavigationInspector />
</DefaultSidebar>
);
}
Loading