@shopgate/engage
Version:
Shopgate's ENGAGE library.
20 lines • 6.33 kB
JavaScript
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import*as React from'react';import PT from'prop-types';import Transition from'react-transition-group/Transition';import{getAbsoluteHeight}from'@shopgate/pwa-common/helpers/dom';import{CART_PATH}from'@shopgate/pwa-common-commerce/cart/constants';import{CART_ITEM_TYPE_COUPON}from'@shopgate/pwa-common-commerce/cart';import{getPageSettings}from'@shopgate/engage/core/config';import{MessageBar,CardList}from'@shopgate/engage/components';import{container,cartItemTransitionDuration as duration,getCartItemTransitionStyle as getTransitionStyle}from"./CartItemCoupon.style";import{messagesContainerCard,messagesCard,messagesContainerLine,messagesLine}from"./CartItem.style";import connect from"./CartItemCoupon.connector";import{CartItemCouponLayout}from"./CartItemCouponLayout";var messageStyles={card:{container:messagesContainerCard,message:messagesCard},line:{container:messagesContainerLine,message:messagesLine}};/**
* The Coupon component.
*/var CartItemCoupon=/*#__PURE__*/function(_React$Component){/**
* Constructor.
* @param {Object} props The component props.
*/function CartItemCoupon(props){var _this2;_classCallCheck(this,CartItemCoupon);_this2=_callSuper(this,CartItemCoupon,[props]);/**
* Sets this coupon to be invisible via its state.
*/_defineProperty(_this2,"transitionOut",function(){_this2.setState({visible:false});});/**
* Deletes the coupon from the cart.
*/_defineProperty(_this2,"deleteCoupon",function(){_this2.props.deleteCoupon(_this2.props.id);});_this2.state={visible:true};return _this2;}/**
* Expose props to the descendant components to use them for the portals.
* @return {Object}
*/_inherits(CartItemCoupon,_React$Component);return _createClass(CartItemCoupon,[{key:"getChildContext",value:function getChildContext(){return{cartItemId:this.props.id,type:CART_ITEM_TYPE_COUPON,editable:this.props.editable};}/**
* We need to set the element height explicitly so that we can animate it later.
*/},{key:"componentDidMount",value:function componentDidMount(){this.transitionElement.style.height="".concat(getAbsoluteHeight(this.cardElement),"px");}/**
* We need to set the element height explicitly so that we can animate it later.
*/},{key:"componentDidUpdate",value:function componentDidUpdate(){this.transitionElement.style.height="".concat(getAbsoluteHeight(this.cardElement),"px");}},{key:"render",value:/**
* Render Function.
* @returns {JSX}
*/function render(){var _this3=this;var _getPageSettings=getPageSettings(CART_PATH),_getPageSettings$cart=_getPageSettings.cartItemsDisplay,cartItemsDisplay=_getPageSettings$cart===void 0?'line':_getPageSettings$cart;return React.createElement(Transition,{"in":this.state.visible,timeout:duration,onExited:this.deleteCoupon},function(state){return React.createElement("div",{ref:function ref(element){if(element)_this3.transitionElement=element;},key:_this3.props.id,style:getTransitionStyle(state)},React.createElement("div",{className:container,ref:function ref(element){if(element)_this3.cardElement=element;}},React.createElement(CardList.Item,null,_this3.props.messages.length>0&&React.createElement(MessageBar,{messages:_this3.props.messages,classNames:messageStyles[cartItemsDisplay]}),React.createElement(CartItemCouponLayout,{handleDelete:_this3.transitionOut,coupon:_this3.props.coupon,currency:_this3.props.currency}))));});}}]);}(React.Component);_defineProperty(CartItemCoupon,"childContextTypes",{cartItemId:PT.string,type:PT.string,editable:PT.bool});_defineProperty(CartItemCoupon,"defaultProps",{deleteCoupon:function deleteCoupon(){}});CartItemCoupon.defaultProps={editable:true};export default connect(CartItemCoupon);