Spaces:
Running
Running
the navigation javascript is wrong with ugly dashboard, help me fix this bug
Browse files- components/navigation.js +133 -114
components/navigation.js
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
|
|
| 1 |
class CustomNavigation extends HTMLElement {
|
| 2 |
connectedCallback() {
|
| 3 |
this.attachShadow({ mode: 'open' });
|
| 4 |
this.shadowRoot.innerHTML = `
|
| 5 |
<style>
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
}
|
| 94 |
-
</style>
|
| 95 |
<nav class="nav-container">
|
| 96 |
-
<div class="container mx-auto px-4 py-
|
| 97 |
<div class="flex items-center justify-between">
|
| 98 |
-
<!--
|
| 99 |
<a href="index.html" class="flex items-center">
|
| 100 |
-
<span class="text-
|
| 101 |
</a>
|
|
|
|
| 102 |
<!-- Desktop Navigation -->
|
| 103 |
-
<div class="hidden md:flex items-center space-x-
|
| 104 |
<a href="index.html" class="nav-link">仪表板</a>
|
| 105 |
<a href="tracker.html" class="nav-link">流程跟踪</a>
|
| 106 |
<a href="roadmap.html" class="nav-link">路线图</a>
|
| 107 |
<a href="experiments.html" class="nav-link">实验设置</a>
|
| 108 |
<a href="team.html" class="nav-link">团队</a>
|
| 109 |
<a href="docs.html" class="nav-link">文档</a>
|
| 110 |
-
<a href="login.html" class="bg-primary hover:bg-red-600 text-white px-4 py-2 rounded-lg transition duration-300">
|
| 111 |
登录
|
| 112 |
</a>
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<!-- Mobile Menu Button -->
|
| 116 |
-
<button id="mobileMenuBtn" class="md:hidden text-gray-
|
| 117 |
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 118 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
|
| 119 |
</svg>
|
|
@@ -121,22 +121,22 @@ class CustomNavigation extends HTMLElement {
|
|
| 121 |
</div>
|
| 122 |
|
| 123 |
<!-- Mobile Menu -->
|
| 124 |
-
<div id="mobileMenu" class="hidden md:hidden mobile-menu mt-
|
| 125 |
-
<div class="flex flex-col space-y-
|
| 126 |
-
<a href="index.html" class="nav-link py-
|
| 127 |
-
<a href="tracker.html" class="nav-link py-
|
| 128 |
-
<a href="roadmap.html" class="nav-link py-
|
| 129 |
-
<a href="experiments.html" class="nav-link py-
|
| 130 |
-
<a href="team.html" class="nav-link py-
|
| 131 |
-
<a href="docs.html" class="nav-link py-
|
| 132 |
-
<a href="login.html" class="w-full bg-primary hover:bg-red-600 text-white px-4 py-
|
| 133 |
登录
|
| 134 |
</a>
|
| 135 |
</div>
|
| 136 |
</div>
|
| 137 |
</div>
|
| 138 |
</nav>
|
| 139 |
-
`;
|
| 140 |
|
| 141 |
// Add mobile menu functionality
|
| 142 |
const mobileMenuBtn = this.shadowRoot.getElementById('mobileMenuBtn');
|
|
@@ -146,9 +146,17 @@ class CustomNavigation extends HTMLElement {
|
|
| 146 |
mobileMenuBtn.addEventListener('click', () => {
|
| 147 |
mobileMenu.classList.toggle('hidden');
|
| 148 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
|
|
|
| 150 |
// Update active link based on current page
|
| 151 |
-
|
| 152 |
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
|
| 153 |
const links = this.shadowRoot.querySelectorAll('.nav-link');
|
| 154 |
|
|
@@ -160,13 +168,24 @@ class CustomNavigation extends HTMLElement {
|
|
| 160 |
link.classList.remove('active');
|
| 161 |
}
|
| 162 |
});
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
-
customElements.define('custom-navigation', CustomNavigation);
|
|
|
|
| 1 |
+
|
| 2 |
class CustomNavigation extends HTMLElement {
|
| 3 |
connectedCallback() {
|
| 4 |
this.attachShadow({ mode: 'open' });
|
| 5 |
this.shadowRoot.innerHTML = `
|
| 6 |
<style>
|
| 7 |
+
:host {
|
| 8 |
+
display: block;
|
| 9 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
.nav-container {
|
| 13 |
+
background: white;
|
| 14 |
+
border-bottom: 1px solid #e5e7eb;
|
| 15 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
| 16 |
+
width: 100%;
|
| 17 |
+
position: sticky;
|
| 18 |
+
top: 0;
|
| 19 |
+
z-index: 1000;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.nav-link {
|
| 23 |
+
position: relative;
|
| 24 |
+
transition: all 0.3s ease;
|
| 25 |
+
text-decoration: none;
|
| 26 |
+
color: #4b5563;
|
| 27 |
+
padding: 0.5rem 1rem;
|
| 28 |
+
border-radius: 0.375rem;
|
| 29 |
+
display: inline-block;
|
| 30 |
+
font-weight: 500;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.nav-link:hover {
|
| 34 |
+
color: #ef4444;
|
| 35 |
+
background-color: #fef2f2;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.nav-link.active {
|
| 39 |
+
color: #ef4444;
|
| 40 |
+
background-color: #fef2f2;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.nav-link.active::after {
|
| 44 |
+
content: '';
|
| 45 |
+
position: absolute;
|
| 46 |
+
bottom: -1px;
|
| 47 |
+
left: 1rem;
|
| 48 |
+
right: 1rem;
|
| 49 |
+
height: 2px;
|
| 50 |
+
background: #ef4444;
|
| 51 |
+
border-radius: 1px;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.mobile-menu {
|
| 55 |
+
animation: slideDown 0.3s ease-out;
|
| 56 |
+
background-color: white;
|
| 57 |
+
border-top: 1px solid #e5e7eb;
|
| 58 |
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
@keyframes slideDown {
|
| 62 |
+
from {
|
| 63 |
+
opacity: 0;
|
| 64 |
+
transform: translateY(-10px);
|
| 65 |
+
}
|
| 66 |
+
to {
|
| 67 |
+
opacity: 1;
|
| 68 |
+
transform: translateY(0);
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
@media (max-width: 768px) {
|
| 73 |
+
.nav-container {
|
| 74 |
+
padding: 0.75rem 1rem;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
button {
|
| 79 |
+
cursor: pointer;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.container {
|
| 83 |
+
max-width: 1280px;
|
| 84 |
+
margin-left: auto;
|
| 85 |
+
margin-right: auto;
|
| 86 |
+
padding-left: 1rem;
|
| 87 |
+
padding-right: 1rem;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.text-primary {
|
| 91 |
+
color: #ef4444 !important;
|
| 92 |
+
}
|
| 93 |
+
</style>
|
|
|
|
|
|
|
| 94 |
<nav class="nav-container">
|
| 95 |
+
<div class="container mx-auto px-4 py-3">
|
| 96 |
<div class="flex items-center justify-between">
|
| 97 |
+
<!-- Logo -->
|
| 98 |
<a href="index.html" class="flex items-center">
|
| 99 |
+
<span class="text-2xl font-bold text-gray-900">PyQuant<span class="text-primary">Flow</span></span>
|
| 100 |
</a>
|
| 101 |
+
|
| 102 |
<!-- Desktop Navigation -->
|
| 103 |
+
<div class="hidden md:flex items-center space-x-1">
|
| 104 |
<a href="index.html" class="nav-link">仪表板</a>
|
| 105 |
<a href="tracker.html" class="nav-link">流程跟踪</a>
|
| 106 |
<a href="roadmap.html" class="nav-link">路线图</a>
|
| 107 |
<a href="experiments.html" class="nav-link">实验设置</a>
|
| 108 |
<a href="team.html" class="nav-link">团队</a>
|
| 109 |
<a href="docs.html" class="nav-link">文档</a>
|
| 110 |
+
<a href="login.html" class="ml-4 bg-primary hover:bg-red-600 text-white px-4 py-2 rounded-lg transition duration-300">
|
| 111 |
登录
|
| 112 |
</a>
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<!-- Mobile Menu Button -->
|
| 116 |
+
<button id="mobileMenuBtn" class="md:hidden text-gray-700 hover:text-gray-900 p-2 rounded-lg hover:bg-gray-100">
|
| 117 |
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 118 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
|
| 119 |
</svg>
|
|
|
|
| 121 |
</div>
|
| 122 |
|
| 123 |
<!-- Mobile Menu -->
|
| 124 |
+
<div id="mobileMenu" class="hidden md:hidden mobile-menu mt-3 rounded-lg">
|
| 125 |
+
<div class="flex flex-col space-y-1 p-2">
|
| 126 |
+
<a href="index.html" class="nav-link py-3 px-4">仪表板</a>
|
| 127 |
+
<a href="tracker.html" class="nav-link py-3 px-4">流程跟踪</a>
|
| 128 |
+
<a href="roadmap.html" class="nav-link py-3 px-4">路线图</a>
|
| 129 |
+
<a href="experiments.html" class="nav-link py-3 px-4">实验设置</a>
|
| 130 |
+
<a href="team.html" class="nav-link py-3 px-4">团队</a>
|
| 131 |
+
<a href="docs.html" class="nav-link py-3 px-4">文档</a>
|
| 132 |
+
<a href="login.html" class="mt-2 w-full bg-primary hover:bg-red-600 text-white px-4 py-3 rounded-lg transition duration-300 text-center font-medium">
|
| 133 |
登录
|
| 134 |
</a>
|
| 135 |
</div>
|
| 136 |
</div>
|
| 137 |
</div>
|
| 138 |
</nav>
|
| 139 |
+
`;
|
| 140 |
|
| 141 |
// Add mobile menu functionality
|
| 142 |
const mobileMenuBtn = this.shadowRoot.getElementById('mobileMenuBtn');
|
|
|
|
| 146 |
mobileMenuBtn.addEventListener('click', () => {
|
| 147 |
mobileMenu.classList.toggle('hidden');
|
| 148 |
});
|
| 149 |
+
|
| 150 |
+
// Close mobile menu when clicking outside
|
| 151 |
+
document.addEventListener('click', (event) => {
|
| 152 |
+
if (!this.contains(event.target) && !mobileMenu.classList.contains('hidden')) {
|
| 153 |
+
mobileMenu.classList.add('hidden');
|
| 154 |
+
}
|
| 155 |
+
});
|
| 156 |
}
|
| 157 |
+
|
| 158 |
// Update active link based on current page
|
| 159 |
+
const updateActiveLink = () => {
|
| 160 |
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
|
| 161 |
const links = this.shadowRoot.querySelectorAll('.nav-link');
|
| 162 |
|
|
|
|
| 168 |
link.classList.remove('active');
|
| 169 |
}
|
| 170 |
});
|
| 171 |
+
};
|
| 172 |
+
|
| 173 |
+
// Update on load and when navigation occurs
|
| 174 |
+
setTimeout(updateActiveLink, 100);
|
| 175 |
+
|
| 176 |
+
// Listen for navigation events (for single page apps or hash changes)
|
| 177 |
+
window.addEventListener('popstate', updateActiveLink);
|
| 178 |
+
|
| 179 |
+
// Close mobile menu when a link is clicked
|
| 180 |
+
const mobileLinks = this.shadowRoot.querySelectorAll('#mobileMenu .nav-link');
|
| 181 |
+
mobileLinks.forEach(link => {
|
| 182 |
+
link.addEventListener('click', () => {
|
| 183 |
+
if (mobileMenu) {
|
| 184 |
+
mobileMenu.classList.add('hidden');
|
| 185 |
+
}
|
| 186 |
+
});
|
| 187 |
+
});
|
| 188 |
+
}
|
| 189 |
}
|
| 190 |
|
| 191 |
+
customElements.define('custom-navigation', CustomNavigation);
|