diff --git a/app/docs/[[...slug]]/page.tsx b/app/docs/[[...slug]]/page.tsx index 23a5a4e..e765173 100644 --- a/app/docs/[[...slug]]/page.tsx +++ b/app/docs/[[...slug]]/page.tsx @@ -77,7 +77,7 @@ export default async function DocsPage({ params: { slug = [] } }: PageProps) { return (
-
+
diff --git a/app/docs/layout.tsx b/app/docs/layout.tsx index daf1296..d949ff0 100644 --- a/app/docs/layout.tsx +++ b/app/docs/layout.tsx @@ -8,7 +8,7 @@ export default function DocsLayout({ return (
-
+
{children}
diff --git a/components/anchor.tsx b/components/anchor.tsx index 3976334..d9782cf 100644 --- a/components/anchor.tsx +++ b/components/anchor.tsx @@ -1,37 +1,78 @@ "use client"; import { cn } from "@/lib/utils"; -import Link from "next/link"; +import Link, { LinkProps } from "next/link"; import { usePathname } from "next/navigation"; -import { ComponentProps, forwardRef } from "react"; +import { forwardRef } from "react"; -type AnchorProps = ComponentProps & { +type AnchorProps = LinkProps & { absolute?: boolean; activeClassName?: string; disabled?: boolean; -}; + className?: string; + children: React.ReactNode; +} & Omit, keyof LinkProps>; const Anchor = forwardRef( - ({ absolute, className = "", activeClassName = "", disabled, children, ...props }, ref) => { + ({ + absolute = false, + className = "", + activeClassName = "", + disabled = false, + children, + href, + ...props + }, ref) => { const path = usePathname(); - const href = props.href.toString(); + const hrefStr = href?.toString() || ''; - // Deteksi URL eksternal menggunakan regex - const isExternal = /^(https?:\/\/|\/\/)/.test(href); + // Check if URL is external + const isExternal = /^(https?:\/\/|\/\/)/.test(hrefStr); - let isMatch = absolute - ? href.split("/")[1] === path.split("/")[1] - : path === href; + // Check if current path matches the link + const isActive = absolute + ? hrefStr.split("/")[1] === path?.split("/")[1] + : path === hrefStr; - if (isExternal) isMatch = false; // Hindari mencocokkan URL eksternal + // Apply active class only for internal links + const linkClassName = cn( + 'transition-colors hover:text-primary', + className, + !isExternal && isActive && activeClassName + ); - if (disabled) + if (disabled) { return ( -
{children}
+ + {children} + ); + } + + + if (isExternal) { + return ( + + {children} + + ); + } + return ( - + {children} ); diff --git a/components/mob-toc.tsx b/components/mob-toc.tsx index 052affd..5334b54 100644 --- a/components/mob-toc.tsx +++ b/components/mob-toc.tsx @@ -87,7 +87,7 @@ export default function MobToc({ tocs }: MobTocProps) { transition={{ duration: 0.2, ease: 'easeInOut' }} >
-
+