SPB Git

Repository Public

Shell.tsx 15.6 KB 408 lines tsx

1// Ossature : en-tête, navigation mobile, pied de page, palette, comparateur.23import { useEffect, useState } from "react";4import { Link, NavLink, Outlet, ScrollRestoration, useLocation, useNavigation, useNavigationType } from "react-router";5import { useIsFetching } from "@tanstack/react-query";6import { LayoutGroup } from "motion/react";7import { Heart, Menu, Moon, Scale, Search, Sun } from "lucide-react";8import { cn } from "@/lib/cn";9import { notifyMotion, SlideMark } from "@/lib/motion";10import { setTheme, useCompare, useFavorites, useTheme } from "@/lib/store";11import { getMotionPref, setMotionPref, type MotionPref } from "@/brand/engine";12import { IconBroker, IconHouse, IconHouseOpen, IconNeighborhood } from "@/brand/icons";13import { ImmokaLogo } from "@/brand/Symbol";14import { ImmokaDoorTransition } from "@/brand/transition";15import { Kbd } from "@/ui/primitives";16import { Sheet } from "@/ui/Sheet";17import { Toaster } from "@/ui/toast";18import { CommandPalette } from "./CommandPalette";1920const NAV = [21  { to: "/recherche", label: "Explorer" },22  { to: "/villes", label: "Villes" },23  { to: "/agences", label: "Courtiers et agences" },24  { to: "/marche", label: "Marché" },25  { to: "/taux", label: "Taux hypothécaires" },26];2728const MORE = [29  { to: "/recherche", label: "Explorer la carte" },30  { to: "/villes", label: "Villes" },31  { to: "/agences", label: "Courtiers et agences" },32  { to: "/marche", label: "Marché immobilier" },33  { to: "/taux", label: "Taux hypothécaires" },34  { to: "/favoris", label: "Favoris" },35  { to: "/comparer", label: "Comparateur" },36  { to: "/vrai-prix", label: "Le vrai prix : la méthode" },37  { to: "/inspecteurs", label: "Inspecteurs en bâtiment" },38  { to: "/demenageurs", label: "Déménageurs" },39  { to: "/sources", label: "Sources" },40  { to: "/a-propos", label: "À propos" },41  { to: "/contact", label: "Contact" },42];4344const MOTION: { value: MotionPref; label: string }[] = [45  { value: "auto", label: "Automatique" },46  { value: "compact", label: "Discrètes" },47  { value: "none", label: "Aucune" },48];4950function ThemeToggle() {51  const theme = useTheme();52  return (53    <button54      type="button"55      onClick={() => {56        const root = document.documentElement;57        root.classList.add("ik-theming");58        setTheme(theme === "dark" ? "light" : "dark");59        window.setTimeout(() => root.classList.remove("ik-theming"), 280);60      }}61      aria-label={theme === "dark" ? "Passer au thème clair" : "Passer au thème sombre"}62      className="ik-press grid size-10 place-items-center rounded-full text-ink-2 transition-colors duration-150 hover:bg-surface-2 hover:text-ink"63    >64      <span key={theme} className="ik-spin-in grid">65        {theme === "dark" ? <Sun className="size-[18px]" /> : <Moon className="size-[18px]" />}66      </span>67    </button>68  );69}7071function Header({ onSearch, onMenu }: { onSearch: () => void; onMenu: () => void }) {72  const { pathname } = useLocation();73  const favCount = Object.keys(useFavorites()).length;74  const wide = pathname === "/recherche";75  const [scrolled, setScrolled] = useState(false);76  useEffect(() => {77    const on = () => setScrolled(window.scrollY > 12);78    on();79    window.addEventListener("scroll", on, { passive: true });80    return () => window.removeEventListener("scroll", on);81  }, []);82  return (83    <header className={cn("sticky top-0 z-50 border-b bg-bg transition-[box-shadow,border-color] duration-300", scrolled ? "border-line-2 shadow-[0_6px_20px_-14px_rgb(0_0_0/0.35)]" : "border-line")}>84      <div className={cn("flex h-16 items-center gap-1", wide ? "px-4 lg:px-6" : "container-x")}>85        <Link to="/" aria-label="Immo-Ka, accueil" className="ik-logo mr-4 shrink-0 xl:mr-6">86          <ImmokaLogo size={34} className={cn("origin-left text-[1.5rem] transition-transform duration-300 ease-[cubic-bezier(0.2,0.7,0.2,1)]", scrolled && "scale-[0.94]")} />87        </Link>88        <LayoutGroup id="entete">89        <nav className="hidden items-center lg:flex" aria-label="Navigation principale">90          {NAV.map((n) => (91            <NavLink92              key={n.to}93              to={n.to}94              className={({ isActive }) =>95                cn(96                  "relative whitespace-nowrap px-2.5 py-2 text-[0.92rem] transition-colors duration-150 xl:px-3",97                  isActive ? "font-medium text-ink" : "text-ink-2 hover:text-ink",98                )99              }100            >101              {({ isActive }) => (102                <>103                  {n.label}104                  {isActive && <SlideMark id="nav-mark" className="absolute inset-x-2.5 -bottom-[13px] h-0.5 bg-accent xl:inset-x-3" />}105                </>106              )}107            </NavLink>108          ))}109        </nav>110        </LayoutGroup>111        <div className="flex-1" />112        <button113          type="button"114          onClick={onSearch}115          className="hidden h-10 items-center gap-2.5 rounded-[10px] border border-line-2 bg-surface pl-3 pr-2 text-[0.88rem] text-ink-3 transition-colors duration-150 hover:border-ink-3 md:flex lg:max-xl:[&>span]:hidden"116        >117          <Search className="size-4" />118          <span className="pr-8">Ville, quartier, adresse</span>119          <Kbd>⌘K</Kbd>120        </button>121        <button122          type="button"123          onClick={onSearch}124          aria-label="Recherche rapide"125          className="grid size-10 place-items-center rounded-full text-ink-2 hover:bg-surface-2 hover:text-ink md:hidden"126        >127          <Search className="size-5" />128        </button>129        <Link130          to="/favoris"131          aria-label={`Favoris (${favCount})`}132          className="relative hidden size-10 place-items-center rounded-full text-ink-2 transition-colors duration-150 hover:bg-surface-2 hover:text-ink sm:grid"133        >134          <Heart className="size-[18px]" />135          {favCount > 0 && (136            <span className="num absolute right-0.5 top-0.5 grid h-4 min-w-4 place-items-center rounded-full bg-accent px-1 text-[0.6rem] font-semibold text-white">137              {favCount}138            </span>139          )}140        </Link>141        <ThemeToggle />142        <button143          type="button"144          onClick={onMenu}145          aria-label="Menu"146          className="grid size-10 place-items-center rounded-full text-ink-2 hover:bg-surface-2 hover:text-ink lg:hidden"147        >148          <Menu className="size-5" />149        </button>150      </div>151    </header>152  );153}154155function TabBar() {156  const favCount = Object.keys(useFavorites()).length;157  const tabs = [158    { to: "/", label: "Accueil", icon: IconHouse, end: true },159    { to: "/recherche", label: "Explorer", icon: IconHouseOpen },160    { to: "/favoris", label: "Favoris", icon: Heart, badge: favCount },161    { to: "/agences", label: "Courtiers", icon: IconBroker },162    { to: "/marche", label: "Marché", icon: IconNeighborhood },163  ];164  return (165    <nav aria-label="Navigation" className="fixed inset-x-0 bottom-0 z-50 border-t border-line bg-bg pb-[env(safe-area-inset-bottom)] lg:hidden">166      <LayoutGroup id="onglets">167      <ul className="mx-auto grid max-w-md grid-cols-5">168        {tabs.map(({ to, label, icon: Icon, end, badge }) => (169          <li key={to}>170            <NavLink171              to={to}172              end={end}173              className={({ isActive }) =>174                cn(175                  "relative flex h-14 flex-col items-center justify-center gap-0.5 text-[0.66rem] transition-colors duration-150",176                  isActive ? "font-medium text-ink" : "text-ink-3",177                )178              }179            >180              {({ isActive }) => (181                <>182                  {isActive && <SlideMark id="tab-mark" className="absolute inset-x-6 top-0 h-0.5 bg-accent" />}183                  <span className="relative">184                    <Icon size={21} className="size-[21px]" strokeWidth={isActive ? 1.9 : 1.6} />185                    {!!badge && (186                      <span className="num absolute -right-2 -top-1 grid h-3.5 min-w-3.5 place-items-center rounded-full bg-accent px-1 text-[0.56rem] font-semibold text-white">187                        {badge}188                      </span>189                    )}190                  </span>191                  {label}192                </>193              )}194            </NavLink>195          </li>196        ))}197      </ul>198      </LayoutGroup>199    </nav>200  );201}202203/** Barre fine en haut : seulement quand une attente réelle dépasse 300 ms. */204function TopProgress() {205  const navigating = useNavigation().state === "loading";206  const fetching = useIsFetching({ predicate: (q) => q.state.data === undefined }) > 0;207  const busy = navigating || fetching;208  const [show, setShow] = useState(false);209  useEffect(() => {210    if (!busy) {211      setShow(false);212      return;213    }214    const t = window.setTimeout(() => setShow(true), 300);215    return () => window.clearTimeout(t);216  }, [busy]);217  return show ? <div className="ik-progress" role="progressbar" aria-label="Chargement" /> : null;218}219220function CompareTray() {221  const items = useCompare();222  const { pathname } = useLocation();223  if (!items.length || pathname === "/comparer") return null;224  return (225    <div className="ik-rise fixed bottom-[calc(4.4rem+env(safe-area-inset-bottom))] right-4 z-40 lg:bottom-6 lg:right-6">226      <Link227        to="/comparer"228        className="flex h-11 items-center gap-2.5 rounded-[10px] bg-ink pl-3.5 pr-4 text-[0.88rem] font-medium text-bg shadow-float transition-transform duration-100 active:scale-[0.98]"229      >230        <Scale className="size-4" />231        Comparer232        <span key={items.length} className="num ik-heart-pop grid size-5 place-items-center rounded-full bg-bg/15 text-xs">{items.length}</span>233      </Link>234    </div>235  );236}237238function Footer() {239  const cols = [240    {241      title: "Chercher",242      links: [243        ["/recherche", "Carte des propriétés"],244        ["/villes", "Toutes les villes"],245        ["/favoris", "Mes favoris"],246        ["/comparer", "Comparateur"],247      ],248    },249    {250      title: "Comprendre",251      links: [252        ["/marche", "Marché immobilier"],253        ["/taux", "Taux hypothécaires"],254        ["/vrai-prix", "Le vrai prix : la méthode"],255        ["/sources", "Sources"],256      ],257    },258    {259      title: "Annuaires",260      links: [261        ["/agences", "Courtiers et agences"],262        ["/inspecteurs", "Inspecteurs en bâtiment"],263        ["/demenageurs", "Déménageurs"],264      ],265    },266    {267      title: "Immo-Ka",268      links: [269        ["/a-propos", "À propos"],270        ["/contact", "Contact"],271        ["/confidentialite", "Confidentialité"],272        ["/conditions", "Conditions d'utilisation"],273      ],274    },275  ] as const;276  return (277    <footer className="mt-24 border-t border-line pb-[calc(5rem+env(safe-area-inset-bottom))] lg:pb-0">278      <div className="container-x grid gap-10 py-14 lg:grid-cols-[1.2fr_2.8fr]">279        <div>280          <ImmokaLogo size={34} className="text-[1.5rem]" />281          <p className="mt-4 max-w-xs text-[0.9rem] leading-relaxed text-ink-3">282            Les propriétés à vendre au Québec, réunies au même endroit. Indépendant, sans compte, sans publicité ciblée.283          </p>284        </div>285        <div className="grid grid-cols-2 gap-8 sm:grid-cols-4">286          {cols.map((c) => (287            <div key={c.title}>288              <div className="eyebrow mb-3.5">{c.title}</div>289              <ul className="space-y-2.5">290                {c.links.map(([to, label]) => (291                  <li key={to}>292                    <Link to={to} className="text-[0.9rem] text-ink-2 transition-colors duration-150 hover:text-ink">293                      {label}294                    </Link>295                  </li>296                ))}297              </ul>298            </div>299          ))}300        </div>301      </div>302      <div className="border-t border-line">303        <div className="container-x flex flex-wrap items-center justify-between gap-3 py-5 text-xs text-ink-3">304          <span>© {new Date().getFullYear()} Immo-Ka. Chaque inscription appartient à son auteur et renvoie vers sa source.</span>305          <a href="mailto:contact@spboucher.ai" className="hover:text-ink">306            contact@spboucher.ai307          </a>308        </div>309      </div>310    </footer>311  );312}313314function MotionSetting() {315  const [pref, setPref] = useState<MotionPref>(getMotionPref());316  const current = MOTION.some((m) => m.value === pref) ? pref : "auto";317  return (318    <div className="mt-4 border-t border-line pt-5">319      <div className="text-[0.92rem] font-medium">Animations d'ouverture</div>320      <p className="mt-1 text-[0.84rem] text-ink-3">La porte de la maison qui s'ouvre quand vous choisissez une propriété.</p>321      <div role="radiogroup" aria-label="Animations d'ouverture" className="mt-3 inline-flex rounded-[10px] bg-surface-2 p-1">322        {MOTION.map((m) => (323          <button324            key={m.value}325            type="button"326            role="radio"327            aria-checked={current === m.value}328            onClick={() => {329              setMotionPref(m.value);330              setPref(m.value);331              notifyMotion();332            }}333            className={cn(334              "h-9 rounded-[7px] px-3.5 text-[0.84rem] transition-colors duration-150",335              current === m.value ? "bg-surface font-medium text-ink shadow-card" : "text-ink-3",336            )}337          >338            {m.label}339          </button>340        ))}341      </div>342    </div>343  );344}345346export function Shell() {347  const { pathname, state, key: locationKey } = useLocation();348  const doorArrival = !!(state as { door?: string } | null)?.door;349  // arrivée directe sur le site : le contenu s'affiche tout de suite, sans fondu350  const firstLoad = locationKey === "default";351  // retour arrière : fondu bref, sans glissement (on revient où l'on était)352  const back = useNavigationType() === "POP";353  const [palette, setPalette] = useState(false);354  const [menu, setMenu] = useState(false);355  const immersive = pathname === "/recherche";356357  useEffect(() => {358    const on = (e: KeyboardEvent) => {359      if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {360        e.preventDefault();361        setPalette((p) => !p);362      }363    };364    window.addEventListener("keydown", on);365    return () => window.removeEventListener("keydown", on);366  }, []);367368  useEffect(() => setMenu(false), [pathname]);369370  return (371    <div className={cn("flex min-h-dvh flex-col", immersive && "h-dvh overflow-hidden")}>372      <a373        href="#contenu"374        className="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-[100] focus:rounded-[8px] focus:bg-ink focus:px-4 focus:py-2 focus:text-sm focus:font-medium focus:text-bg"375      >376        Aller au contenu377      </a>378      <TopProgress />379      <Header onSearch={() => setPalette(true)} onMenu={() => setMenu(true)} />380      <main id="contenu" className={cn("flex-1", immersive ? "min-h-0" : "min-h-[calc(100dvh-4rem)]")}>381        {/* fondu bref au changement de page, sauf quand la porte a fait la transition */}382        <div key={pathname} className={cn(immersive && "h-full", !doorArrival && !immersive && !firstLoad && (back ? "ik-page-back" : "ik-page-in"))}>383          <Outlet />384        </div>385      </main>386      {!immersive && <Footer />}387      <TabBar />388      <CompareTray />389      <CommandPalette open={palette} onClose={() => setPalette(false)} />390      <Sheet open={menu} onClose={() => setMenu(false)} title="Menu">391        <ul className="-mx-2">392          {MORE.map((m) => (393            <li key={m.to}>394              <Link to={m.to} className="block rounded-[8px] px-3 py-3 text-[1rem] text-ink hover:bg-surface-2">395                {m.label}396              </Link>397            </li>398          ))}399        </ul>400        <MotionSetting />401      </Sheet>402      <Toaster />403      <ImmokaDoorTransition />404      <ScrollRestoration />405    </div>406  );407}408
Files main
Menu

Theme