30 lines
587 B
TypeScript
30 lines
587 B
TypeScript
"use client"
|
|
|
|
import { linkVariants } from "./variants"
|
|
|
|
import NextLink from "next/link"
|
|
|
|
import type { LinkProps } from "./link"
|
|
import { usePathname } from "next/navigation"
|
|
|
|
export default function Link({
|
|
className,
|
|
href,
|
|
size,
|
|
variant,
|
|
...props
|
|
}: LinkProps) {
|
|
const currentPageSlug = `/${usePathname()
|
|
.split("/")
|
|
.filter((v) => v)
|
|
.at(-1)}`
|
|
const isActive = currentPageSlug === href
|
|
const classNames = linkVariants({
|
|
active: isActive,
|
|
className,
|
|
size,
|
|
variant,
|
|
})
|
|
return <NextLink className={classNames} href={href} {...props} />
|
|
}
|