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 );
|
2021-05-11 16:36:56 +00:00
|
|
|
const hasFills = Boolean( slot?.fills?.length );
|
2020-10-13 01:40:53 +00:00
|
|
|
|
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 */
|
|
|
|
|
2023-05-08 07:55:09 +00:00
|
|
|
// Only render a slot if a corresponding Fill exists and the item is not a category
|
2020-10-13 01:40:53 +00:00
|
|
|
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 }
|
2021-11-02 19:00:21 +00:00
|
|
|
badge={ item.badge ? item.badge : null }
|
2020-10-13 01:40:53 +00:00
|
|
|
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;
|