@shopgate/engage
Version:
Shopgate's ENGAGE library.
6 lines • 1.65 kB
JavaScript
import*as React from'react';import PropTypes from'prop-types';import classNames from'classnames';import{AVAILABILITY_STATE_OK,AVAILABILITY_STATE_WARNING,AVAILABILITY_STATE_ALERT}from'@shopgate/pwa-common-commerce/product/constants';import{SurroundPortals,PlaceholderLabel,Availability as AvailableText}from'@shopgate/engage/components';import{PRODUCT_AVAILABILITY}from'@shopgate/engage/product';import{hasNewServices}from'@shopgate/engage/core/helpers';import connect from"./Availability.connector";import{placeholder,availability as availabilityStyle}from"./Availability.style";/**
* The Availability component.
* @param {Object} props The component props.
* @return {JSX}
*/function Availability(_ref){var availability=_ref.availability,fulfillmentMethods=_ref.fulfillmentMethods,fulfillmentSelection=_ref.fulfillmentSelection,className=_ref.className;// Render only when no fulfillment methods are available or when the given method exists
if(hasNewServices()&&(!fulfillmentMethods||fulfillmentMethods.indexOf(fulfillmentSelection)!==-1)){return null;}var classes=classNames(placeholder,className?className.toString():null);return React.createElement(SurroundPortals,{portalName:PRODUCT_AVAILABILITY,portalProps:{availability:availability}},React.createElement(PlaceholderLabel,{className:classes,ready:availability!==null},availability&&React.createElement(AvailableText,{className:availabilityStyle,showWhenAvailable:true,text:availability.text||'',state:availability.state})));}Availability.defaultProps={availability:null,fulfillmentMethods:null,fulfillmentSelection:'',className:null};export default connect(React.memo(Availability));