-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocsLayout.tsx
More file actions
242 lines (223 loc) · 7.85 KB
/
Copy pathDocsLayout.tsx
File metadata and controls
242 lines (223 loc) · 7.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { useState, useEffect } from "react";
import { Link, useLocation } from "react-router-dom";
import { FiMenu, FiX, FiChevronRight, FiSearch, FiExternalLink } from "react-icons/fi";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import Header from "./Header";
import Footer from "./Footer";
interface DocsLayoutProps {
children: React.ReactNode;
}
type DocLink = {
title: string;
href: string;
external?: boolean;
};
type DocSection = {
title: string;
links: DocLink[];
};
// Documentation structure
const docSections: DocSection[] = [
{
title: "Getting Started",
links: [
{ title: "Introduction", href: "/docs" },
// { title: "Configuration", href: "/docs/configuration" }
]
},
// {
// title: "Convention",
// links: [
// { title: "Convention Overview", href: "/docs/convention" }
// ]
// },
// {
// title: "Reference",
// links: [
// { title: "Reference Guide", href: "/docs/reference" }
// ]
// },
{
title: "Tools",
links: [
{ title: "Linter", href: "https://security-commits.org/secomlint/", external: true },
{ title: "Dataset", href: "https://github.com/security-commits/security-patches-dataset", external: true },
]
},
{
title: "External Resources",
links: [
// { title: "Blog", href: "/blog" },
{ title: "GitHub Organization", href: "https://github.com/security-commits/secom", external: true }
]
}
];
const DocsLayout = ({ children }: DocsLayoutProps) => {
const [sidebarOpen, setSidebarOpen] = useState(false);
const location = useLocation();
const currentPath = location.pathname;
// Find previous and next pages for navigation
const allLinks = docSections.flatMap(section => section.links);
const currentPageIndex = allLinks.findIndex(link => link.href === currentPath);
const prevPage = currentPageIndex > 0 ? allLinks[currentPageIndex - 1] : null;
const nextPage = currentPageIndex < allLinks.length - 1 ? allLinks[currentPageIndex + 1] : null;
// Close sidebar on mobile when navigating
useEffect(() => {
setSidebarOpen(false);
}, [location]);
// Close sidebar when clicking outside on mobile
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
const sidebar = document.getElementById("docs-sidebar");
const toggleButton = document.getElementById("sidebar-toggle");
if (
sidebarOpen &&
sidebar &&
!sidebar.contains(event.target as Node) &&
toggleButton &&
!toggleButton.contains(event.target as Node)
) {
setSidebarOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [sidebarOpen]);
return (
<div className="min-h-screen bg-background flex flex-col">
<Header />
<div className="flex-1 flex flex-col md:flex-row">
{/* Mobile sidebar toggle */}
<div className="md:hidden p-4 border-b sticky top-16 z-10 bg-background">
<Button
id="sidebar-toggle"
variant="outline"
size="sm"
className="flex items-center gap-2"
onClick={() => setSidebarOpen(!sidebarOpen)}
>
{sidebarOpen ? <FiX size={16} /> : <FiMenu size={16} />}
{sidebarOpen ? "Close Menu" : "Documentation Menu"}
</Button>
</div>
{/* Sidebar */}
<aside
id="docs-sidebar"
className={`
bg-muted/30 border-r w-72 overflow-y-auto
fixed md:sticky top-16 bottom-0
md:h-[calc(100vh-4rem)] h-full z-30
transition-transform duration-300 ease-in-out
${sidebarOpen ? "translate-x-0" : "-translate-x-full md:translate-x-0"}
`}
>
<nav className="p-4">
{docSections.map((section, i) => (
<div key={i} className="mb-6">
<h3 className="font-medium text-sm text-muted-foreground mb-2">
{section.title}
</h3>
<ul className="space-y-1">
{section.links.map((link, j) => {
const isActive = currentPath === link.href;
const linkContent = (
<div className="flex items-center justify-between w-full">
<span>{link.title}</span>
{link.external && <FiExternalLink size={14} />}
</div>
);
return (
<li key={j}>
{link.external ? (
<a
href={link.href}
target="_blank"
rel="noopener noreferrer"
className={`
flex items-center text-sm px-3 py-2 rounded-md
hover:bg-accent hover:text-accent-foreground
${isActive ? "bg-accent text-accent-foreground" : ""}
`}
>
{linkContent}
</a>
) : (
<Link
to={link.href}
className={`
flex items-center text-sm px-3 py-2 rounded-md
hover:bg-accent hover:text-accent-foreground
${isActive ? "bg-accent text-accent-foreground" : ""}
`}
>
{linkContent}
</Link>
)}
</li>
);
})}
</ul>
</div>
))}
</nav>
</aside>
{/* Main content */}
<main className="flex-1 px-4 md:px-8 max-w-5xl mx-auto w-full mt-6 md:mt-10">
{children}
{/* Previous/Next navigation */}
<div className="mt-16 border-t pt-6 flex justify-between">
{prevPage ? (
<Button
variant="outline"
size="sm"
className="flex items-center gap-1"
asChild
>
{prevPage.external ? (
<a href={prevPage.href} target="_blank" rel="noopener noreferrer">
<FiChevronRight className="rotate-180" />
{prevPage.title}
</a>
) : (
<Link to={prevPage.href}>
<FiChevronRight className="rotate-180" />
{prevPage.title}
</Link>
)}
</Button>
) : (
<div></div> // Empty div for spacing when there's no previous page
)}
{nextPage ? (
<Button
variant="outline"
size="sm"
className="flex items-center gap-1"
asChild
>
{nextPage.external ? (
<a href={nextPage.href} target="_blank" rel="noopener noreferrer">
{nextPage.title}
<FiChevronRight />
</a>
) : (
<Link to={nextPage.href}>
{nextPage.title}
<FiChevronRight />
</Link>
)}
</Button>
) : (
<div></div> // Empty div for spacing when there's no next page
)}
</div>
</main>
</div>
<Footer />
</div>
);
};
export default DocsLayout;