@shopgate/engage
Version:
Shopgate's ENGAGE library.
7 lines • 2.55 kB
JavaScript
import React,{useMemo}from'react';import{css}from'glamor';import PropTypes from'prop-types';import{connect}from'react-redux';import{hasNewServices,i18n}from'@shopgate/engage/core/helpers';import{useWidgetSettings}from'@shopgate/engage/core/hooks';import{withCurrentProduct,withWidgetSettings}from'@shopgate/engage/core/hocs';import{Section}from'@shopgate/engage/a11y/components';import{makeGetCurrentProductPropertyByLabel}from'@shopgate/engage/product/selectors/product';import ProductUnitQuantityPicker from"./ProductUnitQuantityPicker";import OrderQuantityHint from"../OrderQuantityHint";var styles={quantityPicker:css({display:'flex',flexDirection:'column'}).toString(),quantityPickerPicker:css({width:'100%'}).toString(),quantityHint:css({'&:not(:empty)':{paddingTop:8,marginBottom:-4}}).toString()};/**
* A Quantity Picker with unit support.
* @returns {JSX.Element}
*/var UnitQuantityPickerWithSection=function UnitQuantityPickerWithSection(_ref){var productId=_ref.productId,variantId=_ref.variantId,productProperty=_ref.productProperty;var _useWidgetSettings=useWidgetSettings('@shopgate/engage/product/components/UnitQuantityPicker'),_useWidgetSettings$sh=_useWidgetSettings.show,show=_useWidgetSettings$sh===void 0?hasNewServices():_useWidgetSettings$sh;var quantityLabel=useMemo(function(){var _ref2;if(!show){return null;}var label=i18n.text('product.sections.quantity');if(((_ref2=productProperty===null||productProperty===void 0?void 0:productProperty.value)!==null&&_ref2!==void 0?_ref2:'')!==''){label=productProperty.value;}return label;},[productProperty,show]);if(!show){return null;}return React.createElement(Section,{title:"product.sections.quantity"},React.createElement(ProductUnitQuantityPicker,{className:styles.quantityPicker,classes:{picker:styles.quantityPickerPicker},size:"large",quantityLabel:quantityLabel,hideHeadline:true},React.createElement(OrderQuantityHint,{productId:variantId||productId,className:styles.quantityHint})));};UnitQuantityPickerWithSection.defaultProps={productId:null,variantId:null,productProperty:null};/**
* Creates the mapStateToProps connector function.
* @returns {Function}
*/var makeMapStateToProps=function makeMapStateToProps(){var getCurrentProductPropertyByLabel=makeGetCurrentProductPropertyByLabel();return function(state,props){return{productProperty:getCurrentProductPropertyByLabel(state,props)};};};export default withWidgetSettings(withCurrentProduct(connect(makeMapStateToProps)(UnitQuantityPickerWithSection)),'@shopgate/engage/product/components/UnitQuantityPicker');