UNPKG

@shopgate/engage

Version:
9 lines 1.3 kB
import*as React from'react';import PropTypes from'prop-types';import{I18n}from"../../../components";/** * Renders the inventory given by the location into a given translation string. * @param {Object} props The component props. * @param {string} props.availabilityText The translation string to use. * @param {Object} props.location The component props. * @param {number|undefined} props.maxNumberVisible The component props. * @param {string} props.aboveMaxExtension The component props. * @return {JSX} */export function StockInfoInventory(props){var availabilityText=props.availabilityText,comingSoon=props.comingSoon,location=props.location,inventory=props.inventory,maxNumberVisible=props.maxNumberVisible,aboveMaxExtension=props.aboveMaxExtension;var visibleInventory=React.useMemo(function(){if(!location||!inventory){return null;}if(inventory.visible!==null&&inventory.visible>maxNumberVisible){return"".concat(maxNumberVisible).concat(aboveMaxExtension);}return inventory.visible;},[aboveMaxExtension,inventory,location,maxNumberVisible]);if((!location||!availabilityText||!inventory)&&!comingSoon){return null;}return React.createElement(I18n.Text,{string:availabilityText,params:{visibleInventory:visibleInventory}});}StockInfoInventory.defaultProps={comingSoon:false,inventory:null};