SPB Git

Repository Public

NavLinks.tsx 2.0 KB 46 lines tsx

1"use client";2import Link from "next/link";3import { usePathname } from "next/navigation";4import { IconFeed, IconHome, IconInfo, IconSearch } from "./icons";56/** Chemin sans préfixe de langue (`/fr/x` après réécriture, `/en/x`) : sert à marquer le lien courant. */7export const barePath = (pathname: string | null) => (pathname ?? "/").replace(/^\/(fr|en)(?=\/|$)/, "") || "/";8const bare = (h: string) => barePath(h);9const isCurrent = (here: string, target: string) => (target === "/" ? here === "/" : here === target || here.startsWith(`${target}/`));1011/** Liens de l'en-tête (≥ 768 px). */12export function NavLinks({ items }: { items: { href: string; label: string; icon?: "feed" }[] }) {13  const here = barePath(usePathname());14  return (15    <>16      {items.map((it) => (17        <Link key={it.href} href={it.href} aria-current={isCurrent(here, bare(it.href)) ? "page" : undefined} className="nav-link hidden md:inline-flex">18          {it.icon === "feed" && <IconFeed size={18} className="text-accent-deep" />}19          {it.label}20        </Link>21      ))}22    </>23  );24}2526const ICONS = { home: IconHome, feed: IconFeed, search: IconSearch, about: IconInfo };27export interface Tab { href: string; label: string; icon: keyof typeof ICONS }2829/** Barre d'onglets du bas (téléphone) : Accueil / Fil / Recherche / À propos. Zones tactiles de 56 px, marges de sécurité iOS. */30export function TabBar({ tabs, label }: { tabs: Tab[]; label: string }) {31  const here = barePath(usePathname());32  return (33    <nav aria-label={label} className="tabbar" data-testid="tabbar">34      {tabs.map((t) => {35        const Icon = ICONS[t.icon];36        return (37          <Link key={t.href} href={t.href} aria-current={isCurrent(here, bare(t.href)) ? "page" : undefined} className={t.icon === "feed" ? "tab-feed" : undefined} data-testid={`tab-${t.icon}`}>38            <span className="tab-icon"><Icon size={21} /></span>39            <span>{t.label}</span>40          </Link>41        );42      })}43    </nav>44  );45}46
Files main
Menu

Theme