SPB Git

Repository Public

PropertyCard.tsx 4.4 KB 107 lines tsx

1// Carte compacte d'une propriété pour les rangées des pages marché, vrai prix2// et favoris : photo réelle, prix, lieu, quelques faits. Le clic ouvre la porte3// (doorClick), la photo porte `data-door-source`.45import type { ReactNode } from "react";6import { Link } from "react-router";7import { cn } from "@/lib/cn";8import { fmtMoney, fmtPct } from "@/lib/format";9import { doorClick, listingPath, preloadListing } from "@/brand/compat";10import { SmartImage } from "@/components/SmartImage";11import { priceOk, type VerdictKey } from "@/lib/api.marche";1213/** Étiquette posée sur une photo : fond de surface du thème, toujours lisible. */14export const PHOTO_TAG = "num rounded-[6px] bg-surface px-1.5 py-1 text-[0.72rem] font-semibold leading-none";1516export const VERDICT_TEXT: Record<VerdictKey, { label: string; long: string; tone: string }> = {17  sous: { label: "Sous l'estimation", long: "Prix demandé sous l'estimation", tone: "text-good" },18  marche: { label: "Prix aligné", long: "Prix demandé aligné sur l'estimation", tone: "text-fair" },19  sur: { label: "Au-dessus", long: "Prix demandé au-dessus de l'estimation", tone: "text-high" },20};2122const TONE_SOFT: Record<VerdictKey, string> = { sous: "bg-good-soft text-good", marche: "bg-fair-soft text-fair", sur: "bg-high-soft text-high" };2324/** Étiquette de verdict du vrai prix (fond teinté). */25export function VerdictLabel({ verdict, deviation, className }: { verdict: VerdictKey; deviation?: number | null; className?: string }) {26  return (27    <span className={cn("num inline-flex items-center gap-1.5 whitespace-nowrap rounded-[6px] px-2.5 py-1.5 text-[0.84rem] font-medium leading-none", TONE_SOFT[verdict], className)}>28      {VERDICT_TEXT[verdict].label}29      {deviation != null && verdict !== "marche" && <span>{fmtPct(deviation)}</span>}30    </span>31  );32}3334export function PropertyCard({35  uid,36  image,37  price,38  line,39  meta,40  verdict,41  deviation,42  context = "card",43  className,44  children,45}: {46  uid: string;47  image: string | null | undefined;48  price: number | null | undefined;49  /** type et lieu */50  line: ReactNode;51  meta?: ReactNode;52  verdict?: VerdictKey | null;53  deviation?: number | null;54  context?: "card" | "favorite";55  className?: string;56  children?: ReactNode;57}) {58  return (59    <Link60      to={listingPath(uid)}61      onClick={(e) => doorClick(e, { uid, image: image ?? null, context })}62      onMouseEnter={() => preloadListing(uid)}63      className={cn("group block outline-none", className)}64    >65      <div data-door-source className="relative aspect-[4/3] overflow-hidden rounded-xl bg-surface-2 transition-transform duration-100 ease-out group-active:scale-[0.985]">66        <SmartImage src={image ?? null} alt="" className="absolute inset-0 size-full transition-transform duration-500 ease-[cubic-bezier(0.2,0.7,0.2,1)] group-hover:scale-[1.035]" />67        {verdict && verdict !== "marche" && (68          <span className={cn(PHOTO_TAG, "absolute left-2.5 top-2.5", VERDICT_TEXT[verdict].tone)}>69            {VERDICT_TEXT[verdict].label}70            {deviation != null && <span className="ml-1 font-medium">{fmtPct(deviation)}</span>}71          </span>72        )}73        {children}74      </div>75      <div className="pt-3">76        <p className="num text-[1.06rem] font-semibold leading-tight">{priceOk(price) ? fmtMoney(price) : <span className="text-[0.95rem] font-medium text-ink-2">Prix sur demande</span>}</p>77        <p className="mt-1 truncate text-[0.9rem] text-ink group-hover:text-brand">{line}</p>78        {meta && <p className="num mt-0.5 truncate text-[0.82rem] text-ink-3">{meta}</p>}79      </div>80    </Link>81  );82}8384export function PropertyCardSkeleton() {85  return (86    <div aria-hidden>87      <div className="skeleton aspect-[4/3] rounded-xl" />88      <div className="skeleton mt-3 h-5 w-28" />89      <div className="skeleton mt-2 h-4 w-40" />90    </div>91  );92}9394/** Rangée de cartes : défilement horizontal aimanté sur mobile, grille ensuite. */95export function CardRow({ children, className }: { children: ReactNode; className?: string }) {96  return (97    <div98      className={cn(99        "no-scrollbar -mx-[clamp(1rem,4vw,2.5rem)] flex snap-x gap-4 overflow-x-auto px-[clamp(1rem,4vw,2.5rem)] sm:mx-0 sm:grid sm:grid-cols-2 sm:gap-x-5 sm:gap-y-8 sm:overflow-visible sm:px-0 lg:grid-cols-4 [&>*]:w-[72vw] [&>*]:shrink-0 [&>*]:snap-start sm:[&>*]:w-auto",100        className,101      )}102    >103      {children}104    </div>105  );106}107
Files main
Menu

Theme