SPB Git

Repository Public

HeaderNav.tsx 7.8 KB 201 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/components/HeaderNav.tsx9 * Module           : components10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-0912 * Last Modified    : 2026-10-2013 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * Navigation d'en-tête. Le menu mobile utilise le motif checkbox + peer-checked :44 * il s'ouvre et se ferme en PUR CSS — fonctionne même sans JavaScript (cache45 * périmé, hydratation cassée, JS bloqué). Le JS n'est qu'une amélioration46 * (fermeture au changement de page, verrou de défilement).47 */48"use client";49import { useEffect, useRef } from "react";50import Link from "next/link";51import { usePathname } from "next/navigation";52import { useLang } from "./LangContext";5354export default function HeaderNav() {55  const { lang, setLang } = useLang();56  const path = usePathname();57  const fr = lang === "fr";58  const box = useRef<HTMLInputElement>(null);5960  // améliorations JS (facultatives) : fermer à la navigation, verrouiller le scroll61  useEffect(() => {62    if (box.current) box.current.checked = false;63    document.body.style.overflow = "";64  }, [path]);65  const onToggle = () => {66    document.body.style.overflow = box.current?.checked ? "hidden" : "";67  };6869  const items = [70    { href: "/", label: fr ? "Estimer" : "Estimate" },71    { href: "/a-vendre", label: fr ? "À vendre" : "For sale" },72    { href: "/ventes", label: fr ? "Ventes" : "Sales" },73    { href: "/cout", label: fr ? "Coût" : "Cost" },74    { href: "/carte", label: fr ? "Carte" : "Map" },75    { href: "/parc", label: fr ? "Parc" : "Portfolio" },76    { href: "/stats", label: fr ? "Statistiques" : "Statistics" },77    { href: "/methodologie", label: fr ? "Méthodologie" : "Methodology" },78  ];79  const isActive = (href: string) =>80    href === "/" ? path === "/" : path.startsWith(href);8182  return (83    <>84      {/* nav texte — desktop : soulignement rouge = page courante */}85      <nav className="hidden items-center gap-5 lg:flex">86        {items.map((it) => (87          <Link88            key={it.href}89            href={it.href}90            className={`vp-mono inline-flex min-h-[38px] items-center whitespace-nowrap border-b-2 pt-[2px] text-[11px] font-medium uppercase tracking-[0.1em] transition-colors ${91              isActive(it.href)92                ? "border-accent text-ink"93                : "border-transparent text-ink-2 hover:text-ink"94            }`}95          >96            {it.label}97          </Link>98        ))}99      </nav>100101      {/* ---- menu mobile : checkbox cachée + peer-checked, zéro JS requis ---- */}102      <div className="lg:hidden">103        <input104          ref={box}105          type="checkbox"106          id="vp-menu"107          className="peer sr-only"108          onChange={onToggle}109          aria-label="Menu"110        />111        {/* hamburger (label = bouton) */}112        <label113          htmlFor="vp-menu"114          aria-hidden="true"115          className="flex h-11 w-11 cursor-pointer flex-col items-center justify-center gap-[5px]"116        >117          <span className="h-px w-[20px] bg-ink" />118          <span className="h-px w-[20px] bg-ink" />119          <span className="h-px w-[12px] self-center ml-[8px] bg-accent" />120        </label>121122        {/* panneau plein écran encre — sibling du checkbox, affiché via peer-checked */}123        <div124          className="vp-dark fixed inset-0 z-[var(--z-modal,900)] hidden flex-col overflow-y-auto peer-checked:flex"125          role="dialog"126          aria-modal="true"127          aria-label="Menu"128        >129          {/* barre du haut : marque + fermer */}130          <div className="flex h-14 shrink-0 items-center justify-between border-b border-[rgba(245,243,238,0.18)] px-4">131            <Link132              href="/"133              className="vp-display flex items-baseline gap-1.5 text-[19px] font-bold leading-none tracking-[-0.04em] text-[var(--paper-on-ink)]"134            >135              Vrai&nbsp;Prix136              <span137                aria-hidden="true"138                className="inline-block h-[7px] w-[7px] bg-[var(--accent-bright)]"139              />140            </Link>141            <label142              htmlFor="vp-menu"143              aria-label={fr ? "Fermer le menu" : "Close menu"}144              className="vp-mono flex h-11 w-11 cursor-pointer items-center justify-center text-[15px] text-[var(--paper-on-ink)]"145            >146              ✕147            </label>148          </div>149150          {/* liens géants */}151          <nav className="flex flex-1 flex-col justify-center px-6 py-8">152            {items.map((it, i) => (153              <Link154                key={it.href}155                href={it.href}156                className="group flex items-baseline gap-4 border-b border-[rgba(245,243,238,0.12)] py-[18px] last:border-0"157              >158                <span className="vp-mono text-[11px] font-medium text-[var(--accent-bright)]">159                  0{i + 1}160                </span>161                <span162                  className={`vp-display text-[28px] font-bold uppercase leading-none tracking-[-0.03em] ${163                    isActive(it.href)164                      ? "text-[var(--accent-bright)]"165                      : "text-[var(--paper-on-ink)] group-active:text-[var(--accent-bright)]"166                  }`}167                >168                  {it.label}169                </span>170                {isActive(it.href) && (171                  <span172                    aria-hidden="true"173                    className="mb-[2px] inline-block h-[6px] w-[6px] self-center bg-[var(--accent-bright)]"174                  />175                )}176              </Link>177            ))}178          </nav>179180          {/* pied du menu */}181          <div className="shrink-0 border-t border-[rgba(245,243,238,0.18)] px-6 pb-[max(20px,env(safe-area-inset-bottom))] pt-4">182            <button183              onClick={() => setLang(fr ? "en" : "fr")}184              className="vp-mono mb-4 border-b border-[var(--paper-on-ink)] pb-1 text-[12px] font-medium uppercase tracking-[0.1em] text-[var(--paper-on-ink)]"185            >186              {fr ? "English version" : "Version française"}187            </button>188            <div className="vp-mono flex flex-wrap gap-x-5 gap-y-1.5 text-[10.5px] uppercase tracking-[0.06em] text-[rgba(245,243,238,0.55)]">189              <Link href="/conditions">{fr ? "Conditions" : "Terms"}</Link>190              <Link href="/confidentialite">191                {fr ? "Confidentialité" : "Privacy"}192              </Link>193              <Link href="/contact">Contact</Link>194            </div>195          </div>196        </div>197      </div>198    </>199  );200}201
Files main
Menu

Theme