2020-10-13 01:40:53 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-04-23 03:44:54 +00:00
|
|
|
import { NavigationItem, useSlot } from '@woocommerce/experimental';
|
2020-12-02 18:16:54 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-04-23 03:44:54 +00:00
|
|
|
import { WooNavigationItem } from '@woocommerce/navigation';
|
2020-10-13 01:40:53 +00:00
|
|
|
|
|
|
|
const Item = ( { item } ) => {
|
2021-04-23 03:44:54 +00:00
|
|
|
const slot = useSlot( 'woocommerce_navigation_' + item.id );
|
2020-10-13 01:40:53 +00:00
|
|
|
const hasFills = Boolean( slot.fills && slot.fills.length );
|
|
|
|
|
2020-12-02 18:16:54 +00:00
|
|
|
const trackClick = ( id ) => {
|
|
|
|
recordEvent( 'navigation_click', {
|
|
|
|
menu_item: id,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Disable reason: The div wrapping the slot item is used for tracking purposes
|
|
|
|
// and should not be a tabbable element.
|
|
|
|
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
|
|
|
2020-10-13 01:40:53 +00:00
|
|
|
// Only render a slot if a coresponding Fill exists and the item is not a category
|
|
|
|
if ( hasFills && ! item.isCategory ) {
|
2020-10-22 03:01:25 +00:00
|
|
|
return (
|
|
|
|
<NavigationItem key={ item.id } item={ item.id }>
|
2020-12-02 18:16:54 +00:00
|
|
|
<div onClick={ () => trackClick( item.id ) }>
|
|
|
|
<WooNavigationItem.Slot name={ item.id } />
|
|
|
|
</div>
|
2020-10-22 03:01:25 +00:00
|
|
|
</NavigationItem>
|
|
|
|
);
|
2020-10-13 01:40:53 +00:00
|
|
|
}
|
2020-10-22 03:01:25 +00:00
|
|
|
|
2020-10-13 01:40:53 +00:00
|
|
|
return (
|
|
|
|
<NavigationItem
|
|
|
|
key={ item.id }
|
|
|
|
item={ item.id }
|
|
|
|
title={ item.title }
|
|
|
|
href={ item.url }
|
|
|
|
navigateToMenu={ ! item.url && item.id }
|
2020-12-02 18:16:54 +00:00
|
|
|
onClick={ () => trackClick( item.id ) }
|
2021-02-15 21:33:51 +00:00
|
|
|
hideIfTargetMenuEmpty
|
2020-10-13 01:40:53 +00:00
|
|
|
/>
|
|
|
|
);
|
2020-12-02 18:16:54 +00:00
|
|
|
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
|
2020-10-13 01:40:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|