forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Navigation Menus to Template Parts screen sidebar in Browse Mode (W…
…ordPress#51492) * Proof of concept * Rename function Addresses WordPress#51492 (comment) * Space docblocks * Update packages/edit-site/src/components/sidebar-navigation-screen-template-part/template-part-navigation-menus.js * Update packages/edit-site/src/components/sidebar-navigation-screen-template-part/template-part-navigation-menu.js * remove unneeded comment * Output a string when a navigation has no title --------- Co-authored-by: Ben Dwyer <[email protected]>
- Loading branch information
1 parent
90af07b
commit ff8ddd9
Showing
9 changed files
with
182 additions
and
13 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
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
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
3 changes: 3 additions & 0 deletions
3
packages/edit-site/src/components/sidebar-navigation-screen-template-part/style.scss
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,3 @@ | ||
.edit-site-sidebar-navigation-screen-template-part-navigation-menu__title.components-heading { | ||
margin-bottom: $grid-unit-10; | ||
} |
28 changes: 28 additions & 0 deletions
28
...onents/sidebar-navigation-screen-template-part/template-part-navigation-menu-list-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,28 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SidebarNavigationItem from '../sidebar-navigation-item'; | ||
import { useLink } from '../routes/link'; | ||
|
||
export default function TemplatePartNavigationMenuListItem( { id } ) { | ||
const [ title ] = useEntityProp( 'postType', 'wp_navigation', 'title', id ); | ||
|
||
const linkInfo = useLink( { | ||
postId: id, | ||
postType: 'wp_navigation', | ||
} ); | ||
|
||
if ( ! id ) return null; | ||
|
||
return ( | ||
<SidebarNavigationItem withChevron { ...linkInfo }> | ||
{ title || __( '(no title)' ) } | ||
</SidebarNavigationItem> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
.../components/sidebar-navigation-screen-template-part/template-part-navigation-menu-list.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,21 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplatePartNavigationMenuListItem from './template-part-navigation-menu-list-item'; | ||
|
||
export default function TemplatePartNavigationMenuList( { menus } ) { | ||
return ( | ||
<ItemGroup className="edit-site-sidebar-navigation-screen-template-part-navigation-menu-list"> | ||
{ menus.map( ( menuId ) => ( | ||
<TemplatePartNavigationMenuListItem | ||
key={ menuId } | ||
id={ menuId } | ||
/> | ||
) ) } | ||
</ItemGroup> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
...e/src/components/sidebar-navigation-screen-template-part/template-part-navigation-menu.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,30 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __experimentalHeading as Heading } from '@wordpress/components'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationMenuEditor from '../sidebar-navigation-screen-navigation-menu/navigation-menu-editor'; | ||
|
||
export default function TemplatePartNavigationMenu( { id } ) { | ||
const [ title ] = useEntityProp( 'postType', 'wp_navigation', 'title', id ); | ||
|
||
if ( ! id ) return null; | ||
|
||
return ( | ||
<> | ||
<Heading | ||
className="edit-site-sidebar-navigation-screen-template-part-navigation-menu__title" | ||
size="12" | ||
upperCase={ true } | ||
> | ||
{ title || __( 'Navigation' ) } | ||
</Heading> | ||
<NavigationMenuEditor navigationMenuId={ id } /> | ||
</> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
.../src/components/sidebar-navigation-screen-template-part/template-part-navigation-menus.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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __experimentalHeading as Heading } from '@wordpress/components'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplatePartNavigationMenu from './template-part-navigation-menu'; | ||
import TemplatePartNavigationMenuList from './template-part-navigation-menu-list'; | ||
|
||
export default function TemplatePartNavigationMenus( { menus } ) { | ||
if ( ! menus.length ) return null; | ||
|
||
// if there is a single menu then render TemplatePartNavigationMenu | ||
if ( menus.length === 1 ) { | ||
return <TemplatePartNavigationMenu id={ menus[ 0 ] } />; | ||
} | ||
|
||
// if there are multiple menus then render TemplatePartNavigationMenuList | ||
return ( | ||
<> | ||
<Heading | ||
className="edit-site-sidebar-navigation-screen-template-part-navigation-menu__title" | ||
size="12" | ||
upperCase={ true } | ||
> | ||
{ __( 'Navigation' ) } | ||
</Heading> | ||
<TemplatePartNavigationMenuList menus={ menus } /> | ||
</> | ||
); | ||
} |
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