-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from JohnsonMao/refactor/header-component
♻️ refactor header component computed scroll 💄 update scroll padding top ♻️ split Menu into separate component in Header ✅ update unit test
- Loading branch information
Showing
10 changed files
with
250 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
@import "./prism-vsc-dark-plus.css"; | ||
|
||
:root { | ||
scroll-padding-top: 72px; | ||
scroll-padding-top: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client'; | ||
|
||
import { usePathname } from 'next/navigation'; | ||
|
||
import cn from '@/utils/cn'; | ||
import getLocale from '@/utils/getLocale'; | ||
|
||
import Link from '../Link'; | ||
|
||
type MenuItem = { | ||
text: string; | ||
href: LinkWithoutLocalePathProps['href']; | ||
}; | ||
|
||
export type MenuProps = { | ||
menu: MenuItem[]; | ||
}; | ||
|
||
function Menu({ menu }: MenuProps) { | ||
const pathname = usePathname(); | ||
|
||
const isActiveLink = (href: LinkWithoutLocalePathProps['href']) => { | ||
const locale = getLocale(pathname) || ''; | ||
const localePrefix = new RegExp(`^/${locale}/?`); | ||
const adjustedPathname = pathname.replace(localePrefix, '/'); | ||
|
||
if (adjustedPathname === '/') return href === '/'; | ||
|
||
return adjustedPathname.startsWith(href) && href !== '/'; | ||
}; | ||
|
||
return ( | ||
<nav> | ||
<ul className="flex rounded-full bg-gray-900/60 px-2 backdrop-blur-md"> | ||
{menu.map(({ text, href }) => ( | ||
<li key={text}> | ||
<Link | ||
href={href} | ||
className={cn( | ||
'block p-3 text-xl leading-none text-white/90 no-underline hover:text-white', | ||
isActiveLink(href) && 'text-blue-500 hover:text-blue-500' | ||
)} | ||
> | ||
{text} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
); | ||
} | ||
|
||
export default Menu; |
Oops, something went wrong.