From 5b7ccf0b671e2999b62befc729a3e517a0433728 Mon Sep 17 00:00:00 2001 From: Bertrand Yuan Date: Mon, 15 Dec 2025 23:48:10 +0800 Subject: initial commit -- the front-end prototype The initial code is base on Anirudh's work. More to see at: https://github.com/techwithanirudh/shadcn-blog Therefore, the code in this commit is under MIT license. --- src/components/active-link.tsx | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/components/active-link.tsx (limited to 'src/components/active-link.tsx') diff --git a/src/components/active-link.tsx b/src/components/active-link.tsx new file mode 100644 index 0000000..bab9670 --- /dev/null +++ b/src/components/active-link.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { isActive } from '@/lib/is-active'; +import { cn } from '@/lib/utils'; +import Link, { type LinkProps } from 'next/link'; +import { usePathname } from 'next/navigation'; +import type { ReactNode } from 'react'; + +type ActiveLinkProps = LinkProps & { + children: ReactNode; + href: string; + target?: string; + rel?: string; + className?: string; + nested?: boolean; +}; + +export const ActiveLink = ({ + href, + children, + className, + nested = false, + ...props +}: ActiveLinkProps) => { + const pathname = usePathname(); + const active = isActive(href, pathname, nested); + + return ( + + {children} + + ); +}; -- cgit v1.2.3