-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.jsx
64 lines (58 loc) · 1.95 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
55
56
57
58
59
60
61
62
63
64
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import Portal from '@shopgate/pwa-common/components/Portal';
import * as portals from '@shopgate/pwa-common-commerce/cart/constants/Portals';
import Price from '@shopgate/pwa-ui-shared/Price';
import PriceStriked from '@shopgate/pwa-ui-shared/PriceStriked';
import styles from './style';
/**
* The Cart Product Price component.
* @param {Object} props The component props.
* @param {Object} context The component context.
* @returns {JSX}
*/
const ProductPrice = ({ currency, defaultPrice, specialPrice }, context) => {
const hasStrikePrice = typeof specialPrice === 'number';
const price = hasStrikePrice ? specialPrice : defaultPrice;
return (
<Fragment>
{hasStrikePrice && (
<Fragment>
<Portal name={portals.CART_ITEM_PRICE_STRIKED_BEFORE} props={context} />
<Portal name={portals.CART_ITEM_PRICE_STRIKED} props={context}>
<PriceStriked
className={styles.priceStriked}
value={defaultPrice}
currency={currency}
/>
</Portal>
<Portal name={portals.CART_ITEM_PRICE_STRIKED_AFTER} props={context} />
</Fragment>
)}
<Portal name={portals.CART_ITEM_PRICE_BEFORE} props={context} />
<Portal name={portals.CART_ITEM_PRICE} props={context}>
<Price
className={styles.price}
currency={currency}
discounted={hasStrikePrice}
taxDisclaimer
unitPrice={price}
/>
</Portal>
<Portal name={portals.CART_ITEM_PRICE_AFTER} props={context} />
</Fragment>
);
};
ProductPrice.propTypes = {
currency: PropTypes.string.isRequired,
defaultPrice: PropTypes.number.isRequired,
specialPrice: PropTypes.number,
};
ProductPrice.defaultProps = {
specialPrice: null,
};
ProductPrice.contextTypes = {
cartItemId: PropTypes.string,
type: PropTypes.string,
};
export default ProductPrice;