From bd400695ff8566dd565dbfa89ef0b7e58877443a Mon Sep 17 00:00:00 2001
From: Wildan Nursahidan <>
Date: Mon, 26 May 2025 11:06:58 +0700
Subject: [PATCH] feat(ui): update search component and improve responsive
design
- Show only search icon on mobile (< 768px) in navbar
- Refactor Anchor component with better type safety and link handling
- Adjust spacing in Table of Contents and main content
- Improve responsive layout and consistency
---
app/docs/[[...slug]]/page.tsx | 2 +-
app/docs/layout.tsx | 2 +-
components/anchor.tsx | 71 +++++++++++++++++++++++++++--------
components/mob-toc.tsx | 2 +-
components/search.tsx | 25 +++++++-----
components/toc.tsx | 2 +-
6 files changed, 76 insertions(+), 28 deletions(-)
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 (
-
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' }}
>
-
+