ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(ui): add mobile navigation drawer for narrow viewports
Juan Denis6172ffe0b923
diff --git a/frontend/index.html b/frontend/index.htmlindex c1fcdfa5..6541565f 100644--- a/frontend/index.html+++ b/frontend/index.html@@ -6,7 +6,7 @@<link rel="icon" type="image/x-icon" href="/favicon.ico" /><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" /><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />- <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" /><meta name="description" content="ServerKit - Server Management Dashboard" /><title>ServerKit</title><script>diff --git a/frontend/src/components/MobileTopBar.jsx b/frontend/src/components/MobileTopBar.jsxnew file mode 100644index 00000000..91763888--- /dev/null+++ b/frontend/src/components/MobileTopBar.jsx@@ -0,0 +1,43 @@+import { Menu, X } from 'lucide-react';+import { useTheme } from '../contexts/ThemeContext';+import ServerKitLogo from './ServerKitLogo';++// Fixed header shown only on narrow viewports (< 768px). Houses the+// hamburger toggle that opens the sidebar as an off-canvas drawer, since+// the persistent sidebar is hidden at this width. Hidden on desktop via CSS.+const MobileTopBar = ({ navOpen, onToggle }) => {+ const { whiteLabel } = useTheme();+ const branded = whiteLabel?.enabled;+ const brandName = branded ? (whiteLabel.brandName || 'Brand') : 'ServerKit';+ const showCustomLogo = branded && whiteLabel.logoData && whiteLabel.mode !== 'text_only';++ return (+ <header className="mobile-topbar">+ <button+ type="button"+ className="mobile-topbar__toggle"+ aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}+ aria-expanded={navOpen}+ aria-controls="primary-navigation"+ onClick={onToggle}+ >+ {navOpen ? <X size={22} aria-hidden="true" /> : <Menu size={22} aria-hidden="true" />}+ </button>+ <div className="mobile-topbar__brand">+ {!branded && (+ <span className="mobile-topbar__logo">+ <ServerKitLogo width={26} height={26} />+ </span>+ )}+ {showCustomLogo && (+ <span className="mobile-topbar__logo">+ <img src={whiteLabel.logoData} alt="" />+ </span>+ )}+ <span className="mobile-topbar__name">{brandName}</span>+ </div>+ </header>+ );+};++export default MobileTopBar;diff --git a/frontend/src/components/Sidebar.jsx b/frontend/src/components/Sidebar.jsxindex 017d6429..391900c7 100644--- a/frontend/src/components/Sidebar.jsx+++ b/frontend/src/components/Sidebar.jsx@@ -2,13 +2,13 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';import { NavLink, useNavigate, useLocation } from 'react-router-dom';import { useAuth } from '../contexts/AuthContext';import { useTheme } from '../contexts/ThemeContext';-import { Star, Settings, LogOut, Sun, Moon, Monitor, ChevronRight, ChevronDown, ChevronUp, Layers, Palette, PanelLeft, Check } from 'lucide-react';+import { Star, Settings, LogOut, Sun, Moon, Monitor, ChevronRight, ChevronDown, ChevronUp, Layers, Palette, PanelLeft, Check, X } from 'lucide-react';import { api } from '../services/api';import ServerKitLogo from './ServerKitLogo';import { SIDEBAR_CATEGORIES, CATEGORY_LABELS, SIDEBAR_PRESETS, getHiddenItemIds, getVisibleItems } from './sidebarItems';import { useContributions } from '../plugins/contributions';-const Sidebar = () => {+const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {} }) => {const { user, logout, updateUser } = useAuth();const { theme, resolvedTheme, setTheme, whiteLabel } = useTheme();const navigate = useNavigate();@@ -16,6 +16,59 @@ const Sidebar = () => {const [menuOpen, setMenuOpen] = useState(false);const [wpInstalled, setWpInstalled] = useState(false);const menuRef = useRef(null);+ const sidebarRef = useRef(null);++ // When collapsed to a drawer and closed, take the whole subtree out of the+ // tab order and the accessibility tree. `inert` is set imperatively so it+ // works on React 18 (which doesn't forward the attribute).+ useEffect(() => {+ const el = sidebarRef.current;+ if (!el) return;+ el.toggleAttribute('inert', isMobile && !mobileOpen);+ }, [isMobile, mobileOpen]);++ // Open drawer: focus the first control, trap Tab, close on Escape, and+ // return focus to the menu toggle on close.+ useEffect(() => {+ if (!isMobile || !mobileOpen) return undefined;+ const el = sidebarRef.current;+ if (!el) return undefined;++ const getFocusable = () => Array.from(+ el.querySelectorAll(+ 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'+ )+ ).filter((node) => node.offsetParent !== null);++ const focusables = getFocusable();+ (focusables[0] || el).focus();++ const handleKeyDown = (e) => {+ if (e.key === 'Escape') {+ e.preventDefault();+ onMobileClose();+ return;+ }+ if (e.key !== 'Tab') return;+ const items = getFocusable();+ if (items.length === 0) return;+ const first = items[0];+ const last = items[items.length - 1];+ if (e.shiftKey && document.activeElement === first) {+ e.preventDefault();+ last.focus();+ } else if (!e.shiftKey && document.activeElement === last) {+ e.preventDefault();+ first.focus();+ }+ };++ el.addEventListener('keydown', handleKeyDown);+ return () => {+ el.removeEventListener('keydown', handleKeyDown);+ document.querySelector('.mobile-topbar__toggle')?.focus();+ };+ }, [isMobile, mobileOpen, onMobileClose]);// Close menu when clicking outsideuseEffect(() => {@@ -188,7 +241,22 @@ const Sidebar = () => {};return (- <aside className="sidebar">+ <aside+ ref={sidebarRef}+ id="primary-navigation"+ className={`sidebar${mobileOpen ? ' sidebar--mobile-open' : ''}`}+ aria-label="Main navigation"+ >+ {isMobile && (+ <button+ type="button"+ className="sidebar__close"+ aria-label="Close navigation menu"+ onClick={onMobileClose}+ >+ <X size={20} aria-hidden="true" />+ </button>+ )}{whiteLabel.enabled ? (<div className="brand-section brand-section--custom">{whiteLabel.mode === 'image_full' ? (diff --git a/frontend/src/hooks/useMediaQuery.js b/frontend/src/hooks/useMediaQuery.jsnew file mode 100644index 00000000..7e9b452e--- /dev/null+++ b/frontend/src/hooks/useMediaQuery.js@@ -0,0 +1,29 @@+import { useState, useEffect } from 'react';++// Subscribe to a CSS media query and re-render when it changes.+// Returns the current match as a boolean. SSR-safe (defaults to false+// when matchMedia is unavailable).+export default function useMediaQuery(query) {+ const getMatch = () => (+ typeof window !== 'undefined' && typeof window.matchMedia === 'function'+ ? window.matchMedia(query).matches+ : false+ );++ const [matches, setMatches] = useState(getMatch);++ useEffect(() => {+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {+ return undefined;+ }+ const mql = window.matchMedia(query);+ const onChange = (e) => setMatches(e.matches);++ // Sync immediately in case the query changed between render and effect.+ setMatches(mql.matches);+ mql.addEventListener('change', onChange);+ return () => mql.removeEventListener('change', onChange);+ }, [query]);++ return matches;+}diff --git a/frontend/src/layouts/DashboardLayout.jsx b/frontend/src/layouts/DashboardLayout.jsxindex 01947ac8..3e679c24 100644--- a/frontend/src/layouts/DashboardLayout.jsx+++ b/frontend/src/layouts/DashboardLayout.jsx@@ -1,11 +1,13 @@import { useState, useEffect, useCallback, useMemo } from 'react';import { Outlet, useLocation } from 'react-router-dom';import Sidebar from '../components/Sidebar';+import MobileTopBar from '../components/MobileTopBar';import CommandPalette from '../components/CommandPalette';import LogsDrawer from '../components/LogsDrawer';import { LogsDrawerProvider } from '../contexts/LogsDrawerContext';import PluginLoader from '../plugins/PluginLoader';import { refreshContributions, useContributions } from '../plugins/contributions';+import useMediaQuery from '../hooks/useMediaQuery';import api from '../services/api';const FULL_PAGE_ROUTES = ['/workflow', '/files', '/docker'];@@ -13,6 +15,10 @@ const FULL_PAGE_ROUTES = ['/workflow', '/files', '/docker'];const DashboardLayout = () => {const location = useLocation();const [paletteOpen, setPaletteOpen] = useState(false);+ const [navOpen, setNavOpen] = useState(false);+ // Matches the sidebar's $breakpoint-md (768px). Below it the persistent+ // sidebar collapses into an off-canvas drawer driven by navOpen.+ const isMobile = useMediaQuery('(max-width: 768px)');const { routes: pluginRoutes } = useContributions();// Plugin routes contribute their path relative to the dashboard@@ -44,6 +50,24 @@ const DashboardLayout = () => {return () => document.removeEventListener('keydown', handleKeyDown);}, [handleKeyDown]);+ // Close the mobile drawer on navigation (covers nav-link taps too).+ useEffect(() => {+ setNavOpen(false);+ }, [location.pathname]);++ // Never leave the drawer "open" when we cross back to the desktop layout.+ useEffect(() => {+ if (!isMobile) setNavOpen(false);+ }, [isMobile]);++ // Lock body scroll behind the drawer while it's open on mobile.+ useEffect(() => {+ if (!(isMobile && navOpen)) return undefined;+ const previous = document.body.style.overflow;+ document.body.style.overflow = 'hidden';+ return () => { document.body.style.overflow = previous; };+ }, [isMobile, navOpen]);+// Load plugin contributions once we're authenticated. Subscribers// (Sidebar, CommandPalette, ExtensionRoutes, PageTitleUpdater) all// pick up the result via useContributions().@@ -54,7 +78,19 @@ const DashboardLayout = () => {return (<LogsDrawerProvider><div className="dashboard-layout">- <Sidebar />+ <MobileTopBar navOpen={navOpen} onToggle={() => setNavOpen(prev => !prev)} />+ <Sidebar+ mobileOpen={navOpen}+ isMobile={isMobile}+ onMobileClose={() => setNavOpen(false)}+ />+ {isMobile && navOpen && (+ <div+ className="sidebar-backdrop"+ onClick={() => setNavOpen(false)}+ aria-hidden="true"+ />+ )}<main className={`main-content${isFullPageRoute ? ' main-content--full-page' : ''}`}><Outlet /></main>diff --git a/frontend/src/styles/_variables.scss b/frontend/src/styles/_variables.scssindex 5a80ba91..221bebc6 100644--- a/frontend/src/styles/_variables.scss+++ b/frontend/src/styles/_variables.scss@@ -186,6 +186,7 @@ $transition-slow: 0.3s ease;// --------------------------------------------$sidebar-width: 280px;$header-height: 64px;+$mobile-header-height: 56px;$sidebar-header-height: 70px;$sidebar-logo-size: 42px;$sidebar-icon-size: 28px;diff --git a/frontend/src/styles/layout/_main-content.scss b/frontend/src/styles/layout/_main-content.scssindex ab232ef0..c0be0280 100644--- a/frontend/src/styles/layout/_main-content.scss+++ b/frontend/src/styles/layout/_main-content.scss@@ -20,7 +20,8 @@@media (max-width: $breakpoint-md) {margin-left: 0;- padding: $space-5;+ // Clear the fixed mobile header (plus the notch inset, if any).+ padding: calc(#{$mobile-header-height} + env(safe-area-inset-top) + #{$space-5}) $space-5 $space-5;}// Remove padding for routed tool surfaces that manage their own layout.@@ -30,6 +31,12 @@padding: 0;overflow: hidden;height: 100vh;++ // Full-bleed tools still sit below the fixed mobile header.+ @media (max-width: $breakpoint-md) {+ height: calc(100dvh - #{$mobile-header-height} - env(safe-area-inset-top));+ margin-top: calc(#{$mobile-header-height} + env(safe-area-inset-top));+ }}}diff --git a/frontend/src/styles/layout/_sidebar.scss b/frontend/src/styles/layout/_sidebar.scssindex 192fc8d5..0800e1f0 100644--- a/frontend/src/styles/layout/_sidebar.scss+++ b/frontend/src/styles/layout/_sidebar.scss@@ -13,11 +13,147 @@z-index: $z-fixed;padding: 0 1rem;+ // Below the breakpoint the persistent rail becomes an off-canvas drawer+ // (it stays mounted so its scroll position and state survive open/close).@media (max-width: $breakpoint-md) {- display: none;+ top: 0;+ left: 0;+ height: 100dvh;+ width: min(280px, 86vw);+ padding-left: max(1rem, env(safe-area-inset-left));+ padding-top: env(safe-area-inset-top);+ z-index: $z-modal;+ transform: translateX(-100%);+ transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);+ will-change: transform;++ &.sidebar--mobile-open {+ transform: translateX(0);+ box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);+ }++ @media (prefers-reduced-motion: reduce) {+ transition: none;+ }+ }+}++// Drawer close button — only rendered/visible in the mobile drawer.+.sidebar__close {+ display: none;++ @media (max-width: $breakpoint-md) {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 44px;+ height: 44px;+ margin: $space-2 0 $space-1 auto;+ border: none;+ background: transparent;+ color: $text-secondary;+ border-radius: $radius-md;+ cursor: pointer;+ @include transition(color);+ @include focus-ring();++ &:hover {+ color: $text-primary;+ background: rgba(255, 255, 255, 0.06);+ }+ }+}++// Scrim behind the drawer. Only mounted on mobile while the drawer is open.+.sidebar-backdrop {+ position: fixed;+ inset: 0;+ background: rgba(0, 0, 0, 0.6);+ z-index: $z-modal-backdrop;+ animation: sidebarBackdropIn 0.2s ease-out;++ @media (prefers-reduced-motion: reduce) {+ animation: none;+ }+}++@keyframes sidebarBackdropIn {+ from { opacity: 0; }+ to { opacity: 1; }+}++// Fixed top bar for narrow viewports — carries the hamburger + brand so the+// drawer is reachable. Hidden entirely on desktop.+.mobile-topbar {+ display: none;++ @media (max-width: $breakpoint-md) {+ display: flex;+ align-items: center;+ gap: $space-2;+ position: fixed;+ top: 0;+ left: 0;+ right: 0;+ height: calc(#{$mobile-header-height} + env(safe-area-inset-top));+ padding-top: env(safe-area-inset-top);+ padding-right: max(#{$space-4}, env(safe-area-inset-right));+ padding-left: max(#{$space-3}, env(safe-area-inset-left));+ background-color: $bg-sidebar;+ border-bottom: 1px solid $border-default;+ z-index: $z-sticky;+ }+}++.mobile-topbar__toggle {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 44px;+ height: 44px;+ flex-shrink: 0;+ border: none;+ background: transparent;+ color: $text-primary;+ border-radius: $radius-md;+ cursor: pointer;+ @include transition(background);+ @include focus-ring();++ &:hover {+ background: $bg-hover;}}+.mobile-topbar__brand {+ display: flex;+ align-items: center;+ gap: $space-2;+ min-width: 0;+}++.mobile-topbar__logo {+ display: grid;+ place-items: center;+ width: 26px;+ height: 26px;+ flex-shrink: 0;++ img {+ width: 100%;+ height: 100%;+ object-fit: contain;+ }+}++.mobile-topbar__name {+ font-size: 1.05rem;+ font-weight: $font-weight-bold;+ color: $text-primary;+ letter-spacing: -0.01em;+ @include truncate();+}+// Brand Section - Clean & Minimal.brand-section {height: $sidebar-header-height;