| 1 |
import './menu.scss'; |
| 2 |
import Button from '../molecules/button'; |
| 3 |
import router from '@elementor/router'; |
| 4 |
import { Match, LocationProvider } from '@reach/router'; |
| 5 |
|
| 6 |
export default function Menu( props ) { |
| 7 |
const ActionButton = ( itemProps ) => { |
| 8 |
if ( ! props.actionButton ) { |
| 9 |
return ''; |
| 10 |
} |
| 11 |
|
| 12 |
return props.actionButton( itemProps ); |
| 13 |
}; |
| 14 |
|
| 15 |
if ( props.promotion ) { |
| 16 |
return ( |
| 17 |
<nav className="eps-menu"> |
| 18 |
{ props.children } |
| 19 |
<ul> |
| 20 |
{ props.menuItems.map( ( item ) => ( |
| 21 |
<li key={ item.type } className="eps-menu-item"> |
| 22 |
<Button text={ item.title } className="eps-menu-item__link" { ...item } /> |
| 23 |
<ActionButton { ...item } /> |
| 24 |
</li> |
| 25 |
) ) } |
| 26 |
</ul> |
| 27 |
</nav> |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
return ( |
| 32 |
<LocationProvider history={ router.appHistory }> |
| 33 |
<nav className="eps-menu"> |
| 34 |
{ props.children } |
| 35 |
<ul> |
| 36 |
{ ( |
| 37 |
props.menuItems.map( ( item ) => ( |
| 38 |
<Match key={ item.type } path={ item.url }> |
| 39 |
{ ( { match } ) => { |
| 40 |
return ( |
| 41 |
<li key={ item.type } className={ `eps-menu-item${ match ? ' eps-menu-item--active' : '' }` }> |
| 42 |
<Button text={ item.title } className="eps-menu-item__link" { ...item } /> |
| 43 |
<ActionButton { ...item } /> |
| 44 |
</li> |
| 45 |
); |
| 46 |
} } |
| 47 |
</Match> |
| 48 |
) ) |
| 49 |
) } |
| 50 |
</ul> |
| 51 |
</nav> |
| 52 |
</LocationProvider> |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
Menu.propTypes = { |
| 57 |
menuItems: PropTypes.arrayOf( PropTypes.object ), |
| 58 |
children: PropTypes.any, |
| 59 |
actionButton: PropTypes.func, |
| 60 |
promotion: PropTypes.bool, |
| 61 |
}; |
| 62 |
|