Admin portal: mobile-friendly layout + nav drawer
app.css:
- New .sor-admin-outer wrapper (flex column, 100vh) so topbar + shell stack vertically
- .sor-admin-shell changed from height:100vh to flex:1 (fills remaining space)
- .sor-admin-topbar: hidden on desktop (display:none), shown at <992px as a 56px
dark strip hosting the hamburger button and brand
- .sor-admin-sidebar: at <992px becomes a fixed overlay drawer (position:fixed,
translateX(-100%)), slides in with .open class (0.25s ease-in-out transition)
- .sor-admin-backdrop: full-screen dim overlay (z-index 1040), hidden on desktop
- Minor: tighter container-fluid padding on small screens
MainLayout.razor:
- Wrapped authorized shell in .sor-admin-outer
- Added mobile topbar with hamburger (<i class="bi bi-list">) + brand
- Added backdrop div rendered conditionally when _drawerOpen
- Drawer state (_drawerOpen bool) managed here; toggled by hamburger, closed
by backdrop click and automatically on any NavigationManager.LocationChanged
- Implements IDisposable to unsubscribe LocationChanged event handler
- Passes IsOpen parameter to NavMenu
NavMenu.razor:
- Added [Parameter] public bool IsOpen { get; set; }
- Applies "open" CSS class to <nav> when IsOpen is true
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1,17 +1,65 @@
|
||||
@inherits LayoutComponentBase
|
||||
@implements IDisposable
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="sor-admin-shell">
|
||||
<NavMenu />
|
||||
<main class="sor-admin-content">
|
||||
<div class="container-fluid py-4">
|
||||
@Body
|
||||
</div>
|
||||
</main>
|
||||
<div class="sor-admin-outer">
|
||||
|
||||
@* Mobile topbar: hamburger + brand. Hidden on desktop via CSS. *@
|
||||
<div class="sor-admin-topbar">
|
||||
<button class="btn btn-link text-white p-0 me-3"
|
||||
@onclick="ToggleDrawer"
|
||||
aria-label="Toggle navigation">
|
||||
<i class="bi bi-list fs-3"></i>
|
||||
</button>
|
||||
<a class="text-white fw-bold text-decoration-none" href="/">
|
||||
<i class="bi bi-lightning-charge-fill text-warning me-2"></i>SOR Admin
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@* Backdrop: click outside the drawer to close it (mobile only). *@
|
||||
@if (_drawerOpen)
|
||||
{
|
||||
<div class="sor-admin-backdrop" @onclick="CloseDrawer"></div>
|
||||
}
|
||||
|
||||
<div class="sor-admin-shell">
|
||||
<NavMenu IsOpen="_drawerOpen" />
|
||||
<main class="sor-admin-content">
|
||||
<div class="container-fluid py-4">
|
||||
@Body
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
@Body
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
private bool _drawerOpen;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Nav.LocationChanged += OnLocationChanged;
|
||||
}
|
||||
|
||||
// Close the drawer automatically whenever the user navigates to any page.
|
||||
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
||||
{
|
||||
_drawerOpen = false;
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
|
||||
private void CloseDrawer() => _drawerOpen = false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Nav.LocationChanged -= OnLocationChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@inject IJSRuntime Js
|
||||
|
||||
<nav class="sor-admin-sidebar d-flex flex-column bg-dark text-white p-3">
|
||||
<nav class="sor-admin-sidebar d-flex flex-column bg-dark text-white p-3 @(IsOpen ? "open" : "")">
|
||||
<a class="navbar-brand text-white fw-bold fs-5 mb-4 text-decoration-none" href="/">
|
||||
<i class="bi bi-lightning-charge-fill text-warning me-2"></i>SOR Admin
|
||||
</a>
|
||||
@@ -138,6 +138,8 @@
|
||||
</nav>
|
||||
|
||||
@code {
|
||||
[Parameter] public bool IsOpen { get; set; }
|
||||
|
||||
private string _theme = "light";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
|
||||
@@ -5,9 +5,28 @@ html, body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ── Outer wrapper ──────────────────────────────────────────────────────────── */
|
||||
/* Stacks the mobile topbar above the shell (sidebar + content). */
|
||||
|
||||
.sor-admin-outer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Mobile topbar ──────────────────────────────────────────────────────────── */
|
||||
/* Hidden on desktop; slides in on mobile to host the hamburger + brand. */
|
||||
|
||||
.sor-admin-topbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ── Shell: sidebar + content ───────────────────────────────────────────────── */
|
||||
|
||||
.sor-admin-shell {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -35,7 +54,71 @@ html, body {
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
/* Monospace JSON editor */
|
||||
/* ── Drawer backdrop ────────────────────────────────────────────────────────── */
|
||||
/* Rendered conditionally in DOM; hidden via media query on desktop so it
|
||||
can never accidentally block clicks if rendered at a wide viewport. */
|
||||
|
||||
.sor-admin-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1040;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.sor-admin-backdrop {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Mobile overrides (< lg = 992px) ────────────────────────────────────────── */
|
||||
|
||||
@media (max-width: 991.98px) {
|
||||
/* Topbar strip: hamburger + brand */
|
||||
.sor-admin-topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 56px;
|
||||
padding: 0 1rem;
|
||||
background: var(--bs-dark, #212529);
|
||||
color: white;
|
||||
flex-shrink: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* Sidebar becomes a fixed overlay drawer, slides in from the left */
|
||||
.sor-admin-sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
z-index: 1045; /* above Bootstrap modal backdrop (1040) */
|
||||
width: 260px;
|
||||
min-width: 260px;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.25s ease-in-out;
|
||||
box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.sor-admin-sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
/* Content fills full width since sidebar is out of flow */
|
||||
.sor-admin-content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Tighten up page padding on small screens */
|
||||
.sor-admin-content .container-fluid {
|
||||
padding-left: 0.75rem;
|
||||
padding-right: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Monospace JSON editor ──────────────────────────────────────────────────── */
|
||||
|
||||
.font-monospace {
|
||||
font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
|
||||
font-size: 0.85rem;
|
||||
|
||||
Reference in New Issue
Block a user