@sofidevo/astro-dynamic-header 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -2
- package/src/Header.astro +46 -0
- package/src/NavMenu.astro +1 -1
- package/src/index.ts +1 -2
- package/src/hamburger.ts +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sofidevo/astro-dynamic-header",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A dynamic Astro header component that switches between floating and fullscreen styles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -61,6 +61,5 @@
|
|
|
61
61
|
"url": "https://github.com/SofiDevO/astro-dynamic-header/issues"
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://github.com/SofiDevO/astro-dynamic-header#readme",
|
|
64
|
-
|
|
65
64
|
"demo": "https://base-astro-psi.vercel.app/fullscreen-demo"
|
|
66
65
|
}
|
package/src/Header.astro
CHANGED
|
@@ -39,14 +39,60 @@ const {
|
|
|
39
39
|
} = Astro.props;
|
|
40
40
|
---
|
|
41
41
|
|
|
42
|
+
<script>
|
|
43
|
+
class HamburgerController {
|
|
44
|
+
private hamburgerBtn: HTMLElement | null;
|
|
45
|
+
private mobileMenu: HTMLElement | null;
|
|
46
|
+
private links: NodeListOf<HTMLElement>;
|
|
47
|
+
|
|
48
|
+
constructor() {
|
|
49
|
+
this.hamburgerBtn = document.getElementById("hamburger-btn");
|
|
50
|
+
this.mobileMenu = document.getElementById("mobile-header-menu");
|
|
51
|
+
this.links = document.querySelectorAll(".mobile-menu__link");
|
|
52
|
+
this.init();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private init(): void {
|
|
56
|
+
if (this.hamburgerBtn && this.mobileMenu) {
|
|
57
|
+
this.hamburgerBtn.addEventListener("click", () => this.toggleMenu());
|
|
58
|
+
this.links.forEach(link => {
|
|
59
|
+
link.addEventListener("click", () => this.closeMenu());
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private closeMenu(): void {
|
|
65
|
+
if (this.hamburgerBtn && this.mobileMenu) {
|
|
66
|
+
this.hamburgerBtn.classList.remove("is-active");
|
|
67
|
+
this.mobileMenu.classList.remove("is-active");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private toggleMenu(): void {
|
|
72
|
+
if (this.hamburgerBtn && this.mobileMenu) {
|
|
73
|
+
this.hamburgerBtn.classList.toggle("is-active");
|
|
74
|
+
this.mobileMenu.classList.toggle("is-active");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Auto-initialize when DOM is ready
|
|
80
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
81
|
+
new HamburgerController();
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
84
|
+
|
|
42
85
|
<div class={`header__container header__container--${headerType}`} style={`z-index: ${zIndex};`}>
|
|
43
86
|
<header class={`header header--${headerType}`} style={`background-color: ${backgroundColor}; backdrop-filter: ${backdropBlur}; -webkit-backdrop-filter: ${backdropBlur};`}>
|
|
44
87
|
<a href={homeUrl}>
|
|
45
88
|
<img class="header__logo" src={logoSrc} alt={logoAlt} style={`width: ${logoWidth};`} />
|
|
46
89
|
</a>
|
|
47
90
|
<NavMenu menuItems={menuItems} />
|
|
91
|
+
<slot/>
|
|
48
92
|
<HamburgerButton />
|
|
93
|
+
|
|
49
94
|
<MobileNav menuItems={menuItems} type={headerType} />
|
|
95
|
+
|
|
50
96
|
</header>
|
|
51
97
|
</div>
|
|
52
98
|
|
package/src/NavMenu.astro
CHANGED
|
@@ -86,7 +86,7 @@ const pagePathname = Astro.url.pathname;
|
|
|
86
86
|
|
|
87
87
|
const isPositionedLeft =
|
|
88
88
|
(subsubmenu as HTMLElement).style.left === "-100%";
|
|
89
|
-
const transformDirection = isPositionedLeft ? "-2rem" : "
|
|
89
|
+
const transformDirection = isPositionedLeft ? "-2rem" : "2rem";
|
|
90
90
|
|
|
91
91
|
const currentTransform = (subsubmenu as HTMLElement).style.transform;
|
|
92
92
|
if (currentTransform && currentTransform.includes("translateX")) {
|
package/src/index.ts
CHANGED
package/src/hamburger.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const d = document;
|
|
2
|
-
|
|
3
|
-
export function HamburgerButton(hamburgerBtn: string, panel: string, menuLink: string): void {
|
|
4
|
-
d.addEventListener("click", (e: Event) => {
|
|
5
|
-
const target = e.target as Element;
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
target?.matches?.(hamburgerBtn) ||
|
|
9
|
-
target?.matches?.(`${hamburgerBtn} *`)
|
|
10
|
-
) {
|
|
11
|
-
d.querySelector(hamburgerBtn)?.classList.toggle("is-active");
|
|
12
|
-
d.querySelector(panel)?.classList.toggle("is-active");
|
|
13
|
-
}
|
|
14
|
-
if (target?.matches?.(menuLink)) {
|
|
15
|
-
d.querySelector(hamburgerBtn)?.classList.remove("is-active");
|
|
16
|
-
d.querySelector(panel)?.classList.remove("is-active");
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
d.addEventListener("DOMContentLoaded", () => {
|
|
22
|
-
HamburgerButton(".hamburger", ".mobile-header__menu", ".mobile-menu__link, .menu__link.mobile-menu__link");
|
|
23
|
-
});
|