Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/components/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,41 @@

import React, { type ReactNode } from 'react';
import Link from '@docusaurus/Link';
import { useLocation } from '@docusaurus/router';
import useBaseUrl from '@docusaurus/useBaseUrl';
import styles from './styles.module.css';

function Navigation({ links }) {
interface NavLink {
label: string;
href: string;
}

interface NavigationProps {
links: NavLink[];
}

function Navigation({ links }: NavigationProps) {
const location = useLocation();

return (
<nav className="container">
<ul className={styles.nav}>
{links.map((link, i) => (
<li key={i} className={styles.links}>
<Link href={link.href}>{link.label}</Link>
</li>
))}
{links.map((link, i) => {
const baseHref = useBaseUrl(link.href);
const isActive = location.pathname === baseHref ||
location.pathname.startsWith(baseHref + '/');

return (
<li key={i} className={`${styles.links} ${isActive ? styles.active : ''}`}>
<Link
href={link.href}
aria-current={isActive ? 'page' : undefined}
>
{link.label}
</Link>
</li>
);
})}
</ul>
</nav>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/Navigation/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
gap: 2rem;
justify-content: center;
}

.active a {
font-weight: 700;
text-decoration: underline;
}