-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.jsx
54 lines (49 loc) · 1.73 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import {
NAV_MENU_FAVORITES,
NAV_MENU_FAVORITES_AFTER,
NAV_MENU_FAVORITES_BEFORE,
} from '@shopgate/pwa-common-commerce/favorites/constants/Portals';
import { FAVORITES_PATH } from '@shopgate/pwa-common-commerce/favorites/constants';
import Portal from '@shopgate/pwa-common/components/Portal';
import HeartIcon from '@shopgate/pwa-ui-shared/icons/HeartIcon';
import { NavDrawer } from '@shopgate/pwa-ui-material';
import { i18n } from '@shopgate/engage/core';
import Badge from './components/Badge';
import connect from '../../../../connector';
import connectBadge from './components/Badge/connector';
import portalProps from '../../../../portalProps';
const LABEL = 'navigation.favorites';
/**
* @param {Function} props.navigate The navigate action.
* @param {Function} props.count The favorite list item count.
* @returns {JSX}
*/
const FavoritesButton = ({ navigate, count }) => {
const ariaLabel = `${i18n.text(LABEL)}. ${i18n.text('common.products')}: ${count}.`;
return (
<Fragment>
<Portal name={NAV_MENU_FAVORITES_BEFORE} props={portalProps} />
<Portal name={NAV_MENU_FAVORITES} props={portalProps}>
<NavDrawer.Item
badge={Badge}
label={LABEL}
aria-label={ariaLabel}
icon={HeartIcon}
onClick={navigate(FAVORITES_PATH, LABEL)}
testId="navDrawerFavoritesButton"
/>
</Portal>
<Portal name={NAV_MENU_FAVORITES_AFTER} props={portalProps} />
</Fragment>
);
};
FavoritesButton.propTypes = {
navigate: PropTypes.func.isRequired,
count: PropTypes.number,
};
FavoritesButton.defaultProps = {
count: 0,
};
export default connect(connectBadge(FavoritesButton));