@shopgate/engage
Version:
Shopgate's ENGAGE library.
64 lines (63 loc) • 2.11 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { SurroundPortals } from '@shopgate/engage/components';
import { CART_ITEM_TYPE_PRODUCT, CART_ITEM_TYPE_COUPON, CART_ITEM } from '@shopgate/pwa-common-commerce/cart';
import { ProductListEntryProvider } from '@shopgate/engage/product';
import CartItemProduct from "./CartItemProduct";
import CartItemCoupon from "./CartItemCoupon";
import CartItemProductProvider from "./CartItemProductProvider";
/**
* The cart item component.
* @param {Object} props The component props.
* @property {Object} props.item The cart item.
* @property {Function} props.onFocus A function to indicate when the item has been focussed.
* @property {boolean} [props.editable] Whether the item is editable.
* @property {string|null} [props.currencyOverride] The currency to use instead of the default one.
* @return {JSX.Element}
*/
import { jsx as _jsx } from "react/jsx-runtime";
function CartItem({
item,
onFocus,
editable,
currencyOverride
}) {
if (item.type !== CART_ITEM_TYPE_PRODUCT && item.type !== CART_ITEM_TYPE_COUPON) {
return null;
}
const props = {
item
};
const isProduct = item.type === CART_ITEM_TYPE_PRODUCT;
if (isProduct) {
return /*#__PURE__*/_jsx(ProductListEntryProvider, {
productId: item?.product?.id,
children: /*#__PURE__*/_jsx(SurroundPortals, {
portalName: CART_ITEM,
portalProps: props,
children: /*#__PURE__*/_jsx(CartItemProductProvider, {
cartItem: item,
onFocus: onFocus,
isEditable: editable,
currencyOverride: currencyOverride,
children: /*#__PURE__*/_jsx(CartItemProduct, {})
})
})
});
}
return /*#__PURE__*/_jsx(SurroundPortals, {
portalName: CART_ITEM,
portalProps: props,
children: /*#__PURE__*/_jsx(CartItemCoupon, {
id: item.id,
coupon: item.coupon,
messages: item.messages,
editable: editable
}, item.id)
});
}
CartItem.defaultProps = {
editable: true,
currencyOverride: null
};
export default /*#__PURE__*/React.memo(CartItem);