SPB Git

Repository Public

MapChrome.tsx 5.3 KB 149 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 { LoukaLoadingIndicator } from "@/brand/Door";9import { LoukaSymbol } from "@/brand/Symbol";10import "./map.css";1112const LEGEND_KEY = "louka: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-brand bg-brand text-brand-ink",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-9 place-items-center overflow-hidden rounded-[3px] border text-[0.6rem] font-medium leading-none", style[kind])}25    >26      <span className={cn("absolute inset-x-0 top-0 h-[2px]", kind === "seen" ? "bg-line-2" : kind === "high" ? "bg-high" : "bg-accent")} />27      1,4 k28    </span>29  );30}3132function Legend() {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 top-3 z-10 max-w-[calc(100%-5rem)]", open ? "w-[13.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="flex h-8 w-full items-center justify-between gap-2 px-3 text-[0.8rem] text-ink-2 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" /> Bon prix (sous le marché)65            </li>66            <li className="flex items-center gap-2.5">67              <Swatch kind="neutral" /> Prix juste ou non estimé68            </li>69            <li className="flex items-center gap-2.5">70              <Swatch kind="high" /> Élevé71            </li>72            <li className="flex items-center gap-2.5">73              <Swatch kind="seen" /> Déjà vu74            </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                <LoukaSymbol size={18} />78              </span>79              Logement sélectionné80            </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              Logements du secteur90            </li>91          </ul>92        )}93      </div>94    </div>95  );96}9798export function MapChrome({99  total,100  loading,101  pitched,102  mobile,103  onZoomIn,104  onZoomOut,105  onPitch,106  onLocate,107}: {108  total: number | undefined;109  loading: boolean;110  pitched: boolean;111  mobile?: boolean;112  onZoomIn: () => void;113  onZoomOut: () => void;114  onPitch: () => void;115  onLocate: () => void;116}) {117  return (118    <>119      {!mobile && (120        <div className="pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center px-3">121          <div className="num flex h-8 items-center gap-2 rounded-[8px] border border-line bg-surface px-3 text-[0.8rem] text-ink shadow-card" aria-live="polite">122            {loading && <LoukaLoadingIndicator size={11} />}123            {total == null ? "Chargement des logements" : plural(total, "logement", "logements")}124          </div>125        </div>126      )}127      <div className="absolute right-3 top-3 z-10 flex flex-col gap-2">128        <div className="lk-mapgroup">129          <button type="button" aria-label="Zoom avant" onClick={onZoomIn} className="lk-mapctl">130            <Plus className="size-[17px]" strokeWidth={1.8} />131          </button>132          <button type="button" aria-label="Zoom arrière" onClick={onZoomOut} className="lk-mapctl">133            <Minus className="size-[17px]" strokeWidth={1.8} />134          </button>135        </div>136        <div className="lk-mapgroup">137          <button type="button" aria-label="Vue en relief" aria-pressed={pitched} onClick={onPitch} className="lk-mapctl">138            <Box className="size-[17px]" strokeWidth={1.8} />139          </button>140          <button type="button" aria-label="Autour de moi" onClick={onLocate} className="lk-mapctl">141            <LocateFixed className="size-[17px]" strokeWidth={1.8} />142          </button>143        </div>144      </div>145      <Legend />146    </>147  );148}149
Files main
Menu

Theme