Skip to content

Commit daafca8

Browse files
CopilotBoshen
andauthored
Fix main content padding when sidebar collapses (#120)
* Initial plan * Add sidebar context and dynamic padding based on collapse state Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
1 parent f780e87 commit daafca8

4 files changed

Lines changed: 79 additions & 46 deletions

File tree

apps/dashboard/src/App.tsx

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { lazy, Suspense } from "react";
22
import { Route, Routes } from "react-router-dom";
33
import Layout from "./components/Layout";
4+
import { SidebarProvider } from "./context/SidebarContext";
45

56
// Lazy load all page components for code-splitting
67
const HomePage = lazy(() => import("./pages/HomePage"));
@@ -18,50 +19,52 @@ const PageLoader = () => (
1819

1920
function App() {
2021
return (
21-
<Routes>
22-
<Route path="/" element={<Layout />}>
23-
<Route
24-
index
25-
element={
26-
<Suspense fallback={<PageLoader />}>
27-
<HomePage />
28-
</Suspense>
29-
}
30-
/>
31-
<Route
32-
path="rolldown-stats"
33-
element={
34-
<Suspense fallback={<PageLoader />}>
35-
<RolldownStatsPage />
36-
</Suspense>
37-
}
38-
/>
39-
<Route
40-
path="minification"
41-
element={
42-
<Suspense fallback={<PageLoader />}>
43-
<MinificationBenchmarksPage />
44-
</Suspense>
45-
}
46-
/>
47-
<Route
48-
path="npm-packages"
49-
element={
50-
<Suspense fallback={<PageLoader />}>
51-
<NpmPackagesPage />
52-
</Suspense>
53-
}
54-
/>
55-
<Route
56-
path="dependents"
57-
element={
58-
<Suspense fallback={<PageLoader />}>
59-
<DependentsPage />
60-
</Suspense>
61-
}
62-
/>
63-
</Route>
64-
</Routes>
22+
<SidebarProvider>
23+
<Routes>
24+
<Route path="/" element={<Layout />}>
25+
<Route
26+
index
27+
element={
28+
<Suspense fallback={<PageLoader />}>
29+
<HomePage />
30+
</Suspense>
31+
}
32+
/>
33+
<Route
34+
path="rolldown-stats"
35+
element={
36+
<Suspense fallback={<PageLoader />}>
37+
<RolldownStatsPage />
38+
</Suspense>
39+
}
40+
/>
41+
<Route
42+
path="minification"
43+
element={
44+
<Suspense fallback={<PageLoader />}>
45+
<MinificationBenchmarksPage />
46+
</Suspense>
47+
}
48+
/>
49+
<Route
50+
path="npm-packages"
51+
element={
52+
<Suspense fallback={<PageLoader />}>
53+
<NpmPackagesPage />
54+
</Suspense>
55+
}
56+
/>
57+
<Route
58+
path="dependents"
59+
element={
60+
<Suspense fallback={<PageLoader />}>
61+
<DependentsPage />
62+
</Suspense>
63+
}
64+
/>
65+
</Route>
66+
</Routes>
67+
</SidebarProvider>
6568
);
6669
}
6770

apps/dashboard/src/components/Layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Outlet } from "react-router-dom";
22
import { AppBar } from "./layout/AppBar";
33
import { Sidebar } from "./layout/Sidebar";
4+
import { useSidebar } from "../context/SidebarContext";
45

56
function Layout() {
7+
const { collapsed } = useSidebar();
8+
69
return (
710
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50/30 to-purple-50/30 dark:from-slate-950 dark:via-slate-900 dark:to-slate-950 relative overflow-hidden">
811
{/* Background decorative elements */}
@@ -12,7 +15,7 @@ function Layout() {
1215
<Sidebar />
1316

1417
{/* Main Content Area */}
15-
<div className="lg:pl-64 transition-all duration-300 relative z-10">
18+
<div className={`${collapsed ? "lg:pl-20" : "lg:pl-64"} transition-all duration-300 relative z-10`}>
1619
<div className="flex flex-col h-screen">
1720
<AppBar />
1821

apps/dashboard/src/components/layout/Sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BarChart3, ChevronLeft, Download, GitBranch, Home, Menu, Package, X, Zap } from "lucide-react";
22
import { useEffect, useState } from "react";
33
import { Link, useLocation } from "react-router-dom";
4+
import { useSidebar } from "../../context/SidebarContext";
45

56
interface NavItem {
67
path: string;
@@ -39,7 +40,7 @@ const navItems: NavItem[] = [
3940

4041
export function Sidebar() {
4142
const location = useLocation();
42-
const [collapsed, setCollapsed] = useState(false);
43+
const { collapsed, setCollapsed } = useSidebar();
4344
const [mobileOpen, setMobileOpen] = useState(false);
4445
// Auto-detect dark mode from system preferences
4546
useEffect(() => {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createContext, useContext, useState } from "react";
2+
3+
interface SidebarContextType {
4+
collapsed: boolean;
5+
setCollapsed: (collapsed: boolean) => void;
6+
}
7+
8+
const SidebarContext = createContext<SidebarContextType | undefined>(undefined);
9+
10+
export function SidebarProvider({ children }: { children: React.ReactNode }) {
11+
const [collapsed, setCollapsed] = useState(false);
12+
13+
return (
14+
<SidebarContext.Provider value={{ collapsed, setCollapsed }}>
15+
{children}
16+
</SidebarContext.Provider>
17+
);
18+
}
19+
20+
export function useSidebar() {
21+
const context = useContext(SidebarContext);
22+
if (context === undefined) {
23+
throw new Error("useSidebar must be used within a SidebarProvider");
24+
}
25+
return context;
26+
}

0 commit comments

Comments
 (0)