Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added dot on header section links #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 30 additions & 4 deletions components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,50 @@ export default function Header(props: { fixed?: boolean }) {
onHover?: (hoverstate: boolean, leftOffset: number) => void;
}) => {
const { item, onHover } = props;

const className = `font-black md:font-semibold ${
scrolled ? "md:hover:text-black/100" : "md:hover:text-white/100"
} transition-all px-3 flex items-center md:justify-center h-full`;

const activeClassName = `relative ${
scrolled ? "text-white-600" : "text-white-400"
} ${
item.type === "section" && item.id === "contact"
? "after:content-[''] after:absolute after:left-1/2 after:bottom-[2px] after:transform after:-translate-x-1/2 after:w-[5px] after:h-[5px] after:bg-white after:opacity-80 after:rounded-full md:after:w-[6px] md:after:h-[6px] md:after:bottom-[19px]"
: "after:content-[''] after:absolute after:left-1/2 after:bottom-[2px] after:transform after:-translate-x-1/2 after:w-[5px] after:h-[5px] after:bg-white after:opacity-80 after:rounded-full md:after:w-[6px] md:after:h-[6px] md:after:bottom-[27px]"
}`;



const isActive = (href?: string, id?: string) => {
if (item.type === "link" && path === href) return true;
if (item.type === "section") {
if (typeof window !== "undefined") {
const hash = window.location.hash;
return path === `${item.page}` && hash === `#${id}`;
}
}
return false;
};
const itemRef = useRef<HTMLButtonElement>(null);

switch (item.type) {
case "link":
return (
<Link href={item.href} className={className}>
<Link
href={item.href}
className={`${className} ${isActive(item.href) ? activeClassName : ""}`}
>
{item.content}
</Link>
);
case "section":
return (
<Link
href={item.page + "#" + item.id}
className={className}
className={`${className} ${
isActive(item.page, item.id) ? activeClassName : ""
}`}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -205,6 +230,7 @@ export default function Header(props: { fixed?: boolean }) {
);
}
};


const DropDownRender = (props: {
items: DropDownItem[];
Expand Down