@sofidevo/astro-dynamic-header 1.0.15 → 1.0.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sofidevo/astro-dynamic-header",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
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",
package/src/Header.astro CHANGED
@@ -39,6 +39,49 @@ 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}>
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" : "2.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
@@ -1,5 +1,4 @@
1
- // TypeScript utilities
2
- export { HamburgerButton } from './hamburger.ts';
1
+
3
2
 
4
3
  // Types
5
4
  export interface MenuItemType {
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
- });