SPB Git

Repository Public

Header.tsx 6.5 KB 112 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/components/layout/Header.tsx9 * Module           : components10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243"use client";44import Link from "next/link";45import { usePathname } from "next/navigation";46import { useEffect, useState } from "react";47import { Logo } from "./Logo";4849type Labels = { apps: string; models: string; maps: string; downloads: string; ecosystem: string; whatsNew: string; compare: string; support: string; menu: string; close: string; theme: string; language: string };5051function ThemeToggle({ label }: { label: string }) {52  const toggle = () => {53    const root = document.documentElement;54    const current = root.dataset.theme ?? (matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");55    const next = current === "light" ? "dark" : "light";56    root.dataset.theme = next;57    try { localStorage.setItem("orix-theme", next); } catch { /* private mode */ }58  };59  return (60    <button type="button" onClick={toggle} aria-label={label} title={label} className="grid h-10 w-10 place-items-center rounded-full text-ink2 transition-colors hover:text-ink" data-testid="theme-toggle">61      <svg width="18" height="18" viewBox="0 0 18 18" fill="none" aria-hidden><circle cx="9" cy="9" r="6.2" stroke="currentColor" strokeWidth="1.5" /><path d="M9 2.8a6.2 6.2 0 0 0 0 12.4Z" fill="currentColor" /></svg>62    </button>63  );64}6566export function Header({ locale, labels }: { locale: "en" | "fr"; labels: Labels }) {67  const path = usePathname() ?? "/";68  const [open, setOpen] = useState(false);69  const [scrolled, setScrolled] = useState(false);70  useEffect(() => { setOpen(false); }, [path]);71  useEffect(() => {72    const on = () => setScrolled(window.scrollY > 12);73    on(); window.addEventListener("scroll", on, { passive: true });74    return () => window.removeEventListener("scroll", on);75  }, []);76  useEffect(() => { document.body.style.overflow = open ? "hidden" : ""; return () => { document.body.style.overflow = ""; }; }, [open]);7778  const p = (s: string) => (locale === "en" ? s : `/fr${s === "/" ? "" : s}`);79  const bare = path === "/fr" ? "/" : path.startsWith("/fr/") ? path.slice(3) : path;80  const other = locale === "en" ? `/fr${bare === "/" ? "" : bare}` : bare;81  const links = [["/apps", labels.apps], ["/models", labels.models], ["/maps", labels.maps], ["/downloads", labels.downloads], ["/ecosystem", labels.ecosystem], ["/whats-new", labels.whatsNew], ["/compare", labels.compare], ["/support", labels.support]] as const;82  const active = (h: string) => bare === h || bare.startsWith(h + "/");8384  return (85    <header className={`fixed inset-x-0 top-0 z-50 transition-[background-color,border-color,backdrop-filter] duration-500 ${scrolled || open ? "border-b border-line bg-[color-mix(in_oklab,var(--bg)_78%,transparent)] backdrop-blur-xl" : "border-b border-transparent"}`}>86      <div className="wrap wrap-wide flex h-16 items-center justify-between gap-4">87        <Link href={p("/")} aria-label="ORIX" className="-ml-1 rounded-lg p-1"><Logo /></Link>88        <nav aria-label="Primary" className="hidden items-center gap-1 md:flex">89          {links.map(([h, l]) => (90            <Link key={h} href={p(h)} aria-current={active(h) ? "page" : undefined} data-testid={h === "/support" ? "nav-support" : undefined} className={`whitespace-nowrap rounded-full px-3 py-2 text-[0.93rem] font-medium transition-colors xl:px-3.5 ${h === "/compare" ? "hidden lg:inline-block " : h === "/maps" ? "hidden xl:inline-block " : ""}${h === "/support" ? "nav-support" : active(h) ? "text-ink" : "text-ink2 hover:text-ink"}`}>{h === "/support" && <span aria-hidden className="mr-1.5">♥</span>}{l}</Link>91          ))}92        </nav>93        <div className="flex items-center gap-1">94          <a href={other} hrefLang={locale === "en" ? "fr-CA" : "en"} lang={locale === "en" ? "fr-CA" : "en"} className="hidden rounded-full px-3 py-2 text-[0.88rem] font-medium text-ink2 transition-colors hover:text-ink sm:block" data-testid="locale-switch">{labels.language}</a>95          <ThemeToggle label={labels.theme} />96          <button type="button" className="grid h-10 w-10 place-items-center rounded-full text-ink md:hidden" aria-expanded={open} aria-controls="mobile-nav" aria-label={open ? labels.close : labels.menu} onClick={() => setOpen((o) => !o)}>97            <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden>98              <path d={open ? "M5 5l10 10M15 5L5 15" : "M3 7h14M3 13h14"} stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />99            </svg>100          </button>101        </div>102      </div>103      {open && (104        <nav id="mobile-nav" aria-label="Primary" className="wrap flex h-[calc(100dvh-4rem)] flex-col gap-1 overflow-y-auto pb-10 pt-4 md:hidden">105          {links.map(([h, l]) => <Link key={h} href={p(h)} className={`rule py-5 text-3xl font-semibold tracking-tight first:border-t-0 ${h === "/support" ? "beam-text" : ""}`}>{l}</Link>)}106          <a href={other} className="rule py-5 text-lg text-ink2">{labels.language}</a>107        </nav>108      )}109    </header>110  );111}112
Files main
Menu

Theme