@shopgate/engage
Version:
Shopgate's ENGAGE library.
39 lines (38 loc) • 1.28 kB
JavaScript
import * as React from 'react';
import PropTypes from 'prop-types';
import { COUPON_TYPE_FIXED, COUPON_TYPE_PERCENTAGE } from '@shopgate/pwa-common-commerce/cart';
import Price from '@shopgate/pwa-ui-shared/Price';
import styles from "./CartItemCouponPrice.style";
/**
* @typedef {import('../../cart.types').SavedPrice} SavedPrice
*/
/**
* The Coupon Price component.
* @param {Object} props The component properties.
* @param {string} props.currency The currency to display.
* @param {SavedPrice} props.savedPrice The saved price details.
* @param {string} props.savedPrice.type The type of the saved price (fixed or percentage).
* @param {number} props.savedPrice.value The value of the saved price.
* @returns {JSX.Element|null}
*/
import { jsx as _jsx } from "react/jsx-runtime";
export const CartItemCouponPrice = /*#__PURE__*/React.memo(({
currency,
savedPrice
}) => {
if (savedPrice.type === COUPON_TYPE_FIXED) {
return /*#__PURE__*/_jsx(Price, {
className: styles,
currency: currency,
discounted: true,
unitPrice: -savedPrice.value
});
}
if (savedPrice.type === COUPON_TYPE_PERCENTAGE) {
return /*#__PURE__*/_jsx("span", {
className: styles,
children: `-${savedPrice.value}%`
});
}
return null;
});