refactor: Extract Sidebar Link to component
This commit is contained in:
29
components/TempDesignSystem/Link/index.tsx
Normal file
29
components/TempDesignSystem/Link/index.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"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} />
|
||||
}
|
||||
Reference in New Issue
Block a user