forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimary-docs-tabs.tsx
More file actions
68 lines (59 loc) · 1.63 KB
/
Copy pathprimary-docs-tabs.tsx
File metadata and controls
68 lines (59 loc) · 1.63 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
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { ChefHat } from "lucide-react";
import BookIcon from "./icons/book";
import ConsoleIcon from "./icons/console";
const PRIMARY_DOCS_LINKS = [
{
href: "/",
label: "Docs",
icon: <BookIcon className="h-4 w-4 text-current" />,
},
{
href: "/reference",
label: "Reference",
icon: <ConsoleIcon className="h-4 w-4 text-current" />,
},
{
href: "/cookbook",
label: "Cookbook",
icon: <ChefHat className="h-4 w-4 text-current" />,
},
];
function getActiveRoute(pathname: string) {
const firstSegment = pathname === "/" ? "/" : `/${pathname.split("/")[1]}`;
if (firstSegment === "/reference") {
return "/reference";
}
if (firstSegment === "/cookbook") {
return "/cookbook";
}
return "/";
}
export function PrimaryDocsTabs({ className }: { className?: string }) {
const pathname = usePathname();
const activeRoute = getActiveRoute(pathname);
return (
<nav className={className} aria-label="Primary docs sections">
{PRIMARY_DOCS_LINKS.map((link) => {
const isActive = activeRoute === link.href;
return (
<Link
key={link.href}
href={link.href}
className={`shell-docs-radius-control shell-docs-primary-tab ${
isActive
? "shell-docs-nav-link-active"
: "shell-docs-nav-link-idle"
}`}
aria-current={isActive ? "page" : undefined}
>
{link.icon}
<span>{link.label}</span>
</Link>
);
})}
</nav>
);
}