feat(home): Cria a logica de funcionamento do menu mobile

This commit is contained in:
Manuela Luana Schumacker Tavares 2022-12-05 22:24:45 -03:00
parent 0cf7b50c8a
commit cdb526203d
3 changed files with 163 additions and 63 deletions

View File

@ -1,38 +1,47 @@
import { isSmallerThen991 } from "Helpers/MediasMatch";
export default class Menu { export default class Menu {
constructor() { constructor() {
this.toggleMenuMobile(); this.selectors();
this.toggleSubCategories(); this.events();
} }
toggleMenuMobile() { selectors() {
$("#open-menu-button, .show-menu .option").on("click", function () { this.openMenuButton = $(".menu__button");
$(".menu-principal").addClass("mobile-open"); this.mainMenu = $(".main-menu");
$("header.header").addClass("menu-mobile-open"); this.closeMenuButton = $(".menu-header__close-button");
}); this.departmentLink = $(".main-menu__department-link");
this.returnButton = $(".submenu__return-button");
$("#close-menu-button").on("click", function () {
$(".menu-principal").removeClass("mobile-open");
$("header.header").removeClass("menu-mobile-open");
});
} }
toggleSubCategories() { events() {
$(".m3-dropdown > button").on("click", function (event) { this.openMenuButton.click(this.openMenu.bind(this));
this.closeMenuButton.click(this.closeMenu.bind(this));
this.returnButton.click(this.closeSubMenu.bind(this));
if (isSmallerThen991) {
this.departmentLink.click(this.openSubMenu.bind(this));
}
}
openMenu() {
this.mainMenu.addClass("is-open");
}
closeMenu() {
this.mainMenu.removeClass("is-open");
}
openSubMenu(event) {
event.preventDefault(); event.preventDefault();
const link = $(event.target);
if ($(this).parent().hasClass("sub-menu-open")) { link.siblings(".submenu").addClass("is-open");
$(this).parent().removeClass("sub-menu-open");
} else {
$(this).parent().siblings().removeClass("sub-menu-open");
$(this).parent().addClass("sub-menu-open");
} }
$(this).parents("ul.itens").toggleClass("has-sub-menu-open"); closeSubMenu(event) {
}); const button = $(event.target);
$(".m3-dropdown .btn-voltar").on("click", function () { button.parents(".submenu").removeClass("is-open");
$(this).parents(".m3-dropdown").removeClass("sub-menu-open");
$(this).parents("ul.itens").removeClass("has-sub-menu-open");
});
} }
} }

View File

@ -13,6 +13,10 @@
} }
.menu-header { .menu-header {
@include mq(lg, min) {
display: none;
}
&__top-wrapper { &__top-wrapper {
display: flex; display: flex;
align-items: center; align-items: center;
@ -62,6 +66,11 @@
transform: translateX(-100%); transform: translateX(-100%);
z-index: map-get($z-index, Level-5); z-index: map-get($z-index, Level-5);
background: $color-white; background: $color-white;
transition: transform 0.2s ease-in-out;
}
&.is-open {
transform: translateX(0);
} }
&__departments { &__departments {
@ -131,6 +140,12 @@
display: block; display: block;
} }
} }
i {
@include mq(lg, min) {
display: none;
}
}
} }
&__account-link { &__account-link {
@ -143,6 +158,10 @@
color: $color-white; color: $color-white;
background: $color-black; background: $color-black;
@include mq(lg, min) {
display: none;
}
i { i {
margin-right: 16px; margin-right: 16px;
} }
@ -160,6 +179,7 @@
overflow: auto; overflow: auto;
padding-bottom: 34px; padding-bottom: 34px;
background: $color-white; background: $color-white;
transition: left 0.2s ease-in-out;
} }
@include mq(lg, min) { @include mq(lg, min) {
@ -175,6 +195,10 @@
transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
} }
&.is-open {
left: 0;
}
&::before { &::before {
content: ""; content: "";
position: absolute; position: absolute;
@ -204,6 +228,10 @@
text-align: left; text-align: left;
background: transparent; background: transparent;
@include mq(lg, min) {
display: none;
}
i { i {
margin-right: 8px; margin-right: 8px;
} }

View File

@ -83,6 +83,59 @@
LOREM IPSUM LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i> <i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a> </a>
<div class="submenu">
<button class="submenu__return-button">
<i class="sprite sprite-menu-left-arrow-icon"></i>
VOLTAR
</button>
<div class="container">
<h2 class="submenu__title">LOREM IPSUM</h2>
<div class="submenu__categories-wrapper">
<ul class="submenu__categories">
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
</ul>
<ul class="submenu__categories">
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li>
</ul>
</div>
<a class="submenu__see-all" href="#">
VER TODOS
<i class="sprite sprite-menu-arrow-icon"></i>
</a>
</div>
</div>
</li> </li>
<li class="main-menu__department"> <li class="main-menu__department">
@ -90,48 +143,58 @@
LOREM IPSUM LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i> <i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a> </a>
<div class="submenu">
<button class="submenu__return-button">
<i class="sprite sprite-menu-left-arrow-icon"></i>
VOLTAR
</button>
<div class="container">
<h2 class="submenu__title">LOREM IPSUM</h2>
<div class="submenu__categories-wrapper">
<ul class="submenu__categories">
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM </li>
<i class="sprite sprite-menu-mobile-arrow-icon"></i> </ul>
</a>
<ul class="submenu__categories">
<li class="submenu__category">
<a class="submenu__category-link" href="#">Lorem Ipsum</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM
<i class="sprite sprite-menu-mobile-arrow-icon"></i>
</a>
</li> </li>
<li class="main-menu__department"> <li class="submenu__category">
<a class="main-menu__department-link" href="#" title="LOREM IPSUM"> <a class="submenu__category-link" href="#">Lorem Ipsum</a>
LOREM IPSUM </li>
<i class="sprite sprite-menu-mobile-arrow-icon"></i> </ul>
</div>
<a class="submenu__see-all" href="#">
VER TODOS
<i class="sprite sprite-menu-arrow-icon"></i>
</a> </a>
</div>
</div>
</li> </li>
</ul> </ul>