SPB Git

Repository Public

MapChrome.tsx 5.8 KB 154 lines tsx

1// Habillage de la carte : compteur, commandes (zoom, relief, autour de moi) et2// légende repliable. Sobre, aux formes de la marque.34import { useState } from "react";5import { Box, ChevronDown, LocateFixed, Minus, Plus } from "lucide-react";6import { cn } from "@/lib/cn";7import { plural } from "@/lib/format";8import { ImmokaLoadingIndicator } from "@/brand/House";9import { ImmokaSymbol } from "@/brand/Symbol";10import "./map.css";1112const LEGEND_KEY = "immoka:legende";1314function Swatch({ kind }: { kind: "neutral" | "good" | "high" | "seen" }) {15  const style: Record<typeof kind, string> = {16    neutral: "border-line-2 bg-surface text-ink",17    good: "border-good bg-surface text-good",18    high: "border-high bg-surface text-high",19    seen: "border-line bg-surface-2 text-ink-3",20  };21  return (22    <span23      aria-hidden24      className={cn("num relative inline-grid h-[1.15rem] w-10 place-items-center overflow-hidden rounded-[3px] border text-[0.6rem] font-medium leading-none", style[kind])}25    >26      {(kind === "high" || kind === "good") && <span className={cn("absolute inset-x-0 top-0 h-[2px]", kind === "high" ? "bg-high" : "bg-good")} />}27      649 k28    </span>29  );30}3132function Legend({ low }: { low?: boolean }) {33  const [open, setOpen] = useState(() => {34    try {35      return localStorage.getItem(LEGEND_KEY) === "1";36    } catch {37      return false;38    }39  });40  const toggle = () => {41    const next = !open;42    setOpen(next);43    try {44      localStorage.setItem(LEGEND_KEY, next ? "1" : "0");45    } catch {46      /* ignoré */47    }48  };49  return (50    <div className={cn("absolute left-3 z-10 max-w-[calc(100%-5rem)]", low ? "top-[3.4rem]" : "top-3", open ? "w-[14.5rem]" : "w-auto")}>51      <div className="overflow-hidden rounded-[10px] border border-line bg-surface shadow-card">52        <button53          type="button"54          onClick={toggle}55          aria-expanded={open}56          className="relative flex h-8 w-full items-center justify-between gap-2 px-3 text-[0.8rem] text-ink-2 before:absolute before:-inset-1.5 before:content-[''] hover:text-ink"57        >58          Légende59          <ChevronDown className={cn("size-3.5 text-ink-3 transition-transform duration-150", open && "rotate-180")} />60        </button>61        {open && (62          <ul className="space-y-2 border-t border-line px-3 pb-3 pt-2.5 text-[0.78rem] text-ink-2">63            <li className="flex items-center gap-2.5">64              <Swatch kind="good" /> Sous le vrai prix65            </li>66            <li className="flex items-center gap-2.5">67              <Swatch kind="neutral" /> Près du vrai prix, ou non estimé68            </li>69            <li className="flex items-center gap-2.5">70              <Swatch kind="high" /> Au-dessus du vrai prix71            </li>72            <li className="flex items-center gap-2.5">73              <Swatch kind="seen" /> Déjà consultée74            </li>75            <li className="flex items-center gap-2.5">76              <span aria-hidden className="inline-grid h-[1.15rem] w-9 place-items-center">77                <ImmokaSymbol size={18} />78              </span>79              Propriété sélectionnée80            </li>81            <li className="flex items-center gap-2.5 border-t border-line pt-2">82              <span83                aria-hidden84                className="relative inline-grid h-[1.3rem] w-9 place-items-center overflow-hidden rounded-[3px] bg-ink font-display text-[0.74rem] leading-none text-bg"85              >86                <span className="absolute inset-x-0 top-0 h-[2px] bg-accent" />87                6288              </span>89              Propriétés du secteur90            </li>91          </ul>92        )}93      </div>94    </div>95  );96}9798export function MapChrome({99  total,100  caption,101  loading,102  error,103  pitched,104  mobile,105  onZoomIn,106  onZoomOut,107  onPitch,108  onLocate,109}: {110  total: number | undefined;111  /** mobile : la phrase de décompte de la page remplace le total */112  caption?: string;113  loading: boolean;114  error?: boolean;115  pitched: boolean;116  mobile?: boolean;117  onZoomIn: () => void;118  onZoomOut: () => void;119  onPitch: () => void;120  onLocate: () => void;121}) {122  return (123    <>124      <div className={cn("pointer-events-none absolute top-3 z-10 flex px-3", mobile ? "left-0 right-14 justify-start" : "inset-x-0 justify-center")}>125        <div className="num flex h-8 min-w-0 items-center gap-2 rounded-[8px] border border-line bg-surface px-3 text-[0.8rem] text-ink shadow-card" aria-live="polite">126          {loading && !error && <ImmokaLoadingIndicator size={11} />}127          <span className="truncate">128            {error ? "Les propriétés n'ont pas pu être placées sur la carte" : (caption ?? (total == null ? "Chargement des propriétés" : total === 0 ? "Aucune propriété" : plural(total, "propriété", "propriétés")))}129          </span>130        </div>131      </div>132      <div className="absolute right-3 top-3 z-10 flex flex-col gap-2">133        <div className="ik-mapgroup">134          <button type="button" aria-label="Zoom avant" onClick={onZoomIn} className="ik-mapctl">135            <Plus className="size-[17px]" strokeWidth={1.8} />136          </button>137          <button type="button" aria-label="Zoom arrière" onClick={onZoomOut} className="ik-mapctl">138            <Minus className="size-[17px]" strokeWidth={1.8} />139          </button>140        </div>141        <div className="ik-mapgroup">142          <button type="button" aria-label="Vue en relief" aria-pressed={pitched} onClick={onPitch} className="ik-mapctl">143            <Box className="size-[17px]" strokeWidth={1.8} />144          </button>145          <button type="button" aria-label="Autour de moi" onClick={onLocate} className="ik-mapctl">146            <LocateFixed className="size-[17px]" strokeWidth={1.8} />147          </button>148        </div>149      </div>150      <Legend low={mobile} />151    </>152  );153}154
Files main
Menu

Theme