forked from rocicorp/zero-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsublink.tsx
More file actions
87 lines (81 loc) · 2.32 KB
/
sublink.tsx
File metadata and controls
87 lines (81 loc) · 2.32 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
'use client';
import {EachRoute} from '@/lib/routes-config';
import Anchor from './anchor';
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible';
import {cn} from '@/lib/utils';
import {SheetClose} from '@/components/ui/sheet';
import {Button} from './ui/button';
import {ChevronDown, ChevronRight} from 'lucide-react';
import {useState} from 'react';
export default function SubLink({
title,
href,
items,
noLink,
level,
isSheet,
}: EachRoute & {level: number; isSheet: boolean}) {
const [isOpen, setIsOpen] = useState(level == 0);
const Comp = (
<Anchor activeClassName="text-primary font-semibold" href={href}>
{title}
</Anchor>
);
const titleOrLink = !noLink ? (
isSheet ? (
<SheetClose asChild>{Comp}</SheetClose>
) : (
Comp
)
) : (
<h4 className="font-semibold sm:text-sm text-primary">{title}</h4>
);
if (!items) {
return <div className="flex flex-col">{titleOrLink}</div>;
}
return (
<div className="flex flex-col gap-1 w-full">
<Collapsible open={isOpen} onOpenChange={setIsOpen}>
<div className="flex items-center gap-2">
{titleOrLink}
<CollapsibleTrigger asChild>
<Button
className="ml-auto mr-3.5 h-6 w-6"
variant="link"
size="icon"
>
{!isOpen ? (
<ChevronRight className="h-[0.9rem] w-[0.9rem]" />
) : (
<ChevronDown className="h-[0.9rem] w-[0.9rem]" />
)}
<span className="sr-only">Toggle</span>
</Button>
</CollapsibleTrigger>
</div>
<CollapsibleContent>
<div
className={cn(
'flex flex-col items-start sm:text-sm dark:text-neutral-300/85 text-neutral-800 ml-0.5 mt-2.5 gap-3',
level > 0 && 'pl-4 border-l ml-1',
)}
>
{items?.map(innerLink => {
const modifiedItems = {
...innerLink,
href: `${href + innerLink.href}`,
level: level + 1,
isSheet,
};
return <SubLink key={modifiedItems.href} {...modifiedItems} />;
})}
</div>
</CollapsibleContent>
</Collapsible>
</div>
);
}