380 lines
10 KiB
JavaScript
380 lines
10 KiB
JavaScript
/**
|
|
* Mobile Drawer Component
|
|
* Slide-in navigation drawer from the left with backdrop
|
|
*/
|
|
class MobileDrawer extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
this.attachShadow({ mode: "open" });
|
|
this.isOpen = false;
|
|
this.handleBackdropClick = this.handleBackdropClick.bind(this);
|
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
}
|
|
|
|
connectedCallback() {
|
|
this.render();
|
|
this.setupEventListeners();
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
document.removeEventListener("keydown", this.handleKeyDown);
|
|
}
|
|
|
|
setupEventListeners() {
|
|
// Close button
|
|
const closeBtn = this.shadowRoot.querySelector(".close-button");
|
|
closeBtn?.addEventListener("click", () => this.close());
|
|
|
|
// Backdrop click
|
|
const backdrop = this.shadowRoot.querySelector(".backdrop");
|
|
backdrop?.addEventListener("click", this.handleBackdropClick);
|
|
|
|
// Escape key
|
|
document.addEventListener("keydown", this.handleKeyDown);
|
|
|
|
// Listen for global open event
|
|
window.addEventListener("open-mobile-drawer", () => this.open());
|
|
window.addEventListener("close-mobile-drawer", () => this.close());
|
|
window.addEventListener("toggle-mobile-drawer", () => this.toggle());
|
|
}
|
|
|
|
handleBackdropClick() {
|
|
this.close();
|
|
}
|
|
|
|
handleKeyDown(e) {
|
|
if (e.key === "Escape" && this.isOpen) {
|
|
this.close();
|
|
}
|
|
}
|
|
|
|
open() {
|
|
this.isOpen = true;
|
|
this.shadowRoot.querySelector(".drawer-container").classList.add("open");
|
|
document.body.style.overflow = "hidden";
|
|
|
|
// Focus trap - focus first focusable element
|
|
setTimeout(() => {
|
|
const closeBtn = this.shadowRoot.querySelector(".close-button");
|
|
closeBtn?.focus();
|
|
}, 100);
|
|
}
|
|
|
|
close() {
|
|
this.isOpen = false;
|
|
this.shadowRoot.querySelector(".drawer-container").classList.remove("open");
|
|
document.body.style.overflow = "";
|
|
}
|
|
|
|
toggle() {
|
|
if (this.isOpen) {
|
|
this.close();
|
|
} else {
|
|
this.open();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
this.shadowRoot.innerHTML = `
|
|
<style>
|
|
:host {
|
|
--drawer-width: 320px;
|
|
--drawer-bg: #ffffff;
|
|
--drawer-header-bg: #951D51;
|
|
--drawer-header-color: #ffffff;
|
|
--backdrop-color: rgba(0, 0, 0, 0.5);
|
|
--transition-duration: 300ms;
|
|
--section-title-color: #64748b;
|
|
--link-color: #1e293b;
|
|
--link-hover-color: #951D51;
|
|
--border-color: #e2e8f0;
|
|
}
|
|
|
|
.drawer-container {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
z-index: 1000;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.drawer-container.open {
|
|
pointer-events: auto;
|
|
}
|
|
|
|
.backdrop {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: var(--backdrop-color);
|
|
opacity: 0;
|
|
transition: opacity var(--transition-duration) ease;
|
|
}
|
|
|
|
.drawer-container.open .backdrop {
|
|
opacity: 1;
|
|
}
|
|
|
|
.drawer {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: min(var(--drawer-width), 85vw);
|
|
height: 100%;
|
|
background-color: var(--drawer-bg);
|
|
transform: translateX(-100%);
|
|
transition: transform var(--transition-duration) cubic-bezier(0.4, 0, 0.2, 1);
|
|
display: flex;
|
|
flex-direction: column;
|
|
box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
|
|
}
|
|
|
|
.drawer-container.open .drawer {
|
|
transform: translateX(0);
|
|
}
|
|
|
|
.drawer-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 12px 16px;
|
|
background-color: var(--drawer-header-bg);
|
|
color: var(--drawer-header-color);
|
|
min-height: 56px;
|
|
}
|
|
|
|
.drawer-logo {
|
|
font-family: var(--font-family-base, system-ui);
|
|
font-size: 1.125rem;
|
|
font-weight: 700;
|
|
color: inherit;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.close-button {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 32px;
|
|
height: 32px;
|
|
background: #ffffff;
|
|
border: none;
|
|
border-radius: 50%;
|
|
cursor: pointer;
|
|
color: #951D51;
|
|
transition: all 150ms ease;
|
|
}
|
|
|
|
.close-button:hover {
|
|
background: #f1f5f9;
|
|
transform: scale(1.05);
|
|
}
|
|
|
|
.close-button:focus {
|
|
outline: 2px solid rgba(255, 255, 255, 0.5);
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
.drawer-content {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
overflow-x: hidden;
|
|
padding: 0;
|
|
}
|
|
|
|
.nav-section {
|
|
padding: 20px 16px;
|
|
border-bottom: 1px solid var(--border-color);
|
|
}
|
|
|
|
.nav-section:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.nav-section-title {
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
color: var(--section-title-color);
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.nav-list {
|
|
list-style: none;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
|
|
.nav-list a {
|
|
display: block;
|
|
padding: 10px 12px;
|
|
color: var(--link-color);
|
|
text-decoration: none;
|
|
font-size: 0.9375rem;
|
|
border-radius: 8px;
|
|
transition: all 150ms ease;
|
|
}
|
|
|
|
.nav-list a:hover {
|
|
background-color: #f1f5f9;
|
|
color: var(--link-hover-color);
|
|
}
|
|
|
|
.nav-list a:focus {
|
|
outline: 2px solid var(--link-hover-color);
|
|
outline-offset: -2px;
|
|
}
|
|
|
|
/* Milinda section - smaller styling */
|
|
.nav-section.milinda .nav-section-title {
|
|
font-size: 0.6875rem;
|
|
}
|
|
|
|
.nav-section.milinda .nav-list a {
|
|
font-size: 0.875rem;
|
|
padding: 8px 12px;
|
|
}
|
|
|
|
.drawer-footer {
|
|
padding: 20px 16px;
|
|
border-top: 1px solid var(--border-color);
|
|
background-color: #f8fafc;
|
|
}
|
|
|
|
.auth-buttons {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
|
|
.btn {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 12px 20px;
|
|
font-size: 0.9375rem;
|
|
font-weight: 600;
|
|
border-radius: 10px;
|
|
border: none;
|
|
cursor: pointer;
|
|
transition: all 150ms ease;
|
|
text-decoration: none;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: #951D51;
|
|
color: #ffffff;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #7a1842;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background-color: transparent;
|
|
color: #951D51;
|
|
border: 2px solid #951D51;
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background-color: #951D51;
|
|
color: #ffffff;
|
|
}
|
|
|
|
.btn:focus {
|
|
outline: 2px solid #951D51;
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
/* Scrollbar styling */
|
|
.drawer-content::-webkit-scrollbar {
|
|
width: 6px;
|
|
}
|
|
|
|
.drawer-content::-webkit-scrollbar-track {
|
|
background: transparent;
|
|
}
|
|
|
|
.drawer-content::-webkit-scrollbar-thumb {
|
|
background-color: #cbd5e1;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.drawer-content::-webkit-scrollbar-thumb:hover {
|
|
background-color: #94a3b8;
|
|
}
|
|
</style>
|
|
|
|
<div class="drawer-container">
|
|
<div class="backdrop"></div>
|
|
<nav class="drawer" aria-label="Main navigation">
|
|
<div class="drawer-header">
|
|
<a href="index.html" class="drawer-logo">Milinda</a>
|
|
<button class="close-button" aria-label="Sluit menu">
|
|
<close-icon size="18" color="#951D51"></close-icon>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="drawer-content">
|
|
<div class="nav-section">
|
|
<h2 class="nav-section-title">Onderwerpen</h2>
|
|
<ul class="nav-list">
|
|
<li><a href="#">Boeddhisme (algemeen)</a></li>
|
|
<li><a href="#">Theravada</a></li>
|
|
<li><a href="#">Zen</a></li>
|
|
<li><a href="#">Tibetaans boeddhisme</a></li>
|
|
<li><a href="#">Meditatie</a></li>
|
|
<li><a href="#">Mindfulness</a></li>
|
|
<li><a href="#">Vipassana</a></li>
|
|
<li><a href="#">Pali-canon</a></li>
|
|
<li><a href="#">Biografie / autobiografie</a></li>
|
|
<li><a href="#">Kinderboeken</a></li>
|
|
<li><a href="#">Alle onderwerpen bekijken</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section">
|
|
<h2 class="nav-section-title">Imprints</h2>
|
|
<ul class="nav-list">
|
|
<li><a href="#">Asoka</a></li>
|
|
<li><a href="#">Bodhi</a></li>
|
|
<li><a href="#">Dharma</a></li>
|
|
<li><a href="#">Sangha</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section milinda">
|
|
<h2 class="nav-section-title">Milinda</h2>
|
|
<ul class="nav-list">
|
|
<li><a href="#">Over ons</a></li>
|
|
<li><a href="#">Klantenservice</a></li>
|
|
<li><a href="#">Verzending & retourneren</a></li>
|
|
<li><a href="#">Nieuwsbrief</a></li>
|
|
<li><a href="#">Contact</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="drawer-footer">
|
|
<div class="auth-buttons">
|
|
<a href="#" class="btn btn-primary">Inloggen</a>
|
|
<a href="#" class="btn btn-secondary">Registreren</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
customElements.define("mobile-drawer", MobileDrawer);
|