mirror of
https://github.com/cosscom/coss.git
synced 2026-09-14 20:06:50 +08:00
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
"use client"
|
|
|
|
import Link from "next/link"
|
|
import { usePathname } from "next/navigation"
|
|
|
|
import { PAGES_NEW } from "@/lib/docs"
|
|
import type { source } from "@/lib/source"
|
|
import { Badge } from "@/registry/default/ui/badge"
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarGroup,
|
|
SidebarGroupContent,
|
|
SidebarGroupLabel,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from "@/registry/default/ui/sidebar"
|
|
|
|
export function DocsSidebar({
|
|
tree,
|
|
...props
|
|
}: React.ComponentProps<typeof Sidebar> & { tree: typeof source.pageTree }) {
|
|
const pathname = usePathname()
|
|
|
|
return (
|
|
<Sidebar
|
|
className="sticky top-(--header-height) z-30 hidden h-[calc(100svh-var(--header-height))] bg-transparent lg:flex"
|
|
collapsible="none"
|
|
{...props}
|
|
>
|
|
<SidebarContent className="no-scrollbar px-4 py-2">
|
|
<div className="h-(--top-spacing) shrink-0" />
|
|
{tree.children.map((item) => (
|
|
<SidebarGroup key={item.$id} className="gap-1">
|
|
<SidebarGroupLabel className="h-7 px-0 text-sidebar-accent-foreground">
|
|
{item.name}
|
|
</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
{item.type === "folder" && (
|
|
<SidebarMenu className="gap-0.5">
|
|
{item.children.map((item) => {
|
|
return (
|
|
item.type === "page" && (
|
|
<SidebarMenuItem key={item.url}>
|
|
<SidebarMenuButton
|
|
render={<Link href={item.url} />}
|
|
isActive={item.url === pathname}
|
|
className="from-secondary to-secondary/64 ps-3.5 text-sidebar-foreground/64 hover:bg-transparent active:bg-transparent data-[active=true]:bg-gradient-to-tr"
|
|
>
|
|
{item.name}
|
|
{PAGES_NEW.includes(item.url) && (
|
|
<Badge variant="info">New</Badge>
|
|
)}
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
)
|
|
)
|
|
})}
|
|
</SidebarMenu>
|
|
)}
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
))}
|
|
</SidebarContent>
|
|
</Sidebar>
|
|
)
|
|
}
|