🎨 add functionalities when submenu close on resize breakpoint using windowStore
This commit is contained in:
parent
c88a180acc
commit
fb5be8caa9
@ -4,9 +4,12 @@ import Image from "next/image";
|
|||||||
import ProfileIcon from "@Assets/icons/user.svg";
|
import ProfileIcon from "@Assets/icons/user.svg";
|
||||||
import ProfileModal from "./ProfileModal";
|
import ProfileModal from "./ProfileModal";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {
|
||||||
type IState = {
|
|
||||||
isModalOpen: boolean;
|
isModalOpen: boolean;
|
||||||
|
openProfileModal: () => void;
|
||||||
|
closeProfileModal: () => void;
|
||||||
|
};
|
||||||
|
type IState = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class Profile extends React.Component<IProps, IState> {
|
export default class Profile extends React.Component<IProps, IState> {
|
||||||
@ -15,24 +18,14 @@ export default class Profile extends React.Component<IProps, IState> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
isModalOpen: false,
|
isModalOpen: false,
|
||||||
};
|
};
|
||||||
this.openModal = this.openModal.bind(this);
|
|
||||||
this.closeModal = this.closeModal.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override render(): JSX.Element {
|
public override render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className={classes["root"]}>
|
<div className={classes["root"]}>
|
||||||
<Image alt="profile" src={ProfileIcon} className={classes["profile-icon"]} onClick={this.openModal} />
|
<Image alt="profile" src={ProfileIcon} className={classes["profile-icon"]} onClick={this.props.openProfileModal} />
|
||||||
{this.state.isModalOpen && <ProfileModal isOpen={this.state.isModalOpen} closeModal={this.closeModal} />}
|
{this.props.isModalOpen && <ProfileModal isOpen={this.props.isModalOpen} closeModal={this.props.closeProfileModal} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private openModal() {
|
|
||||||
this.setState({ isModalOpen: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
private closeModal() {
|
|
||||||
this.setState({ isModalOpen: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,12 @@ type IState = {
|
|||||||
open: EHeaderOpeningState;
|
open: EHeaderOpeningState;
|
||||||
isBurgerMenuOpen: boolean;
|
isBurgerMenuOpen: boolean;
|
||||||
isNotificationMenuOpen: boolean;
|
isNotificationMenuOpen: boolean;
|
||||||
|
isProfileMenuOpen: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class Header extends React.Component<IProps, IState> {
|
export default class Header extends React.Component<IProps, IState> {
|
||||||
private onScrollYDirectionChange = () => { };
|
private onScrollYDirectionChange = () => { };
|
||||||
|
private onWindowResize = () => { };
|
||||||
|
|
||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -34,11 +36,14 @@ export default class Header extends React.Component<IProps, IState> {
|
|||||||
open: EHeaderOpeningState.OPEN,
|
open: EHeaderOpeningState.OPEN,
|
||||||
isBurgerMenuOpen: false,
|
isBurgerMenuOpen: false,
|
||||||
isNotificationMenuOpen: false,
|
isNotificationMenuOpen: false,
|
||||||
|
isProfileMenuOpen: false,
|
||||||
};
|
};
|
||||||
this.openBurgerMenu = this.openBurgerMenu.bind(this);
|
this.openBurgerMenu = this.openBurgerMenu.bind(this);
|
||||||
this.closeBurgerMenu = this.closeBurgerMenu.bind(this);
|
this.closeBurgerMenu = this.closeBurgerMenu.bind(this);
|
||||||
this.openNotificationMenu = this.openNotificationMenu.bind(this);
|
this.openNotificationMenu = this.openNotificationMenu.bind(this);
|
||||||
this.closeNotificationMenu = this.closeNotificationMenu.bind(this);
|
this.closeNotificationMenu = this.closeNotificationMenu.bind(this);
|
||||||
|
this.closeProfileMenu = this.closeProfileMenu.bind(this);
|
||||||
|
this.openProfileMenu = this.openProfileMenu.bind(this);
|
||||||
this.visibility = this.visibility.bind(this);
|
this.visibility = this.visibility.bind(this);
|
||||||
}
|
}
|
||||||
public override render(): JSX.Element {
|
public override render(): JSX.Element {
|
||||||
@ -55,7 +60,7 @@ export default class Header extends React.Component<IProps, IState> {
|
|||||||
<Notifications isModalOpen={this.state.isNotificationMenuOpen} openNotificationModal={this.openNotificationMenu} closeNotificationModal={this.closeNotificationMenu} />
|
<Notifications isModalOpen={this.state.isNotificationMenuOpen} openNotificationModal={this.openNotificationMenu} closeNotificationModal={this.closeNotificationMenu} />
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["profile-section"]}>
|
<div className={classes["profile-section"]}>
|
||||||
<Profile />
|
<Profile isModalOpen={this.state.isProfileMenuOpen} closeProfileModal={this.closeProfileMenu} openProfileModal={this.openProfileMenu} />
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["burger-menu"]}>
|
<div className={classes["burger-menu"]}>
|
||||||
<BurgerMenu isModalOpen={this.state.isBurgerMenuOpen} closeBurgerMenu={this.closeBurgerMenu} openBurgerMenu={this.openBurgerMenu} />
|
<BurgerMenu isModalOpen={this.state.isBurgerMenuOpen} closeBurgerMenu={this.closeBurgerMenu} openBurgerMenu={this.openBurgerMenu} />
|
||||||
@ -69,10 +74,15 @@ export default class Header extends React.Component<IProps, IState> {
|
|||||||
this.onScrollYDirectionChange = WindowStore.getInstance().onScrollYDirectionChange((scrollYDirection) =>
|
this.onScrollYDirectionChange = WindowStore.getInstance().onScrollYDirectionChange((scrollYDirection) =>
|
||||||
this.visibility(scrollYDirection),
|
this.visibility(scrollYDirection),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.onWindowResize = WindowStore.getInstance().onResize((window) =>
|
||||||
|
this.onResize(window)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override componentWillUnmount() {
|
public override componentWillUnmount() {
|
||||||
this.onScrollYDirectionChange();
|
this.onScrollYDirectionChange();
|
||||||
|
this.onWindowResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private visibility(scrollYDirection: number) {
|
private visibility(scrollYDirection: number) {
|
||||||
@ -86,6 +96,13 @@ export default class Header extends React.Component<IProps, IState> {
|
|||||||
if (open !== this.state.open) this.setState({ open });
|
if (open !== this.state.open) this.setState({ open });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onResize(window: Window) {
|
||||||
|
if (window.innerWidth === 1300) {
|
||||||
|
this.setState({ isBurgerMenuOpen: false });
|
||||||
|
this.setState({ isProfileMenuOpen: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private openBurgerMenu() {
|
private openBurgerMenu() {
|
||||||
this.setState({ isBurgerMenuOpen: true });
|
this.setState({ isBurgerMenuOpen: true });
|
||||||
}
|
}
|
||||||
@ -101,4 +118,12 @@ export default class Header extends React.Component<IProps, IState> {
|
|||||||
private closeNotificationMenu() {
|
private closeNotificationMenu() {
|
||||||
this.setState({ isNotificationMenuOpen: false });
|
this.setState({ isNotificationMenuOpen: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private openProfileMenu() {
|
||||||
|
this.setState({ isProfileMenuOpen: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
private closeProfileMenu() {
|
||||||
|
this.setState({ isProfileMenuOpen: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,17 @@ export default class WindowStore {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onResize(callback: (window: Window) => void) {
|
||||||
|
this.event.on("resize", callback);
|
||||||
|
return () => {
|
||||||
|
this.event.off("resize", callback);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private iniEvents(): void {
|
private iniEvents(): void {
|
||||||
window.addEventListener("scroll", (e: Event) => this.scrollYHandler(e));
|
window.addEventListener("scroll", (e: Event) => this.scrollYHandler(e));
|
||||||
|
window.addEventListener("resize", (e: Event) => this.resizeHandler());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private scrollYHandler = (() => {
|
private scrollYHandler = (() => {
|
||||||
@ -40,4 +49,8 @@ export default class WindowStore {
|
|||||||
previousYDirection = scrollYDirection;
|
previousYDirection = scrollYDirection;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
private resizeHandler() {
|
||||||
|
this.event.emit("resize", window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user