UNPKG

@shopgate/engage

Version:
58 lines (57 loc) 2.3 kB
import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Portal, I18n, PlaceholderLabel, PriceStriked as StrikePrice } from '@shopgate/engage/components'; import { PRODUCT_PRICE_STRIKED, PRODUCT_PRICE_STRIKED_AFTER, PRODUCT_PRICE_STRIKED_BEFORE } from '@shopgate/engage/product/constants'; import { withPriceCalculation } from '@shopgate/engage/product/hocs'; import { useWidgetSettings } from '@shopgate/engage/core/hooks'; import connect from "./connector"; import styles from "./style"; /** * The PriceStriked component. * @param {Object} props The component props. * @return {JSX} */ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; const PriceStriked = ({ price }) => { const { msrpLabel = 'price.msrp', unitPriceStrikedLabel } = useWidgetSettings('@shopgate/engage/product/components/Header/PriceStriked'); return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Portal, { name: PRODUCT_PRICE_STRIKED_BEFORE }), /*#__PURE__*/_jsx(Portal, { name: PRODUCT_PRICE_STRIKED, children: /*#__PURE__*/_jsxs(PlaceholderLabel, { className: styles.placeholder, ready: price !== null, children: [price && price.msrp > 0 && price.unitPrice !== price.msrp && /*#__PURE__*/_jsxs(_Fragment, { children: [!!msrpLabel && /*#__PURE__*/_jsx(I18n.Text, { string: msrpLabel, className: styles.msrp }), /*#__PURE__*/_jsx(StrikePrice, { className: styles.msrpStriked, value: price.msrp, currency: price.currency })] }), price && !price.msrp && price.unitPriceStriked > 0 && price.unitPrice !== price.unitPriceStriked && /*#__PURE__*/_jsxs(_Fragment, { children: [!!unitPriceStrikedLabel && /*#__PURE__*/_jsx(I18n.Text, { string: unitPriceStrikedLabel, className: styles.msrp }), /*#__PURE__*/_jsx(StrikePrice, { value: price.unitPriceStriked, currency: price.currency })] })] }) }), /*#__PURE__*/_jsx(Portal, { name: PRODUCT_PRICE_STRIKED_AFTER })] }); }; PriceStriked.defaultProps = { price: null }; export default connect(withPriceCalculation(PriceStriked));