refactor: enhance link active state handling in Navbar and HamburgerMenu components

This commit is contained in:
2025-06-16 14:02:21 +03:30
parent 7c56fdc8cd
commit 96e0fc9e0d
6 changed files with 30 additions and 12 deletions
@@ -72,7 +72,7 @@ export default async function ProductPage({
title={productCategory?.title || t('page_products_default_title')}
imageSrc={images.homeProductBack.src}
/>
<div className="container-fluid mx-auto my-24">
<div className="container-fluid mx-auto my-12 md:my-24">
<Breadcrumb items={breadcrumbItems} />
<ProductCategoryCardInProducts
productCategory={productCategory}
+1 -1
View File
@@ -33,7 +33,7 @@ export default async function ProductsPage({
title={t('pages_product_categories_title')}
imageSrc={images.aboutBanner.src}
/>
<div className="container-fluid mx-auto my-24">
<div className="container-fluid mx-auto my-12 md:my-24">
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
{productCategories.map((category) => (
<ProductsCategoryCard key={category.id} {...category} />
+1 -1
View File
@@ -32,7 +32,7 @@ export default async function ProjectsPage({
title={t('pages_projects_title')}
imageSrc={images.aboutBanner.src}
/>
<div className="container-fluid mx-auto my-24">
<div className="container-fluid mx-auto my-12 md:my-24">
<ProjectsGridView />
</div>
</main>
+16 -7
View File
@@ -28,11 +28,23 @@ export default function HamburgerMenu({ isOpen, onClose }: Props) {
routes.home,
routes.about,
routes.contact,
routes.products,
routes.productCategories,
routes.projects,
routes.blog,
];
const linkClass = (href: string) => {
let isActive = false;
if (href === '/' || href === `/${locale}`) {
isActive = pathname === '/' || pathname === `/${locale}`;
} else {
isActive = pathname.startsWith(href);
}
return isActive
? 'bg-primary text-white'
: 'border border-white/10 text-white hover:bg-white/10';
};
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
@@ -76,17 +88,14 @@ export default function HamburgerMenu({ isOpen, onClose }: Props) {
<nav className="flex flex-col gap-6">
{links.map(({ route: link, title }) => {
const isActive = pathname === link();
return (
<Link
key={link()}
href={link()}
onClick={onClose}
className={`rounded-lg px-4 py-3 text-center text-sm font-medium ${
isActive
? 'bg-primary text-white'
: 'border border-white/10 text-white hover:bg-white/10'
}`}
className={`rounded-lg px-4 py-3 text-center text-sm font-medium ${linkClass(
link(),
)}`}
>
{title}
</Link>
+9 -2
View File
@@ -28,8 +28,15 @@ export default function Navbar() {
routes.contact,
];
const linkClass = (href: string) =>
pathname === href ? 'text-primary font-semibold' : 'text-white';
const linkClass = (href: string) => {
let isActive = false;
if (href === '/' || href === `/${locale}`) {
isActive = pathname === '/' || pathname === `/${locale}`;
} else {
isActive = pathname.startsWith(href);
}
return isActive ? 'text-primary font-semibold' : 'text-white';
};
return (
<>