Files
web/components/TempDesignSystem/Link/index.tsx
2024-05-24 10:48:45 +02:00

38 lines
709 B
TypeScript

"use client"
import NextLink from "next/link"
import { usePathname } from "next/navigation"
import { linkVariants } from "./variants"
import type { LinkProps } from "./link"
export default function Link({
className,
href,
partialMatch = false,
size,
prefetch,
variant,
...props
}: LinkProps) {
const currentPageSlug = usePathname()
let isActive = currentPageSlug === href
if (partialMatch && !isActive) {
isActive = currentPageSlug.startsWith(href)
}
const classNames = linkVariants({
active: isActive,
className,
size,
variant,
})
return (
<NextLink
prefetch={prefetch}
className={classNames}
href={href}
{...props}
/>
)
}