Skip to content

Commit e97b59e

Browse files
committed
fix theme button
1 parent 7daf7ff commit e97b59e

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

src/components/widgets/HeaderNew.astro

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Auto-hide on scroll, transparent background, no underlines
55
*/
66
import Logo from '~/components/Logo.astro';
7-
import ToggleTheme from '~/components/common/ToggleTheme.astro';
87
import { getHomePermalink, trimSlash } from '~/utils/permalinks';
98
import { Icon } from 'astro-icon/components';
109
@@ -155,7 +154,14 @@ const slug = Astro.url.pathname;
155154
</ul>
156155
</nav>
157156
<div class="box-row box-row-btn" style="display: flex; gap: 1rem; align-items: center;">
158-
<ToggleTheme iconClass="w-6 h-6" class="theme-toggle-btn" />
157+
<button
158+
type="button"
159+
class="theme-toggle-btn"
160+
aria-label="Toggle between Dark and Light mode"
161+
onclick="document.documentElement.classList.toggle('dark'); localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';"
162+
>
163+
<Icon name="tabler:sun" class="w-6 h-6" />
164+
</button>
159165
<div class="link lang-switcher">
160166
<a href={langSwitchLink}>
161167
<span>{langSwitchText}</span>
@@ -253,7 +259,14 @@ const slug = Astro.url.pathname;
253259
</nav>
254260

255261
<div class="header-right">
256-
<ToggleTheme iconClass="w-5 h-5" class="theme-toggle-btn" />
262+
<button
263+
type="button"
264+
class="theme-toggle-btn"
265+
aria-label="Toggle between Dark and Light mode"
266+
onclick="document.documentElement.classList.toggle('dark'); localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';"
267+
>
268+
<Icon name="tabler:sun" class="w-5 h-5" />
269+
</button>
257270
<div class="link lang-switcher">
258271
<a href={langSwitchLink}>
259272
<span>{langSwitchText}</span>
@@ -312,6 +325,8 @@ const slug = Astro.url.pathname;
312325
justify-content: space-between;
313326
max-width: 1400px;
314327
margin: 0 auto;
328+
position: relative;
329+
z-index: 1;
315330
}
316331

317332
.main-nav-bar .border-bottom {
@@ -963,23 +978,4 @@ const slug = Astro.url.pathname;
963978

964979
// Initial check
965980
updateScrollState();
966-
967-
// Theme toggle
968-
const themeToggles = document.querySelectorAll('[data-aw-toggle-color-scheme]');
969-
themeToggles.forEach(btn => {
970-
btn.addEventListener('click', () => {
971-
const isDark = document.documentElement.classList.toggle('dark');
972-
localStorage.theme = isDark ? 'dark' : 'light';
973-
974-
// Update icon for all theme toggle buttons
975-
const allToggles = document.querySelectorAll('[data-aw-toggle-color-scheme]');
976-
allToggles.forEach(toggle => {
977-
const icon = toggle.querySelector('svg');
978-
if (icon) {
979-
// Toggle between sun and moon icons by swapping the icon
980-
// This is a simple approach - the icon will update on next page load
981-
}
982-
});
983-
});
984-
});
985981
</script>

0 commit comments

Comments
 (0)