Spaces:
Running
Running
Download components/navbar.js from CSNET/thairice-ndvi-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/spaces/CSNET/thairice-ndvi-visualizer/resolve/main/components/navbar.js
- Command line
-
hf download hf://spaces/CSNET/thairice-ndvi-visualizer/components/navbar.js
-
curl -L -o navbar.js https://huggingface.co/spaces/CSNET/thairice-ndvi-visualizer/resolve/main/components/navbar.js
11.9 kB
| class CustomNavbar extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| display: block; | |
| position: sticky; | |
| top: 0; | |
| z-index: 1000; | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; | |
| } | |
| .navbar { | |
| background: rgba(255, 255, 255, 0.95); | |
| backdrop-filter: blur(10px); | |
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); | |
| border-bottom: 1px solid rgba(16, 185, 129, 0.1); | |
| } | |
| .nav-container { | |
| max-width: 1280px; | |
| margin: 0 auto; | |
| padding: 0 1rem; | |
| } | |
| .nav-content { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| height: 4rem; | |
| } | |
| .logo { | |
| display: flex; | |
| align-items: center; | |
| gap: 0.75rem; | |
| text-decoration: none; | |
| color: #111827; | |
| font-weight: 700; | |
| font-size: 1.5rem; | |
| } | |
| .logo-icon { | |
| color: #10b981; | |
| width: 2rem; | |
| height: 2rem; | |
| } | |
| .nav-links { | |
| display: flex; | |
| align-items: center; | |
| gap: 2rem; | |
| } | |
| .nav-link { | |
| color: #4b5563; | |
| text-decoration: none; | |
| font-weight: 500; | |
| font-size: 0.95rem; | |
| padding: 0.5rem 0; | |
| position: relative; | |
| transition: color 0.2s ease; | |
| } | |
| .nav-link:hover { | |
| color: #10b981; | |
| } | |
| .nav-link.active { | |
| color: #10b981; | |
| } | |
| .nav-link.active::after { | |
| content: ''; | |
| position: absolute; | |
| bottom: 0; | |
| left: 0; | |
| right: 0; | |
| height: 2px; | |
| background: linear-gradient(90deg, #10b981, #059669); | |
| border-radius: 1px; | |
| } | |
| .mobile-menu-btn { | |
| display: none; | |
| background: none; | |
| border: none; | |
| color: #4b5563; | |
| cursor: pointer; | |
| padding: 0.5rem; | |
| border-radius: 0.375rem; | |
| } | |
| .mobile-menu-btn:hover { | |
| background: #f3f4f6; | |
| } | |
| .mobile-menu { | |
| display: none; | |
| background: white; | |
| border-top: 1px solid #e5e7eb; | |
| padding: 1rem; | |
| animation: slideDown 0.3s ease; | |
| } | |
| .mobile-nav-links { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| } | |
| .mobile-nav-link { | |
| color: #4b5563; | |
| text-decoration: none; | |
| padding: 0.75rem 1rem; | |
| border-radius: 0.5rem; | |
| font-weight: 500; | |
| transition: background-color 0.2s ease; | |
| } | |
| .mobile-nav-link:hover { | |
| background: #f3f4f6; | |
| } | |
| .mobile-nav-link.active { | |
| background: #d1fae5; | |
| color: #065f46; | |
| } | |
| @keyframes slideDown { | |
| from { | |
| opacity: 0; | |
| transform: translateY(-10px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| @media (max-width: 768px) { | |
| .nav-links { | |
| display: none; | |
| } | |
| .mobile-menu-btn { | |
| display: block; | |
| } | |
| .mobile-menu.active { | |
| display: block; | |
| } | |
| } | |
| @media (min-width: 769px) { | |
| .mobile-menu { | |
| display: none !important; | |
| } | |
| } | |
| </style> | |
| <nav class="navbar"> | |
| <div class="nav-container"> | |
| <div class="nav-content"> | |
| <a href="/" class="logo"> | |
| <i data-feather="leaf" class="logo-icon"></i> | |
| <span>ThaiRice NDVI</span> | |
| </a> | |
| <div class="nav-links"> | |
| <a href="#ndvi-map" class="nav-link active"> | |
| <i data-feather="map" style="width: 1.25rem; height: 1.25rem; margin-right: 0.5rem;"></i> | |
| Map | |
| </a> | |
| <a href="#field-details" class="nav-link"> | |
| <i data-feather="bar-chart-2" style="width: 1.25rem; height: 1.25rem; margin-right: 0.5rem;"></i> | |
| Analytics | |
| </a> | |
| <a href="#recommendations" class="nav-link"> | |
| <i data-feather="clipboard" style="width: 1.25rem; height: 1.25rem; margin-right: 0.5rem;"></i> | |
| Recommendations | |
| </a> | |
| <a href="/fields" class="nav-link"> | |
| <i data-feather="grid" style="width: 1.25rem; height: 1.25rem; margin-right: 0.5rem;"></i> | |
| All Fields | |
| </a> | |
| <button class="bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200 transform hover:-translate-y-0.5 shadow-md hover:shadow-lg" onclick="exportNDVIReport()"> | |
| <i data-feather="download" style="width: 1.25rem; height: 1.25rem; margin-right: 0.5rem;"></i> | |
| Export Report | |
| </button> | |
| </div> | |
| <button class="mobile-menu-btn" id="mobileMenuBtn"> | |
| <i data-feather="menu" style="width: 1.5rem; height: 1.5rem;"></i> | |
| </button> | |
| </div> | |
| <div class="mobile-menu" id="mobileMenu"> | |
| <div class="mobile-nav-links"> | |
| <a href="#ndvi-map" class="mobile-nav-link active"> | |
| <i data-feather="map" style="width: 1.25rem; height: 1.25rem; margin-right: 0.75rem;"></i> | |
| Map | |
| </a> | |
| <a href="#field-details" class="mobile-nav-link"> | |
| <i data-feather="bar-chart-2" style="width: 1.25rem; height: 1.25rem; margin-right: 0.75rem;"></i> | |
| Analytics | |
| </a> | |
| <a href="#recommendations" class="mobile-nav-link"> | |
| <i data-feather="clipboard" style="width: 1.25rem; height: 1.25rem; margin-right: 0.75rem;"></i> | |
| Recommendations | |
| </a> | |
| <a href="/fields" class="mobile-nav-link"> | |
| <i data-feather="grid" style="width: 1.25rem; height: 1.25rem; margin-right: 0.75rem;"></i> | |
| All Fields | |
| </a> | |
| <button class="bg-green-600 hover:bg-green-700 text-white font-medium py-3 px-4 rounded-lg transition duration-200 mt-2 flex items-center justify-center" onclick="exportNDVIReport()"> | |
| <i data-feather="download" style="width: 1.25rem; height: 1.25rem; margin-right: 0.75rem;"></i> | |
| Export Report | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </nav> | |
| `; | |
| // Initialize mobile menu | |
| this.initializeMobileMenu(); | |
| // Update active link based on scroll | |
| this.initializeScrollSpy(); | |
| // Replace feather icons | |
| setTimeout(() => { | |
| if (window.feather) { | |
| window.feather.replace(); | |
| } | |
| }, 100); | |
| } | |
| initializeMobileMenu() { | |
| const mobileMenuBtn = this.shadowRoot.getElementById('mobileMenuBtn'); | |
| const mobileMenu = this.shadowRoot.getElementById('mobileMenu'); | |
| if (mobileMenuBtn && mobileMenu) { | |
| mobileMenuBtn.addEventListener('click', () => { | |
| mobileMenu.classList.toggle('active'); | |
| const icon = mobileMenuBtn.querySelector('i'); | |
| if (mobileMenu.classList.contains('active')) { | |
| icon.setAttribute('data-feather', 'x'); | |
| } else { | |
| icon.setAttribute('data-feather', 'menu'); | |
| } | |
| window.feather.replace(); | |
| }); | |
| // Close menu when clicking on a link | |
| const mobileLinks = mobileMenu.querySelectorAll('.mobile-nav-link'); | |
| mobileLinks.forEach(link => { | |
| link.addEventListener('click', () => { | |
| mobileMenu.classList.remove('active'); | |
| const icon = mobileMenuBtn.querySelector('i'); | |
| icon.setAttribute('data-feather', 'menu'); | |
| window.feather.replace(); | |
| }); | |
| }); | |
| } | |
| } | |
| initializeScrollSpy() { | |
| const navLinks = this.shadowRoot.querySelectorAll('.nav-link, .mobile-nav-link'); | |
| const sections = ['ndvi-map', 'field-details', 'recommendations']; | |
| const observer = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| const id = entry.target.id; | |
| navLinks.forEach(link => { | |
| link.classList.remove('active'); | |
| if (link.getAttribute('href') === `#${id}`) { | |
| link.classList.add('active'); | |
| } | |
| }); | |
| } | |
| }); | |
| }, { threshold: 0.5 }); | |
| sections.forEach(section => { | |
| const element = document.getElementById(section); | |
| if (element) observer.observe(element); | |
| }); | |
| } | |
| } | |
| customElements.define('custom-navbar', CustomNavbar); |