-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation: Add a 'open list view' button (#46335)
* Navigation: Add a 'open list view' button * Remove invalid comment * Update packages/edit-post/src/plugins/navigation-list-view-menu-item.js
- Loading branch information
Showing
3 changed files
with
72 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/edit-post/src/plugins/navigation-list-view-menu-item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
BlockEditorProvider, | ||
__unstableBlockToolbarLastItem, | ||
__unstableBlockNameContext, | ||
} from '@wordpress/block-editor'; | ||
import { ToolbarButton, ToolbarGroup } from '@wordpress/components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { listView } from '@wordpress/icons'; | ||
|
||
const NavMenuSidebarToggle = () => { | ||
// eslint-disable-next-line @wordpress/data-no-store-string-literals | ||
const { openGeneralSidebar } = useDispatch( 'core/edit-post' ); | ||
|
||
return ( | ||
<ToolbarGroup> | ||
<ToolbarButton | ||
className="components-toolbar__control" | ||
label={ __( 'Open navigation list view' ) } | ||
onClick={ () => openGeneralSidebar( 'edit-post/block' ) } | ||
icon={ listView } | ||
/> | ||
</ToolbarGroup> | ||
); | ||
}; | ||
|
||
let MaybeNavMenuSidebarToggle = Fragment; | ||
|
||
const isOffCanvasNavigationEditorEnabled = | ||
window?.__experimentalEnableOffCanvasNavigationEditor === true; | ||
|
||
if ( isOffCanvasNavigationEditorEnabled ) { | ||
MaybeNavMenuSidebarToggle = NavMenuSidebarToggle; | ||
} | ||
|
||
const NavigationEditMenuItem = () => { | ||
return ( | ||
<BlockEditorProvider> | ||
<__unstableBlockToolbarLastItem> | ||
<__unstableBlockNameContext.Consumer> | ||
{ ( blockName ) => | ||
blockName === 'core/navigation' && ( | ||
<MaybeNavMenuSidebarToggle /> | ||
) | ||
} | ||
</__unstableBlockNameContext.Consumer> | ||
</__unstableBlockToolbarLastItem> | ||
</BlockEditorProvider> | ||
); | ||
}; | ||
|
||
export default NavigationEditMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters