2022-05-12 14:07:26 +00:00
|
|
|
import {FC, PropsWithChildren} from "react";
|
2022-04-21 11:02:39 +00:00
|
|
|
import {INavigationItemProps} from "../types/data.types";
|
2022-05-12 14:07:26 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
|
|
|
|
const sidebar: INavigationItemProps = require("../public/compiled/sidebar.tree.min.json");
|
2022-04-21 11:02:39 +00:00
|
|
|
|
2022-05-12 14:07:26 +00:00
|
|
|
interface ISidebarProps{
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IMenuProps{
|
|
|
|
items: INavigationItemProps[]
|
|
|
|
level?: number
|
|
|
|
}
|
2022-04-11 17:15:04 +00:00
|
|
|
|
2022-05-12 14:07:26 +00:00
|
|
|
interface IMenuItemProps{
|
|
|
|
item: INavigationItemProps
|
|
|
|
level?: number
|
2022-05-11 15:43:23 +00:00
|
|
|
}
|
2022-04-11 17:15:04 +00:00
|
|
|
|
2022-05-12 14:07:26 +00:00
|
|
|
const MenuItem: FC<PropsWithChildren<IMenuItemProps>>= ({level, item, children}) => (
|
|
|
|
<li className={`menuitem level-${level}`}>
|
|
|
|
<div className={"menuitem-title"}>
|
|
|
|
<Link href={`/${item.path.join("/")}`}>
|
|
|
|
<a>
|
|
|
|
{
|
|
|
|
level===0?
|
|
|
|
<b>{item.title}</b>
|
|
|
|
:
|
|
|
|
<span>{item.title}</span>
|
|
|
|
}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
children
|
|
|
|
}
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
|
|
|
|
const Menu: FC<IMenuProps> = (props) => {
|
|
|
|
const {items, level = 0} = props;
|
|
|
|
return(
|
|
|
|
<ul className={"sidebar-menu"}>
|
|
|
|
{items.map((item) => {
|
|
|
|
return (
|
|
|
|
<MenuItem item={item}
|
|
|
|
level={level}
|
|
|
|
key={item.localPath}
|
|
|
|
>
|
|
|
|
<Menu items={item.children} level={level+1}/>
|
|
|
|
</MenuItem>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Sidebar: FC<ISidebarProps> = (props) => {
|
|
|
|
const mainItems = sidebar.children.filter((c) => c.children.length===0)
|
|
|
|
const subItems = sidebar.children.filter((c) => c.children.length!==0);
|
|
|
|
|
2022-04-11 17:15:04 +00:00
|
|
|
return (
|
2022-05-11 15:43:23 +00:00
|
|
|
<nav className={`default-sidebar`}>
|
2022-05-12 14:07:26 +00:00
|
|
|
<Menu items={[{...sidebar, title: "", children: mainItems}]}/>
|
|
|
|
<br/>
|
|
|
|
<Menu items={subItems}/>
|
2022-04-21 11:02:39 +00:00
|
|
|
</nav>
|
2022-04-11 17:15:04 +00:00
|
|
|
)
|
|
|
|
}
|