File indexing completed on 2025-01-26 05:27:58
0001 import React , {useEffect, useState, useRef, useContext}from 'react' 0002 import {MetaheaderContext} from '../contexts/MetaheaderContext'; 0003 0004 const DomainsMenu_subdomain = () => { 0005 const {state} = useContext(MetaheaderContext); 0006 const [dropdownClass, setDropdownClass] = useState('test'); 0007 const toggleEl = useRef(null); 0008 0009 useEffect(() => { 0010 document.addEventListener('mousedown',handleClick, false); 0011 return () => { 0012 0013 document.removeEventListener('mousedown',handleClick, false); 0014 }; 0015 },[dropdownClass]) 0016 0017 const handleClick= e => { 0018 let cls = ""; 0019 if (toggleEl.current.contains(e.target)){ 0020 if (dropdownClass === "open"){ 0021 if (e.target.className === "domains-menu-link-item"){ 0022 cls = ""; 0023 } else { 0024 cls = "open"; 0025 } 0026 } else { 0027 cls = "open"; 0028 } 0029 } 0030 setDropdownClass(cls); 0031 } 0032 return ( 0033 <div ref={toggleEl} id="domains-dropdown-menu" className={dropdownClass}> 0034 <a className="domains-menu-link-item">{state.storeConfig.name} ⌄</a> 0035 <ul className="dropdown-menu dropdown-menu-right"> 0036 {state.domains.filter(domain=>domain.is_show_in_menu==1) 0037 .sort((a, b) => a.name > b.name? 1 : -1) 0038 .map((domain, index)=><li key={index}> 0039 <a href={domain.is_show_real_domain_as_url==1?'https://'+domain.host:state.baseUrlStore+'/s/'+domain.name}>{domain.name}</a></li>)} 0040 </ul> 0041 </div> 0042 ) 0043 } 0044 0045 export default DomainsMenu_subdomain