Skip to content

Commit daa4069

Browse files
committed
Update sidebar.tsx
1 parent fbd9ad9 commit daa4069

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

apps/docs/components/geistdocs/sidebar.tsx

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
"use client";
22

3-
import {
4-
Collapsible,
5-
CollapsibleContent,
6-
CollapsibleTrigger,
7-
} from "@repo/shadcn-ui/components/ui/collapsible";
8-
import { cn } from "@repo/shadcn-ui/lib/utils";
93
import type {
104
Folder as FolderType,
115
Item as ItemType,
@@ -15,33 +9,63 @@ import { ChevronRightIcon, ExternalLinkIcon } from "lucide-react";
159
import Link from "next/link";
1610
import { usePathname } from "next/navigation";
1711
import type { ReactNode } from "react";
12+
import {
13+
Collapsible,
14+
CollapsibleContent,
15+
CollapsibleTrigger,
16+
} from "@/components/ui/collapsible";
17+
import { cn } from "@/lib/utils";
1818

1919
type FolderProps = {
2020
item: FolderType;
2121
level: number;
2222
children: ReactNode;
2323
};
2424

25-
export const Folder = ({ item, level, children }: FolderProps) => (
26-
<Collapsible defaultOpen={item.defaultOpen}>
27-
<CollapsibleTrigger
28-
className="group mt-4 mb-2 flex w-full items-center justify-between gap-4 first-child:mt-0"
29-
data-level={level}
30-
>
31-
{item.index ? (
32-
<Link className="text-pretty font-medium text-sm" href={item.index.url}>
33-
{item.name}
34-
</Link>
35-
) : (
36-
<span className="text-pretty font-medium text-sm">{item.name}</span>
25+
export const Folder = ({ item, level, children }: FolderProps) => {
26+
const pathname = usePathname();
27+
const isActive = pathname === item.index?.url;
28+
29+
const linkInner = item.index ? (
30+
<Link
31+
className={cn(
32+
"text-pretty font-medium text-sm",
33+
isActive && "text-primary"
3734
)}
38-
<ChevronRightIcon className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-90" />
39-
</CollapsibleTrigger>
40-
<CollapsibleContent>
41-
<ul>{children}</ul>
42-
</CollapsibleContent>
43-
</Collapsible>
44-
);
35+
href={item.index.url}
36+
>
37+
{item.name}
38+
</Link>
39+
) : (
40+
<span className="text-pretty font-medium text-sm">{item.name}</span>
41+
);
42+
43+
if (!item.children.length) {
44+
return (
45+
<div
46+
className="mt-4 mb-2 flex w-full items-center justify-between gap-4 first-child:mt-0"
47+
data-level={level}
48+
>
49+
{linkInner}
50+
</div>
51+
);
52+
}
53+
54+
return (
55+
<Collapsible defaultOpen={item.defaultOpen}>
56+
<CollapsibleTrigger
57+
className="group mt-4 mb-2 flex w-full items-center justify-between gap-4 first-child:mt-0"
58+
data-level={level}
59+
>
60+
{linkInner}
61+
<ChevronRightIcon className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-90" />
62+
</CollapsibleTrigger>
63+
<CollapsibleContent>
64+
<ul>{children}</ul>
65+
</CollapsibleContent>
66+
</Collapsible>
67+
);
68+
};
4569

4670
type ItemProps = {
4771
item: ItemType;

0 commit comments

Comments
 (0)