Skip to content

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.

feat(ui): add layout switcher with compact rail variant

Juan Deniscd16d9a47930
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 266fdcf3..d98e7325 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -3,6 +3,7 @@ import { BrowserRouter as Router, Routes, Route, Navigate, useLocation, useParam
import { AuthProvider, useAuth } from './contexts/AuthContext';
import { ToastProvider } from './contexts/ToastContext';
import { ThemeProvider } from './contexts/ThemeContext';
+import { LayoutProvider } from './contexts/LayoutContext';
import { ResourceTierProvider } from './contexts/ResourceTierContext';
import { Toaster } from './components/ui/sonner';
import DashboardLayout from './layouts/DashboardLayout';
@@ -319,14 +320,16 @@ function App() {
<Router>
<PageTitleUpdater />
<ThemeProvider>
- <AuthProvider>
- <ResourceTierProvider>
- <ToastProvider>
- <AppRoutes />
- <Toaster />
- </ToastProvider>
- </ResourceTierProvider>
- </AuthProvider>
+ <LayoutProvider>
+ <AuthProvider>
+ <ResourceTierProvider>
+ <ToastProvider>
+ <AppRoutes />
+ <Toaster />
+ </ToastProvider>
+ </ResourceTierProvider>
+ </AuthProvider>
+ </LayoutProvider>
</ThemeProvider>
</Router>
);
diff --git a/frontend/src/components/Sidebar.jsx b/frontend/src/components/Sidebar.jsx
index 8cd53689..fcb329ed 100644
--- a/frontend/src/components/Sidebar.jsx
+++ b/frontend/src/components/Sidebar.jsx
@@ -2,7 +2,8 @@ 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, X, Server } from 'lucide-react';
+import { useLayout } from '../contexts/LayoutContext';
+import { Star, Settings, LogOut, Sun, Moon, Monitor, ChevronRight, ChevronDown, ChevronUp, Layers, Palette, PanelLeft, PanelLeftClose, Check, X, Server } from 'lucide-react';
import { api } from '../services/api';
import WorkspaceSwitcher from './WorkspaceSwitcher';
import { SIDEBAR_CATEGORIES, CATEGORY_LABELS, SIDEBAR_PRESETS, getHiddenItemIds, getVisibleItems } from './sidebarItems';
@@ -11,6 +12,7 @@ import { useContributions } from '../plugins/contributions';
const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {} }) => {
const { user, logout, updateUser } = useAuth();
const { theme, resolvedTheme, setTheme, whiteLabel } = useTheme();
+ const { layout, setLayout } = useLayout();
const navigate = useNavigate();
const [menuOpen, setMenuOpen] = useState(false);
const [wpInstalled, setWpInstalled] = useState(false);
@@ -378,6 +380,31 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {
</button>
</div>
</div>
+ <div className="context-menu-section">
+ <div className="context-menu-label" id="layout-switcher-label">Layout</div>
+ <div className="theme-switcher" role="group" aria-labelledby="layout-switcher-label">
+ <button
+ type="button"
+ className={`theme-btn ${layout === 'sidebar' ? 'active' : ''}`}
+ onClick={() => setLayout('sidebar')}
+ aria-label="Sidebar layout"
+ aria-pressed={layout === 'sidebar'}
+ title="Sidebar"
+ >
+ <PanelLeft size={14} aria-hidden="true" />
+ </button>
+ <button
+ type="button"
+ className={`theme-btn ${layout === 'rail' ? 'active' : ''}`}
+ onClick={() => setLayout('rail')}
+ aria-label="Compact rail layout"
+ aria-pressed={layout === 'rail'}
+ title="Compact"
+ >
+ <PanelLeftClose size={14} aria-hidden="true" />
+ </button>
+ </div>
+ </div>
<div className="context-menu-section">
<div className="context-menu-label" id="sidebar-view-label">Sidebar View</div>
<div className="view-switcher" role="group" aria-labelledby="sidebar-view-label">
diff --git a/frontend/src/contexts/LayoutContext.jsx b/frontend/src/contexts/LayoutContext.jsx
new file mode 100644
index 00000000..8777275f
--- /dev/null
+++ b/frontend/src/contexts/LayoutContext.jsx
@@ -0,0 +1,43 @@
+import { createContext, useContext, useState, useEffect, useCallback } from 'react';
+
+const LayoutContext = createContext(null);
+
+// Shell geometry options, kept in sync with the switcher in Sidebar and the
+// [data-layout="..."] rules in styles/layout/_sidebar.scss. 'topbar' is reserved
+// for a later phase; any unknown or stale stored value falls back to 'sidebar'.
+const LAYOUTS = ['sidebar', 'rail'];
+const DEFAULT_LAYOUT = 'sidebar';
+
+const normalize = (value) => (LAYOUTS.includes(value) ? value : DEFAULT_LAYOUT);
+
+export function LayoutProvider({ children }) {
+ const [layout, setLayoutState] = useState(() => normalize(localStorage.getItem('layout')));
+
+ const setLayout = useCallback((next) => {
+ const value = normalize(next);
+ setLayoutState(value);
+ localStorage.setItem('layout', value);
+ document.documentElement.setAttribute('data-layout', value);
+ }, []);
+
+ // Mirror the persisted choice onto the document (matches ThemeContext).
+ useEffect(() => {
+ document.documentElement.setAttribute('data-layout', layout);
+ }, [layout]);
+
+ return (
+ <LayoutContext.Provider value={{ layout, setLayout }}>
+ {children}
+ </LayoutContext.Provider>
+ );
+}
+
+export function useLayout() {
+ const context = useContext(LayoutContext);
+ if (!context) {
+ throw new Error('useLayout must be used within a LayoutProvider');
+ }
+ return context;
+}
+
+export default LayoutContext;
diff --git a/frontend/src/styles/_variables.scss b/frontend/src/styles/_variables.scss
index f0169c7c..b96a6d73 100644
--- a/frontend/src/styles/_variables.scss
+++ b/frontend/src/styles/_variables.scss
@@ -216,6 +216,7 @@ $ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
// LAYOUT
// --------------------------------------------
$sidebar-width: 250px;
+$sidebar-rail-width: 64px;
$header-height: 64px;
$mobile-header-height: 56px;
$sidebar-header-height: 70px;
diff --git a/frontend/src/styles/layout/_sidebar.scss b/frontend/src/styles/layout/_sidebar.scss
index a17f7d46..9a1cbc11 100644
--- a/frontend/src/styles/layout/_sidebar.scss
+++ b/frontend/src/styles/layout/_sidebar.scss
@@ -696,3 +696,65 @@
box-shadow: 0 0 6px currentColor;
}
}
+
+// ============================================
+// COMPACT RAIL LAYOUT — [data-layout="rail"]
+// A 64px icon-only rail that expands to the full sidebar on hover/focus.
+// Desktop only: below $breakpoint-md the off-canvas drawer is unchanged.
+// ============================================
+@media (min-width: ($breakpoint-md + 1)) {
+ [data-layout="rail"] {
+ .main-content {
+ margin-left: $sidebar-rail-width;
+ }
+
+ .sidebar {
+ width: $sidebar-rail-width;
+ transition: width 0.18s $ease-out-quint;
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+
+ // Expand to the full sidebar while hovered or keyboard-focused. The
+ // panel is position: fixed, so it overlays content instead of
+ // pushing it — the .main-content offset stays at the rail width.
+ &:hover,
+ &:focus-within {
+ width: $sidebar-width;
+ box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
+ }
+
+ // Collapsed state: bare icon rail. font-size: 0 hides nav text while
+ // keeping it in the accessibility tree; fixed-size SVG icons stay.
+ &:not(:hover):not(:focus-within) {
+ .nav-item {
+ justify-content: center;
+ gap: 0;
+ font-size: 0;
+ }
+
+ .nav-sub-item {
+ padding-left: 0.625rem;
+ }
+
+ .brand-section,
+ .workspace-switcher,
+ .user-mini {
+ justify-content: center;
+ gap: 0;
+ }
+
+ .brand-text,
+ .brand-star,
+ .nav-category,
+ .nav-expand-btn,
+ .workspace-switcher__select,
+ .user-meta,
+ .user-menu-arrow {
+ display: none;
+ }
+ }
+ }
+ }
+}