-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make nav components more atomic #24266
Changes from all commits
43c18f2
a4bbf76
ee380c5
f93fceb
9b7bc2f
937c3c7
3444b29
f93d0ad
e7c0011
53b85b2
7b68ca6
aca45b5
a5c4416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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; |
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>; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, good point. |
||
|
||
export default NavigationMenu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial state of
activeLevel
is going to be theactiveId
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
activeId
represents the item ID as opposed to the level ID. I renamed thisactiveItemId
for the time being but we can rename later if that's still confusing.