luluUCD commited on
Commit
955ca69
·
verified ·
1 Parent(s): e5a88a8

the navigation javascript is wrong with ugly dashboard, help me fix this bug

Browse files
Files changed (1) hide show
  1. 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
- :host {
7
- display: block;
8
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
9
- }
10
-
11
- .nav-container {
12
- background: linear-gradient(135deg, #ffffff 0%, #fef2f2 100%);
13
- border-bottom: 1px solid #fed7d7;
14
- box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.1), 0 2px 4px -1px rgba(239, 68, 68, 0.06);
15
- width: 100%;
16
- position: sticky;
17
- top: 0;
18
- z-index: 1000;
19
- }
20
-
21
- .nav-link {
22
- position: relative;
23
- transition: color 0.3s ease;
24
- text-decoration: none;
25
- color: #4b5563;
26
- padding: 0.5rem 0.75rem;
27
- border-radius: 0.375rem;
28
- display: inline-block;
29
- }
30
-
31
- .nav-link:hover {
32
- color: #ef4444;
33
- background-color: #fef2f2;
34
- }
35
-
36
- .nav-link.active {
37
- color: #ef4444;
38
- font-weight: 600;
39
- }
40
-
41
- .nav-link.active::after {
42
- content: '';
43
- position: absolute;
44
- bottom: -4px;
45
- left: 0.75rem;
46
- right: 0.75rem;
47
- height: 2px;
48
- background: linear-gradient(90deg, #ef4444 0%, #f43f5e 100%);
49
- border-radius: 1px;
50
- }
51
-
52
- .mobile-menu {
53
- animation: slideDown 0.3s ease-out;
54
- background-color: white;
55
- border-top: 1px solid #fed7d7;
56
- }
57
-
58
- @keyframes slideDown {
59
- from {
60
- opacity: 0;
61
- transform: translateY(-10px);
62
- }
63
- to {
64
- opacity: 1;
65
- transform: translateY(0);
66
- }
67
- }
68
-
69
- @media (max-width: 768px) {
70
- .nav-container {
71
- padding: 0.75rem 1rem;
72
- }
73
- }
74
-
75
- /* Fix for icons */
76
- i[data-feather] {
77
- width: 1rem;
78
- height: 1rem;
79
- stroke-width: 2;
80
- vertical-align: middle;
81
- }
82
-
83
- button {
84
- cursor: pointer;
85
- }
86
-
87
- .container {
88
- max-width: 1280px;
89
- margin-left: auto;
90
- margin-right: auto;
91
- padding-left: 1rem;
92
- padding-right: 1rem;
93
- }
94
- </style>
95
  <nav class="nav-container">
96
- <div class="container mx-auto px-4 py-4">
97
  <div class="flex items-center justify-between">
98
- <!-- Simplified Logo -->
99
  <a href="index.html" class="flex items-center">
100
- <span class="text-xl font-bold text-gray-800">PyQuant<span class="text-primary">Flow</span></span>
101
  </a>
 
102
  <!-- Desktop Navigation -->
103
- <div class="hidden md:flex items-center space-x-6">
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-600">
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-4 pb-4">
125
- <div class="flex flex-col space-y-3">
126
- <a href="index.html" class="nav-link py-2">仪表板</a>
127
- <a href="tracker.html" class="nav-link py-2">流程跟踪</a>
128
- <a href="roadmap.html" class="nav-link py-2">路线图</a>
129
- <a href="experiments.html" class="nav-link py-2">实验设置</a>
130
- <a href="team.html" class="nav-link py-2">团队</a>
131
- <a href="docs.html" class="nav-link py-2">文档</a>
132
- <a href="login.html" class="w-full bg-primary hover:bg-red-600 text-white px-4 py-2 rounded-lg transition duration-300 mt-3 text-center">
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
- setTimeout(() => {
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
- // Initialize icons in shadow DOM
165
- if (typeof feather !== 'undefined') {
166
- feather.replace({ selector: 'i' });
167
- }
168
- }, 100);
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);