-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create new menu button to nav block (#36245)
* Adds a create new button to navigation block * Keep it simple
- Loading branch information
Showing
2 changed files
with
34 additions
and
17 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
42 changes: 25 additions & 17 deletions
42
packages/block-library/src/navigation/edit/navigation-menu-selector.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 |
---|---|---|
@@ -1,34 +1,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { MenuGroup, MenuItemsChoice } from '@wordpress/components'; | ||
import { MenuGroup, MenuItem, MenuItemsChoice } from '@wordpress/components'; | ||
import { useEntityId } from '@wordpress/core-data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useNavigationMenu from '../use-navigation-menu'; | ||
|
||
export default function NavigationMenuSelector( { onSelect } ) { | ||
export default function NavigationMenuSelector( { onSelect, onCreateNew } ) { | ||
const { navigationMenus } = useNavigationMenu(); | ||
const navigationMenuId = useEntityId( 'postType', 'wp_navigation' ); | ||
|
||
return ( | ||
<MenuGroup> | ||
<MenuItemsChoice | ||
value={ navigationMenuId } | ||
onSelect={ ( selectedId ) => | ||
onSelect( | ||
navigationMenus.find( | ||
( post ) => post.id === selectedId | ||
<> | ||
<MenuGroup> | ||
<MenuItemsChoice | ||
value={ navigationMenuId } | ||
onSelect={ ( selectedId ) => | ||
onSelect( | ||
navigationMenus.find( | ||
( post ) => post.id === selectedId | ||
) | ||
) | ||
) | ||
} | ||
choices={ navigationMenus.map( ( { id, title } ) => ( { | ||
value: id, | ||
label: title.rendered, | ||
} ) ) } | ||
/> | ||
</MenuGroup> | ||
} | ||
choices={ navigationMenus.map( ( { id, title } ) => ( { | ||
value: id, | ||
label: title.rendered, | ||
} ) ) } | ||
/> | ||
</MenuGroup> | ||
<MenuGroup> | ||
<MenuItem onClick={ onCreateNew }> | ||
{ __( 'Create new menu' ) } | ||
</MenuItem> | ||
</MenuGroup> | ||
</> | ||
); | ||
} |