-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs-sidebar.tsx
More file actions
165 lines (157 loc) · 5.61 KB
/
docs-sidebar.tsx
File metadata and controls
165 lines (157 loc) · 5.61 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
"use client";
import Link from "next/link";
import { cn } from "./cn";
import { useState } from "react";
import { Menu, X } from "lucide-react";
import { Button } from "./ui/button";
import { SiDiscord, SiGithub } from "@icons-pack/react-simple-icons";
import { ReactDocsConfig } from "./config";
interface DocPage {
slug: string;
title: string;
icon?: string;
isExternal?: boolean;
}
interface Props {
config: ReactDocsConfig;
navigation: {
group: string;
pages: DocPage[];
}[];
currentPath: string;
}
const iconMap: Record<string, React.ComponentType<{ className?: string }>> = {
github: SiGithub,
discord: SiDiscord,
};
export function DocsSidebar({ config, navigation, currentPath }: Props) {
const [isOpen, setIsOpen] = useState(false);
return (
<>
{/* Mobile Menu Button */}
<Button
variant="ghost"
size="icon"
className="md:hidden h-8 w-8 p-0"
onClick={() => setIsOpen(!isOpen)}
>
{isOpen ? <X className="h-4 w-4" /> : <Menu className="h-4 w-4" />}
</Button>
{/* Mobile Navigation Portal */}
{isOpen && (
<>
{/* Overlay */}
<div
className="fixed inset-0 bg-black/50 z-50"
onClick={() => setIsOpen(false)}
/>
{/* Sidebar */}
<div
className="
fixed inset-y-0 left-0 z-50
w-64
bg-gray-900
overflow-y-auto
p-4
"
>
<nav>
{navigation.map((section) => (
<div key={section.group} className="mb-8">
<h5 className="mb-2 text-sm font-semibold text-gray-400">
{section.group}
</h5>
<ul className="space-y-1.5">
{section.pages.map((page) => {
const IconComponent = page.icon
? iconMap[page.icon]
: null;
return (
<li key={page.slug}>
{page.isExternal ? (
<a
href={page.slug}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 text-sm text-gray-400 hover:text-white hover:bg-gray-800 rounded-md p-1.5 transition-all"
>
{IconComponent && (
<div className="p-1 border border-gray-700 rounded-md">
<IconComponent className="w-4 h-4" />
</div>
)}
{page.title}
</a>
) : (
<Link
href={config.basePath + `/${page.slug}`}
className={cn(
"block text-sm text-gray-400 hover:text-white hover:bg-gray-800 rounded-md p-1.5 transition-all",
currentPath === config.basePath + `/${page.slug}` &&
"text-white bg-gray-800"
)}
onClick={() => setIsOpen(false)}
>
{page.title}
</Link>
)}
</li>
);
})}
</ul>
</div>
))}
</nav>
</div>
</>
)}
{/* Desktop Navigation */}
<div className="hidden md:block">
<nav>
{navigation.map((section) => (
<div key={section.group} className="mb-8">
<h5 className="mb-2 text-sm font-semibold text-gray-400">
{section.group}
</h5>
<ul className="space-y-1.5">
{section.pages.map((page) => {
const IconComponent = page.icon ? iconMap[page.icon] : null;
return (
<li key={page.slug}>
{page.isExternal ? (
<a
href={page.slug}
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 text-sm text-gray-400 hover:text-white hover:bg-gray-800 rounded-md p-1.5 transition-all"
>
{IconComponent && (
<div className="p-1 border border-gray-700 rounded-md">
<IconComponent className="w-4 h-4" />
</div>
)}
{page.title}
</a>
) : (
<Link
href={`${config.basePath}/${page.slug}`}
className={cn(
"block text-sm text-gray-400 hover:text-white hover:bg-gray-800 rounded-md p-1.5 transition-all",
currentPath === `${config.basePath}/${page.slug}` &&
"text-white bg-gray-800"
)}
>
{page.title}
</Link>
)}
</li>
);
})}
</ul>
</div>
))}
</nav>
</div>
</>
);
}