Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Storytelling navigation in mobile view #1425

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions elements/storytelling/src/helpers/render-html-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,11 @@ export function parseNavWithAddSection(

const navHtml = `
<div class="navigation">
<div class="container">
<ul>
<div class="container nav-container">
<span class="hamburger-menu" aria-label="Toggle navigation">
</span>
<div class="nav-overlay"></div>
<ul class="nav-list">
${nav
.map(({ id, title, state }) =>
state
Expand All @@ -333,6 +336,25 @@ export function parseNavWithAddSection(
`;
const navDOM = parser.parseFromString(navHtml, "text/html").body.firstChild;

// Add click handler for hamburger menu
const hamburgerBtn = navDOM.querySelector(".hamburger-menu");
const navList = navDOM.querySelector(".navigation .container ul");
const navOverlay = navDOM.querySelector(".nav-overlay");
const navListItems = navDOM.querySelectorAll(".nav-list li");

if (hamburgerBtn && navList) {
const navEventHandlers = () => {
hamburgerBtn.classList.toggle("active");
navList.classList.toggle("show");
navOverlay.classList.toggle("show");
};
hamburgerBtn.addEventListener("click", () => navEventHandlers());
navOverlay.addEventListener("click", () => navEventHandlers());
navListItems.forEach((item) => {
item.addEventListener("click", () => navEventHandlers());
});
}

if (html[0].classList.contains("hero")) navIndex = 1;
html.splice(navIndex, 0, navDOM);
}
Expand Down
72 changes: 72 additions & 0 deletions elements/storytelling/src/style.eox.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,78 @@ ${slider}
.navigation li a:hover {
--primary-background-hover: transparent;
}
.hamburger-menu {
display: none;
cursor: pointer;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTUsOS41TDcuNSwxNEgyLjVMNSw5LjVNMyw0SDdWOEgzVjRNNSwyMEEyLDIgMCAwLDAgNywxOEEyLDIgMCAwLDAgNSwxNkEyLDIgMCAwLDAgMywxOEEyLDIgMCAwLDAgNSwyME05LDVWN0gyMVY1SDlNOSwxOUgyMVYxN0g5VjE5TTksMTNIMjFWMTFIOVYxM1oiIC8+PC9zdmc+");
background-repeat: no-repeat;
background-size: contain;
width: 30px;
height: 30px;
}
.nav-list {
list-style: none;
padding: 0;
margin: 0;
}
.nav-overlay {
display: none;
}
@media (max-width: 768px) {
.navigation {
padding: 0px;
height: 50px;
}
.navigation .container {
display: flex;
justify-content: center;
align-items: center;
}
.hamburger-menu {
display: flex;
}
.navigation .container ul {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
z-index: 99999999;
display: none;
flex-direction: column;
}
.nav-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 99999998;
cursor: pointer;
}
.navigation .container ul.show, .nav-overlay.show {
display: flex !important;
}
.nav-list li {
padding: 15px;
border-bottom: 1px solid #eee;
}
.hamburger-menu.active span:nth-child(1) {
transform: rotate(45deg) translate(8px, 8px);
}
.hamburger-menu.active span:nth-child(2) {
opacity: 0;
}
.hamburger-menu.active span:nth-child(3) {
transform: rotate(-45deg) translate(7px, -7px);
}
.navigation .container ul li {
width: 100%;
text-align: center;
}
}
.section-wrap {
scroll-margin: 120px;
}
Expand Down
Loading