This commit is contained in:
Mackie 2026-06-08 14:05:00 +08:00
parent e850391afe
commit 129a5da516
2 changed files with 26 additions and 0 deletions

View file

@ -7,12 +7,30 @@ import { CMSLink } from '@/components/Link'
export const HeaderNav: React.FC<{ data: HeaderType }> = ({ data }) => {
const navItems = data?.navItems || []
// Optional: Function to handle smooth scroll override if needed
const handleNavClick = (e: React.MouseEvent<HTMLAnchorElement>, href: string) => {
if (href.startsWith('#')) {
const element = document.querySelector(href)
if (element) {
e.preventDefault()
element.scrollIntoView({ behavior: 'smooth' })
// Update URL hash without jumping
history.pushState(null, '', href)
}
}
}
return (
<nav className="flex flex-col md:flex-row gap-1 md:items-center">
{navItems.map(({ link }, i) => (
<CMSLink
key={i}
{...link}
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
if (link.url?.startsWith('#')) {
handleNavClick(e, link.url)
}
}}
appearance="link"
className="px-4 py-2 rounded-xl text-sm text-foreground/60 hover:text-foreground hover:bg-foreground/10 transition-all"
/>

View file

@ -241,4 +241,12 @@ html[data-theme='light'] {
/* Add this to your global CSS file */
.column-with-connector:last-of-type::after {
content: none;
}
html {
scroll-behavior: smooth;
}
[id] {
scroll-margin-top: 5rem; /* Adjust this to match your header height */
}