-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] modularize typescript structure into single components
- Loading branch information
1 parent
9653a24
commit a3cb607
Showing
2 changed files
with
31 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
import MenuButtonToggleComponent from './components/menu-button-toggle/menu-button-toggle.component' | ||
|
||
function headerComponent(){ | ||
const header = document.querySelector('.header') | ||
const headerMenuButtonToggle = header?.querySelector('.header__mobile-burger') | ||
const headerNavigationContainer = header?.querySelector('.header__menu') | ||
|
||
if (headerMenuButtonToggle){ | ||
headerMenuButtonToggle.addEventListener('click', ()=>{ | ||
if (headerNavigationContainer){ | ||
headerNavigationContainer.classList.toggle('active') | ||
headerMenuButtonToggle.classList.toggle('active') | ||
} | ||
}) | ||
} | ||
} | ||
|
||
headerComponent(); | ||
new MenuButtonToggleComponent(); |
29 changes: 29 additions & 0 deletions
29
...es/Private/Build/TypeScript/components/menu-button-toggle/menu-button-toggle.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default class MenuButtonToggle { | ||
private readonly header: HTMLElement | null; | ||
private readonly headerMenuButtonToggle: Element | null | undefined; | ||
private readonly headerNavigationContainer: Element | null | undefined; | ||
|
||
|
||
constructor() { | ||
this.header = document.querySelector('.header'); | ||
|
||
if (!this.header) return; | ||
|
||
this.headerMenuButtonToggle = this.header.querySelector('.header__mobile-burger') || null; | ||
this.headerNavigationContainer = this.header.querySelector('.header__menu') || null; | ||
this.#initialize(); | ||
} | ||
|
||
#initialize(): void { | ||
if (this.headerMenuButtonToggle) { | ||
this.headerMenuButtonToggle.addEventListener('click', () => this.#toggleMenu()); | ||
} | ||
} | ||
|
||
#toggleMenu(): void { | ||
if (this.headerNavigationContainer && this.headerMenuButtonToggle) { | ||
this.headerNavigationContainer.classList.toggle('active'); | ||
this.headerMenuButtonToggle.classList.toggle('active'); | ||
} | ||
} | ||
} |