|
1
|
"use client" |
|
2
|
|
|
3
|
import React from "react" |
|
4
|
import { Sidebar } from "types" |
|
5
|
import { SidebarItemLink } from "./Link" |
|
6
|
import { SidebarItemSubCategory } from "./SubCategory" |
|
7
|
import { DottedSeparator } from "@/components/DottedSeparator" |
|
8
|
import { SidebarItemCategory } from "./Category" |
|
9
|
import { SidebarItemSidebar } from "./Sidebar" |
|
10
|
|
|
11
|
export type SidebarItemProps = { |
|
12
|
item: Sidebar.SidebarItem |
|
13
|
nested?: boolean |
|
14
|
hasNextItems?: boolean |
|
15
|
isParentCategoryOpen?: boolean |
|
16
|
} & React.AllHTMLAttributes<HTMLElement> |
|
17
|
|
|
18
|
export const SidebarItem = ({ |
|
19
|
item, |
|
20
|
hasNextItems = false, |
|
21
|
...props |
|
22
|
}: SidebarItemProps) => { |
|
23
|
switch (item.type) { |
|
24
|
case "category": |
|
25
|
return ( |
|
26
|
<> |
|
27
|
<SidebarItemCategory item={item} {...props} /> |
|
28
|
{hasNextItems && <DottedSeparator />} |
|
29
|
</> |
|
30
|
) |
|
31
|
case "sub-category": |
|
32
|
return <SidebarItemSubCategory item={item} {...props} /> |
|
33
|
case "link": |
|
34
|
case "ref": |
|
35
|
case "external": |
|
36
|
return <SidebarItemLink item={item} {...props} /> |
|
37
|
case "sidebar": |
|
38
|
return <SidebarItemSidebar item={item} {...props} /> |
|
39
|
case "separator": |
|
40
|
return <DottedSeparator /> |
|
41
|
} |
|
42
|
} |