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
@@ -14,6 +14,7 @@
|
||||
"nav.print_labels": "Print Labels",
|
||||
"nav.sign_out": "Sign Out",
|
||||
"nav.admin_login": "Admin Login",
|
||||
"nav.menu": "Menu",
|
||||
|
||||
"common.cancel": "Cancel",
|
||||
"common.save": "Save Changes",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"nav.print_labels": "打印标签",
|
||||
"nav.sign_out": "退出登录",
|
||||
"nav.admin_login": "管理员登录",
|
||||
"nav.menu": "菜单",
|
||||
|
||||
"common.cancel": "取消",
|
||||
"common.save": "保存更改",
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -19,7 +19,21 @@
|
||||
<div class="app-container {{if not .IsAuthenticated}}public-layout{{end}}">
|
||||
<!-- Sidebar Navigation -->
|
||||
{{if .IsAuthenticated}}
|
||||
<aside class="sidebar">
|
||||
<!-- Mobile Top Bar (hidden on desktop) -->
|
||||
<header class="mobile-topbar">
|
||||
<button type="button" class="mobile-menu-btn" aria-label="{{T "nav.menu"}}" aria-controls="sidebar" onclick="toggleSidebar()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
|
||||
</svg>
|
||||
</button>
|
||||
<div class="brand">
|
||||
<div class="brand-logo">S</div>
|
||||
<span class="brand-name">Solis</span>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Backdrop shown behind the drawer on mobile -->
|
||||
<div class="sidebar-backdrop" onclick="closeSidebar()"></div>
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="brand">
|
||||
<div class="brand-logo">S</div>
|
||||
<span class="brand-name">Solis</span>
|
||||
|
||||
Reference in new issue
Block a user