-
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 Screen: Consolidate menu name and switcher (#34786)
* Navigation Screen: Consolidate menu name and switcher * Update E2E test selectors * Use MenuSwitcher * Update dropdown z-index styles * Style menu switcher's new button * Hide top level 'New menu' button on small screens * Render minimal header when menu isn't selected * Add explaining comment for menu item group style reset * Try better name for file and component
- Loading branch information
Showing
8 changed files
with
204 additions
and
89 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
80 changes: 80 additions & 0 deletions
80
packages/edit-navigation/src/components/header/menu-actions.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,80 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
DropdownMenu, | ||
__experimentalText as Text, | ||
} from '@wordpress/components'; | ||
import { chevronDown } from '@wordpress/icons'; | ||
import { useRef } from '@wordpress/element'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import MenuSwitcher from '../menu-switcher'; | ||
import { useMenuEntityProp, useSelectedMenuId } from '../../hooks'; | ||
|
||
export default function MenuActions( { menus, isLoading } ) { | ||
const [ selectedMenuId, setSelectedMenuId ] = useSelectedMenuId(); | ||
const [ menuName ] = useMenuEntityProp( 'name', selectedMenuId ); | ||
|
||
// The title ref is passed to the popover as the anchorRef so that the | ||
// dropdown is centered over the whole title area rather than just one | ||
// part of it. | ||
const titleRef = useRef(); | ||
|
||
if ( isLoading ) { | ||
return ( | ||
<div className="edit-navigation-menu-actions"> | ||
{ __( 'Loading…' ) } | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="edit-navigation-menu-actions"> | ||
<div | ||
ref={ titleRef } | ||
className="edit-navigation-menu-actions__subtitle-wrapper" | ||
> | ||
<Text | ||
size="body" | ||
className="edit-navigation-menu-actions__subtitle" | ||
as="h2" | ||
> | ||
{ decodeEntities( menuName ) } | ||
</Text> | ||
|
||
<DropdownMenu | ||
icon={ chevronDown } | ||
toggleProps={ { | ||
label: __( 'Switch menu' ), | ||
className: | ||
'edit-navigation-menu-actions__switcher-toggle', | ||
showTooltip: false, | ||
__experimentalIsFocusable: true, | ||
} } | ||
popoverProps={ { | ||
className: | ||
'edit-navigation-menu-actions__switcher-dropdown', | ||
position: 'bottom center', | ||
anchorRef: titleRef.current, | ||
} } | ||
> | ||
{ ( { onClose } ) => ( | ||
<MenuSwitcher | ||
menus={ menus } | ||
selectedMenuId={ selectedMenuId } | ||
onSelectMenu={ ( menuId ) => { | ||
setSelectedMenuId( menuId ); | ||
onClose(); | ||
} } | ||
/> | ||
) } | ||
</DropdownMenu> | ||
</div> | ||
</div> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/edit-navigation/src/components/header/new-button.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,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, Modal } from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AddMenu from '../add-menu'; | ||
import { useSelectedMenuId } from '../../hooks'; | ||
|
||
export default function NewButton( { menus } ) { | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
const [ , setSelectedMenuId ] = useSelectedMenuId(); | ||
|
||
return ( | ||
<> | ||
<Button variant="tertiary" onClick={ () => setIsModalOpen( true ) }> | ||
{ __( 'New menu' ) } | ||
</Button> | ||
{ isModalOpen && ( | ||
<Modal | ||
title={ __( 'Create a new menu' ) } | ||
onRequestClose={ () => setIsModalOpen( false ) } | ||
> | ||
<AddMenu | ||
menus={ menus } | ||
helpText={ __( | ||
'A short descriptive name for your menu.' | ||
) } | ||
onCreate={ ( menuId ) => { | ||
setIsModalOpen( false ); | ||
setSelectedMenuId( menuId ); | ||
} } | ||
/> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.