forked from M3-Academy/desafio-react-e-typescript
Entrega do Desafio #2
@ -1,22 +1,52 @@
|
||||
import { HeaderContentTop } from "./HeaderContentTop";
|
||||
import styles from "./Header.module.scss"
|
||||
import styles from "./Header.module.scss";
|
||||
import { HeaderContentBottom } from "./HeaderContentBottom";
|
||||
import {useState} from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import Icon__Menu from "../../assets/imgs/IconMenu.svg";
|
||||
|
||||
const Header = () => {
|
||||
const [menuIsVisible, setMenuIsVisible] = useState(false);
|
||||
|
||||
const [menuIsVisible, setMenuIsVisible]= useState(false);
|
||||
const resizeWindow = () => {
|
||||
window.addEventListener("resize", () => {
|
||||
if (window.innerWidth > 1024) {
|
||||
document.body.style.overflowY = "auto";
|
||||
}
|
||||
if (window.innerWidth <= 1024 && menuIsVisible) {
|
||||
document.body.style.overflowY = "hidden";
|
||||
} else {
|
||||
document.body.style.overflowY = "auto";
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
resizeWindow();
|
||||
});
|
||||
|
||||
return (
|
||||
<header>
|
||||
<ul className={styles["Header__Top"]}>
|
||||
<button className={styles["Header__Button"]} onClick={() => setMenuIsVisible(true)} aria-label="abrir menu">
|
||||
<img src={Icon__Menu} alt="ícone de menu" className={styles["Icon__Menu"]} />
|
||||
</button>
|
||||
<HeaderContentTop menuIsVisible={menuIsVisible} setMenuIsVisible={setMenuIsVisible}/>
|
||||
</ul>
|
||||
<HeaderContentBottom menuIsVisible={menuIsVisible} setMenuIsVisible={setMenuIsVisible}/>
|
||||
<button
|
||||
className={styles["Header__Button"]}
|
||||
onClick={() => setMenuIsVisible(true)}
|
||||
aria-label="abrir menu"
|
||||
>
|
||||
<img
|
||||
src={Icon__Menu}
|
||||
alt="ícone de menu"
|
||||
className={styles["Icon__Menu"]}
|
||||
/>
|
||||
</button>
|
||||
<HeaderContentTop
|
||||
menuIsVisible={menuIsVisible}
|
||||
setMenuIsVisible={setMenuIsVisible}
|
||||
/>
|
||||
</ul>
|
||||
<HeaderContentBottom
|
||||
menuIsVisible={menuIsVisible}
|
||||
setMenuIsVisible={setMenuIsVisible}
|
||||
/>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
import styles from "./Header.module.scss"
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
interface HeaderContentProps {
|
||||
menuIsVisible: boolean;
|
||||
@ -7,6 +7,16 @@ interface HeaderContentProps {
|
||||
}
|
||||
|
||||
const HeaderContentBottom = ({menuIsVisible,setMenuIsVisible}: HeaderContentProps) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (window.innerWidth <= 1024){
|
||||
document.body.style.overflowY = menuIsVisible ? 'hidden' : 'auto';
|
||||
}
|
||||
if (window.innerWidth > 1024){
|
||||
document.body.style.overflowY = 'auto';
|
||||
}
|
||||
}, [menuIsVisible]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={
|
||||
|
Loading…
Reference in New Issue
Block a user