mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-02-08 18:39:31 +08:00
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
"use client"
|
|
|
|
import Link from "next/link"
|
|
import { usePathname } from "next/navigation"
|
|
import { SidebarNavItem } from "types/nav"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
export interface DocsSidebarNavProps {
|
|
items: SidebarNavItem[]
|
|
}
|
|
|
|
export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
|
|
const pathname = usePathname()
|
|
|
|
return items.length ? (
|
|
<div className="w-full">
|
|
{items.map((item, index) => (
|
|
<div key={index} className={cn("pb-8")}>
|
|
<h4 className="mb-1 rounded-md px-2 py-1 text-sm font-semibold">
|
|
{item.title}
|
|
</h4>
|
|
{item?.items?.length && (
|
|
<DocsSidebarNavItems items={item.items} pathname={pathname} />
|
|
)}
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : null
|
|
}
|
|
|
|
interface DocsSidebarNavItemsProps {
|
|
items: SidebarNavItem[]
|
|
pathname: string | null
|
|
}
|
|
|
|
export function DocsSidebarNavItems({
|
|
items,
|
|
pathname,
|
|
}: DocsSidebarNavItemsProps) {
|
|
return items?.length ? (
|
|
<div className="grid grid-flow-row auto-rows-max text-sm">
|
|
{items.map((item, index) =>
|
|
item.href ? (
|
|
<Link
|
|
key={index}
|
|
href={item.href}
|
|
className={cn(
|
|
"flex w-full items-center rounded-md p-2 hover:underline",
|
|
item.disabled && "cursor-not-allowed opacity-60",
|
|
{
|
|
"bg-slate-100 dark:bg-slate-800": pathname === item.href,
|
|
}
|
|
)}
|
|
target={item.external ? "_blank" : ""}
|
|
rel={item.external ? "noreferrer" : ""}
|
|
>
|
|
{item.title}
|
|
</Link>
|
|
) : (
|
|
<span
|
|
key={index}
|
|
className="flex w-full cursor-not-allowed items-center rounded-md p-2 opacity-60 hover:underline"
|
|
>
|
|
{item.title}
|
|
</span>
|
|
)
|
|
)}
|
|
</div>
|
|
) : null
|
|
}
|