fosrl.pangolin/src/components/sidebar-nav.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-10-13 16:18:54 -04:00
"use client"
2024-10-13 18:33:41 -04:00
import React from 'react'
2024-10-13 16:18:54 -04:00
import Link from "next/link"
import { usePathname } from "next/navigation"
import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
items: {
href: string
title: string
}[]
2024-10-13 18:33:41 -04:00
disabled?: boolean
2024-10-13 16:18:54 -04:00
}
2024-10-13 18:33:41 -04:00
export function SidebarNav({ className, items, disabled = false, ...props }: SidebarNavProps) {
2024-10-13 16:18:54 -04:00
const pathname = usePathname()
return (
<nav
className={cn(
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
2024-10-13 18:33:41 -04:00
disabled && "opacity-50 pointer-events-none",
2024-10-13 16:18:54 -04:00
className
)}
{...props}
>
{items.map((item) => (
<Link
key={item.href}
href={item.href}
className={cn(
buttonVariants({ variant: "ghost" }),
pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
2024-10-13 18:33:41 -04:00
"justify-start",
disabled && "cursor-not-allowed"
2024-10-13 16:18:54 -04:00
)}
2024-10-13 18:33:41 -04:00
onClick={disabled ? (e) => e.preventDefault() : undefined}
tabIndex={disabled ? -1 : undefined}
aria-disabled={disabled}
2024-10-13 16:18:54 -04:00
>
{item.title}
</Link>
))}
</nav>
)
2024-10-13 18:33:41 -04:00
}