| class CooperativeHeader extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| display: block; | |
| width: 100%; | |
| position: sticky; | |
| top: 0; | |
| z-index: 50; | |
| backdrop-filter: blur(10px); | |
| background: rgba(255, 255, 255, 0.9); | |
| border-bottom: 1px solid rgba(0, 0, 0, 0.1); | |
| } | |
| .header-container { | |
| max-width: 1280px; | |
| margin: 0 auto; | |
| padding: 1rem 1.5rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .logo { | |
| display: flex; | |
| align-items: center; | |
| text-decoration: none; | |
| font-weight: bold; | |
| font-size: 1.5rem; | |
| color: #1f2937; | |
| } | |
| .logo-icon { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| width: 40px; | |
| height: 40px; | |
| background: linear-gradient(135deg, #3B82F6, #10B981); | |
| border-radius: 10px; | |
| margin-right: 0.75rem; | |
| color: white; | |
| } | |
| .nav-links { | |
| display: none; | |
| } | |
| .nav-links a { | |
| color: #4b5563; | |
| text-decoration: none; | |
| font-weight: 500; | |
| padding: 0.5rem 1rem; | |
| border-radius: 0.5rem; | |
| transition: all 0.2s; | |
| display: flex; | |
| align-items: center; | |
| } | |
| .nav-links a i { | |
| margin-right: 0.5rem; | |
| width: 1.125rem; | |
| height: 1.125rem; | |
| } | |
| .nav-links a:hover { | |
| color: #3B82F6; | |
| background-color: #eff6ff; | |
| } | |
| .nav-links a.active { | |
| color: #3B82F6; | |
| background-color: #eff6ff; | |
| } | |
| .mobile-menu-btn { | |
| background: none; | |
| border: none; | |
| padding: 0.5rem; | |
| color: #4b5563; | |
| cursor: pointer; | |
| border-radius: 0.5rem; | |
| } | |
| .mobile-menu-btn:hover { | |
| background-color: #f3f4f6; | |
| } | |
| .mobile-menu { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: white; | |
| z-index: 100; | |
| padding: 2rem; | |
| transform: translateX(100%); | |
| transition: transform 0.3s ease; | |
| } | |
| .mobile-menu.active { | |
| transform: translateX(0); | |
| } | |
| .mobile-menu-header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 2rem; | |
| } | |
| .mobile-nav-links { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 1rem; | |
| } | |
| .mobile-nav-links a { | |
| color: #1f2937; | |
| text-decoration: none; | |
| font-weight: 500; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| display: flex; | |
| align-items: center; | |
| font-size: 1.125rem; | |
| } | |
| .mobile-nav-links a:hover { | |
| background-color: #f3f4f6; | |
| } | |
| .mobile-nav-links a i { | |
| margin-right: 1rem; | |
| width: 1.25rem; | |
| height: 1.25rem; | |
| } | |
| .mobile-menu-overlay { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: rgba(0, 0, 0, 0.5); | |
| z-index: 99; | |
| opacity: 0; | |
| pointer-events: none; | |
| transition: opacity 0.3s ease; | |
| } | |
| .mobile-menu-overlay.active { | |
| opacity: 1; | |
| pointer-events: all; | |
| } | |
| @media (min-width: 768px) { | |
| .nav-links { | |
| display: flex; | |
| gap: 0.5rem; | |
| } | |
| .mobile-menu-btn { | |
| display: none; | |
| } | |
| } | |
| @media (min-width: 1024px) { | |
| .nav-links { | |
| gap: 1rem; | |
| } | |
| } | |
| </style> | |
| <div class="header-container"> | |
| <a href="/" class="logo"> | |
| <div class="logo-icon"> | |
| <i data-feather="star"></i> | |
| </div> | |
| <span>Cooperative Constellation</span> | |
| </a> | |
| <nav class="nav-links"> | |
| <a href="/" class="active"> | |
| <i data-feather="home"></i> | |
| Home | |
| </a> | |
| <a href="cooperatives.html"> | |
| <i data-feather="users"></i> | |
| Cooperatives | |
| </a> | |
| <a href="network.html"> | |
| <i data-feather="globe"></i> | |
| Network | |
| </a> | |
| <a href="resources.html"> | |
| <i data-feather="book"></i> | |
| Resources | |
| </a> | |
| <a href="about.html"> | |
| <i data-feather="info"></i> | |
| About | |
| </a> | |
| <a href="join.html" class="bg-primary-500 text-white hover:bg-primary-600 px-4 py-2 rounded-lg"> | |
| <i data-feather="plus-circle"></i> | |
| Join Us | |
| </a> | |
| </nav> | |
| <button class="mobile-menu-btn" aria-label="Open menu"> | |
| <i data-feather="menu"></i> | |
| </button> | |
| <div class="mobile-menu-overlay"></div> | |
| <div class="mobile-menu"> | |
| <div class="mobile-menu-header"> | |
| <a href="/" class="logo"> | |
| <div class="logo-icon"> | |
| <i data-feather="star"></i> | |
| </div> | |
| <span>Cooperative Constellation</span> | |
| </a> | |
| <button class="mobile-menu-close" aria-label="Close menu"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </div> | |
| <nav class="mobile-nav-links"> | |
| <a href="/"> | |
| <i data-feather="home"></i> | |
| Home | |
| </a> | |
| <a href="cooperatives.html"> | |
| <i data-feather="users"></i> | |
| Cooperatives | |
| </a> | |
| <a href="network.html"> | |
| <i data-feather="globe"></i> | |
| Network | |
| </a> | |
| <a href="resources.html"> | |
| <i data-feather="book"></i> | |
| Resources | |
| </a> | |
| <a href="about.html"> | |
| <i data-feather="info"></i> | |
| About | |
| </a> | |
| <a href="join.html" style="background-color: #3B82F6; color: white;"> | |
| <i data-feather="plus-circle"></i> | |
| Join Our Network | |
| </a> | |
| </nav> | |
| </div> | |
| </div> | |
| `; | |
| this.initializeMobileMenu(); | |
| this.updateActiveLink(); | |
| } | |
| initializeMobileMenu() { | |
| const menuBtn = this.shadowRoot.querySelector('.mobile-menu-btn'); | |
| const closeBtn = this.shadowRoot.querySelector('.mobile-menu-close'); | |
| const mobileMenu = this.shadowRoot.querySelector('.mobile-menu'); | |
| const overlay = this.shadowRoot.querySelector('.mobile-menu-overlay'); | |
| const mobileLinks = this.shadowRoot.querySelectorAll('.mobile-nav-links a'); | |
| const openMenu = () => { | |
| mobileMenu.classList.add('active'); | |
| overlay.classList.add('active'); | |
| document.body.style.overflow = 'hidden'; | |
| }; | |
| const closeMenu = () => { | |
| mobileMenu.classList.remove('active'); | |
| overlay.classList.remove('active'); | |
| document.body.style.overflow = ''; | |
| }; | |
| menuBtn.addEventListener('click', openMenu); | |
| closeBtn.addEventListener('click', closeMenu); | |
| overlay.addEventListener('click', closeMenu); | |
| mobileLinks.forEach(link => { | |
| link.addEventListener('click', closeMenu); | |
| }); | |
| } | |
| updateActiveLink() { | |
| const currentPath = window.location.pathname; | |
| const navLinks = this.shadowRoot.querySelectorAll('.nav-links a, .mobile-nav-links a'); | |
| navLinks.forEach(link => { | |
| const href = link.getAttribute('href'); | |
| if (href === currentPath || (href === '/' && currentPath.endsWith('/'))) { | |
| link.classList.add('active'); | |
| } else { | |
| link.classList.remove('active'); | |
| } | |
| }); | |
| } | |
| } | |
| customElements.define('cooperative-header', CooperativeHeader); |