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
+2
View File
@@ -22,5 +22,7 @@ COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/node_modules ./node_modules
VOLUME ["/app/contactMessages.json"]
EXPOSE 5000 EXPOSE 5000
CMD ["npm", "start"] CMD ["npm", "start"]
@@ -72,7 +72,7 @@ export default async function ProductPage({
title={productCategory?.title || t('page_products_default_title')} title={productCategory?.title || t('page_products_default_title')}
imageSrc={images.homeProductBack.src} 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} /> <Breadcrumb items={breadcrumbItems} />
<ProductCategoryCardInProducts <ProductCategoryCardInProducts
productCategory={productCategory} productCategory={productCategory}
+1 -1
View File
@@ -33,7 +33,7 @@ export default async function ProductsPage({
title={t('pages_product_categories_title')} title={t('pages_product_categories_title')}
imageSrc={images.aboutBanner.src} 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"> <div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
{productCategories.map((category) => ( {productCategories.map((category) => (
<ProductsCategoryCard key={category.id} {...category} /> <ProductsCategoryCard key={category.id} {...category} />
+1 -1
View File
@@ -32,7 +32,7 @@ export default async function ProjectsPage({
title={t('pages_projects_title')} title={t('pages_projects_title')}
imageSrc={images.aboutBanner.src} imageSrc={images.aboutBanner.src}
/> />
<div className="container-fluid mx-auto my-24"> <div className="container-fluid mx-auto my-12 md:my-24">
<ProjectsGridView /> <ProjectsGridView />
</div> </div>
</main> </main>
+16 -7
View File
@@ -28,11 +28,23 @@ export default function HamburgerMenu({ isOpen, onClose }: Props) {
routes.home, routes.home,
routes.about, routes.about,
routes.contact, routes.contact,
routes.products, routes.productCategories,
routes.projects, routes.projects,
routes.blog, 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(() => { useEffect(() => {
function handleClickOutside(event: MouseEvent) { function handleClickOutside(event: MouseEvent) {
if (menuRef.current && !menuRef.current.contains(event.target as Node)) { 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"> <nav className="flex flex-col gap-6">
{links.map(({ route: link, title }) => { {links.map(({ route: link, title }) => {
const isActive = pathname === link();
return ( return (
<Link <Link
key={link()} key={link()}
href={link()} href={link()}
onClick={onClose} onClick={onClose}
className={`rounded-lg px-4 py-3 text-center text-sm font-medium ${ className={`rounded-lg px-4 py-3 text-center text-sm font-medium ${linkClass(
isActive link(),
? 'bg-primary text-white' )}`}
: 'border border-white/10 text-white hover:bg-white/10'
}`}
> >
{title} {title}
</Link> </Link>
+9 -2
View File
@@ -28,8 +28,15 @@ export default function Navbar() {
routes.contact, routes.contact,
]; ];
const linkClass = (href: string) => const linkClass = (href: string) => {
pathname === href ? 'text-primary font-semibold' : 'text-white'; 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 ( return (
<> <>