-
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.
Make nav components more atomic (#24266)
* Break nav components into smaller pieces * Get visible menu items based on menu id and active state * Allow null and root text in back button * Allow root text for navigation title * Add line break to make use of multiple menus more obvious * Fix back button case at root level * Remove secondary nav styling * Simplify component props * Pass parsed data back to navigation children * Move nav menu item logic into menu * Simplify nav components to bare essentials * Allow menu level navigation without changing active item * Handle PR feedback
- Loading branch information
Showing
6 changed files
with
148 additions
and
163 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 was deleted.
Oops, something went wrong.
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,51 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Icon, chevronRight } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from '../button'; | ||
import Text from '../text'; | ||
|
||
const NavigationMenuItem = ( props ) => { | ||
const { | ||
children, | ||
hasChildren, | ||
id, | ||
isActive, | ||
onClick, | ||
setActiveLevel, | ||
title, | ||
} = props; | ||
const classes = classnames( 'components-navigation__menu-item', { | ||
'is-active': isActive, | ||
} ); | ||
|
||
const handleClick = () => { | ||
if ( children.length ) { | ||
setActiveLevel( id ); | ||
return; | ||
} | ||
onClick( props ); | ||
}; | ||
|
||
return ( | ||
<li className={ classes }> | ||
<Button className={ classes } onClick={ handleClick }> | ||
<Text variant="body.small"> | ||
<span>{ title }</span> | ||
</Text> | ||
{ hasChildren ? <Icon icon={ chevronRight } /> : null } | ||
</Button> | ||
</li> | ||
); | ||
}; | ||
|
||
export default NavigationMenuItem; |
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,5 @@ | ||
const NavigationMenu = ( { children } ) => { | ||
return <ul className="components-navigation__menu">{ children }</ul>; | ||
}; | ||
|
||
export default NavigationMenu; |
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