Make sidebar a responsive off-canvas drawer on mobile
The fixed 260px sidebar overlapped page content on phones. Below 768px it now slides off-canvas behind a hamburger top bar with a tap/Escape-dismissable backdrop, and the main content uses full width. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
62d799a60d
commit
52b3a69b89
5 files changed
+123
-1
No files matched your search
@@ -1098,6 +1098,50 @@ tr:last-child .actions-dropdown-menu {
|
||||
color: var(--color-brand-primary);
|
||||
}
|
||||
|
||||
/* Mobile top bar + drawer backdrop (hidden on desktop) */
|
||||
.mobile-topbar {
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background-color: var(--color-bg-surface);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 90;
|
||||
}
|
||||
|
||||
.mobile-topbar .brand {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-text-main);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mobile-menu-btn svg {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
.sidebar-backdrop {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
z-index: 99;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.public-header {
|
||||
padding: 1rem 1.5rem;
|
||||
@@ -1108,5 +1152,31 @@ tr:last-child .actions-dropdown-menu {
|
||||
.items-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
/* Show the mobile top bar */
|
||||
.mobile-topbar {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* Sidebar becomes an off-canvas drawer */
|
||||
.sidebar {
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.25s ease;
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
/* Backdrop visible only while the drawer is open */
|
||||
.sidebar-backdrop.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Content takes the full width; no reserved sidebar gutter */
|
||||
.main-wrapper {
|
||||
margin-left: 0;
|
||||
padding: 1.5rem 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,44 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// 4. Initialize drag and drop mechanics for directories and assets
|
||||
initDragAndDrop();
|
||||
|
||||
// 5. Mobile sidebar drawer interactions
|
||||
initMobileSidebar();
|
||||
});
|
||||
|
||||
// Mobile off-canvas sidebar drawer
|
||||
function toggleSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
if (!sidebar) return;
|
||||
sidebar.classList.contains("open") ? closeSidebar() : openSidebar();
|
||||
}
|
||||
|
||||
function openSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
const backdrop = document.querySelector(".sidebar-backdrop");
|
||||
if (sidebar) sidebar.classList.add("open");
|
||||
if (backdrop) backdrop.classList.add("show");
|
||||
}
|
||||
|
||||
function closeSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
const backdrop = document.querySelector(".sidebar-backdrop");
|
||||
if (sidebar) sidebar.classList.remove("open");
|
||||
if (backdrop) backdrop.classList.remove("show");
|
||||
}
|
||||
|
||||
function initMobileSidebar() {
|
||||
// Close the drawer after tapping a nav link so the destination is visible
|
||||
document.querySelectorAll(".sidebar .nav-link").forEach(link => {
|
||||
link.addEventListener("click", closeSidebar);
|
||||
});
|
||||
|
||||
// Close on Escape for keyboard/accessibility
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") closeSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
function setupToastListeners() {
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
|
||||
Reference in new issue
Block a user