File size: 1,518 Bytes
f730525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use client";

import { usePathname } from 'next/navigation';
import Link from 'next/link';

export interface NavLinkProps {
    href: string;
    children: React.ReactNode;
    onClick?: () => void; // Include onClick as an optional prop
    target?: string;
}

const HeaderNavLink: React.FC<NavLinkProps> = ({ href, children, onClick }) => {
    // Use the useRouter hook to get information about the current route
    const pathname = usePathname();

    // Determine if the current tab is active
    const isActive = pathname === href;

    const handleClick = () => {
        if (onClick) {
            onClick(); // Call the onClick handler if provided
        }
    };

    return (
        <Link href={href} passHref>
            {/* Add a class to highlight the active tab */}
            <div className={`flex items-center font-bold ${isActive ? 'text-blue-500' : ''}`} onClick={handleClick}>
                {children}
            </div>
        </Link>
    );
};

const FooterNavLink: React.FC<NavLinkProps> = ({ href, children, onClick, target }) => {
    const handleClick = () => {
        if (onClick) {
            onClick(); // Call the onClick handler if provided
        }
    };

    return (
        <Link href={href} passHref target={target}>
            {/* Add a class to highlight the active tab */}
            <div className="flex items-center font-bold" onClick={handleClick}>
                {children}
            </div>
        </Link>
    );
}

export { HeaderNavLink, FooterNavLink }