Repository navigation
Expand file tree
/
Copy pathSidebar.tsx
More file actions
89 lines (81 loc) · 2.42 KB
/
Copy pathSidebar.tsx
File metadata and controls
89 lines (81 loc) · 2.42 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
import { useRouter } from "next/router";
import React from "react";
import tw from "twin.macro";
import { sidebarContent } from "../data/sidebar";
import { Link } from "./Link";
import { Logo } from "./Logo";
import { ScrollArea } from "./ScrollArea";
import { Search } from "./Search";
import { ThemeSwitcher } from "./ThemeSwitcher";
export const Sidebar: React.FC = ({ ...props }) => {
return (
<div
css={[
tw`hidden`,
tw`md:h-screen md:sticky md:top-0 md:overflow-hidden md:block md:min-w-sidebar`,
tw`md:border-r md:border-gray-200`,
]}
className="sidebar"
{...props}
>
<ScrollArea>
<div tw="pt-6 pb-6 px-4 sticky top-0 bg-background">
<div tw="flex items-center justify-between">
<Link tw="w-full flex items-center" href="/">
<div tw="flex items-center">
<Logo tw="w-8 h-8 mr-4" /> <span tw="font-bold">Railway</span>
</div>
</Link>
<ThemeSwitcher />
</div>
</div>
<div tw="mx-4 mb-6">
<Search />
</div>
<SidebarContent />
</ScrollArea>
</div>
);
};
export const MobileSidebar: React.FC<{ isOpen: boolean }> = ({ isOpen }) => {
return (
<div css={[isOpen ? tw`block` : tw`hidden`, tw`w-full`, tw`md:hidden`]}>
<SidebarContent />
</div>
);
};
const SidebarContent: React.FC = () => {
const { pathname } = useRouter();
return (
<>
{sidebarContent.map((section, i) => (
<React.Fragment key={i}>
{section.title != null && (
<h5 tw="px-4 my-2 text-foreground text-sm font-bold">
{section.title}
</h5>
)}
<ul tw="mb-8">
{section.pages.map(page => (
<li key={page.slug}>
<Link
href={page.slug}
css={[
tw`text-gray-700 text-sm`,
tw`block px-4 py-2`,
tw`hover:bg-gray-100 hover:text-foreground`,
tw`focus:outline-none focus:bg-pink-100`,
pathname === page.slug &&
tw`bg-pink-100 text-pink-900 hover:bg-pink-100 border-r-2 border-pink-500`,
]}
>
{page.title}
</Link>
</li>
))}
</ul>
</React.Fragment>
))}
</>
);
};