@shopgate/engage
Version:
Shopgate's ENGAGE library.
4 lines • 1.51 kB
JavaScript
import React,{useCallback}from'react';import PropTypes from'prop-types';import{css}from'glamor';import{i18n}from'@shopgate/engage/core';import{Toggle}from'@shopgate/engage/components';import{ELEMENT_ID_SHIPPING_CONTACT_TOGGLE}from"../../constants";import{useRegistration}from"../../hooks";var styles={root:css({display:'flex',justifyContent:'space-between',paddingBottom:24}).toString(),label:css({paddingRight:8}).toString()};/**
* @param {Object} props The component props
* @returns {JSX.Element}
*/var RegistrationFormToggle=function RegistrationFormToggle(_ref){var isGuest=_ref.isGuest;var _useRegistration=useRegistration(isGuest),isShippingAddressSelectionEnabled=_useRegistration.isShippingAddressSelectionEnabled,isShippingFormVisible=_useRegistration.isShippingFormVisible,setIsShippingFormVisible=_useRegistration.setIsShippingFormVisible;var handleChange=useCallback(function(e){setIsShippingFormVisible(e.target.checked);},[setIsShippingFormVisible]);if(!isShippingAddressSelectionEnabled){return null;}return React.createElement("div",{className:styles.root,id:ELEMENT_ID_SHIPPING_CONTACT_TOGGLE},React.createElement("label",{"aria-hidden":true,className:styles.label,htmlFor:"toggle-shipping-form",id:"toggle-shipping-form-label"},i18n.text('registration.different_shipping_address_label')),React.createElement(Toggle,{id:"toggle-shipping-form",checked:isShippingFormVisible,onChange:handleChange}));};RegistrationFormToggle.defaultProps={isGuest:false};export default RegistrationFormToggle;