mirror of
https://github.com/yyhuni/xingrin.git
synced 2026-02-08 23:43:11 +08:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
"use client"
|
|
|
|
import { type Icon } from "@tabler/icons-react"
|
|
import Link from "next/link"
|
|
import { usePathname } from "next/navigation"
|
|
|
|
import {
|
|
SidebarGroup,
|
|
SidebarGroupLabel,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from "@/components/ui/sidebar"
|
|
|
|
export function NavSystem({
|
|
items,
|
|
}: {
|
|
items: {
|
|
name: string
|
|
url: string
|
|
icon: Icon
|
|
}[]
|
|
}) {
|
|
const pathname = usePathname()
|
|
const normalize = (p: string) => (p !== "/" && p.endsWith("/") ? p.slice(0, -1) : p)
|
|
const current = normalize(pathname)
|
|
|
|
return (
|
|
<SidebarGroup className="group-data-[collapsible=icon]:hidden">
|
|
<SidebarGroupLabel>系统设置</SidebarGroupLabel>
|
|
<SidebarMenu>
|
|
{items.map((item) => {
|
|
const navUrl = normalize(item.url)
|
|
const isActive = current === navUrl || current.startsWith(navUrl + "/")
|
|
|
|
return (
|
|
<SidebarMenuItem key={item.name}>
|
|
<SidebarMenuButton asChild isActive={isActive}>
|
|
<Link href={item.url}>
|
|
<item.icon />
|
|
<span>{item.name}</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
)
|
|
})}
|
|
</SidebarMenu>
|
|
</SidebarGroup>
|
|
)
|
|
}
|