Adicionando submenu desktop e mobile

This commit is contained in:
Bernardo Cunha Ernani Waldhelm 2022-12-07 20:46:41 -03:00
parent 738eab0adc
commit ee9f332933
2 changed files with 64 additions and 29 deletions

View File

@ -1,38 +1,46 @@
import { isSmallerThen991 } from "Helpers/MediasMatch";
export default class Menu {
constructor() {
this.toggleMenuMobile();
this.toggleSubCategories();
this.selectors();
this.events();
}
toggleMenuMobile() {
$("#open-menu-button, .show-menu .option").on("click", function () {
$(".menu-principal").addClass("mobile-open");
$("header.header").addClass("menu-mobile-open");
});
$("#close-menu-button").on("click", function () {
$(".menu-principal").removeClass("mobile-open");
$("header.header").removeClass("menu-mobile-open");
});
selectors() {
this.openMenuButton = $(".menu__button");
this.mainMenu = $(".main-menu");
this.closeMenuButton = $(".menu-header__close-button");
this.departmentsLink = $(".main-menu__department__link");
this.returnSubmenu = $(".submenu__return-button");
}
toggleSubCategories() {
$(".m3-dropdown > button").on("click", function (event) {
events() {
this.openMenuButton.click(this.openMenu.bind(this));
this.closeMenuButton.click(this.closeMenu.bind(this));
this.returnSubmenu.click(this.closeSubmenu);
if (isSmallerThen991) {
this.departmentsLink.click(this.openSubmenu);
}
}
openMenu() {
this.mainMenu.addClass("isOpen");
}
closeMenu() {
this.mainMenu.removeClass("isOpen");
}
openSubmenu(event) {
event.preventDefault();
const link = $(event.target);
if ($(this).parent().hasClass("sub-menu-open")) {
$(this).parent().removeClass("sub-menu-open");
} else {
$(this).parent().siblings().removeClass("sub-menu-open");
$(this).parent().addClass("sub-menu-open");
link.siblings(".submenu").addClass("isOpen"); //siblings pega os irmãos
}
$(this).parents("ul.itens").toggleClass("has-sub-menu-open");
});
closeSubmenu(events) {
const button = $(events.target);
$(".m3-dropdown .btn-voltar").on("click", function () {
$(this).parents(".m3-dropdown").removeClass("sub-menu-open");
$(this).parents("ul.itens").removeClass("has-sub-menu-open");
});
button.parents(".submenu").removeClass("isOpen"); //parents pega os pais do elemento
}
}

View File

@ -15,6 +15,10 @@
.menu-header {
@include mq(lg, min) {
display: none;
}
&__top-wrapper {
display: flex;
align-items: center;
@ -64,6 +68,11 @@
width: 100%;
height: 100%;
background: $white;
transition: transform 0.2s ease-in-out;
}
&.isOpen {
transform: translateX(0);
}
&__departments {
@ -113,7 +122,7 @@
font-size: 12px;
line-height: 15px;
color: $white;
display: flex;
//display: flex;
align-items: center;
justify-content: space-between;
@ -134,6 +143,12 @@
}
}
i {
@include mq(lg, min) {
display: none;
}
}
}
}
@ -147,6 +162,10 @@
font-size: 10px;
color: $white;
@include mq(lg, min) {
display: none;
}
i {
margin-right: 16px;
}
@ -165,7 +184,7 @@
height: 100%;
overflow: auto;
padding-bottom: 34px;
transition: left 0.2s ease-in-out;
}
@include mq(lg, min) {
@ -179,8 +198,12 @@
opacity: 0;
pointer-events: none;
transition: all 0.2s ease-in-out;
}
&.isOpen {
left: 0;
}
&::before {
content: '';
@ -215,6 +238,10 @@
margin-right: 8px;
}
@include mq(lg, min) {
display: none;
}
}
&__title {