SPB Git

Repository Public

primitives.tsx 7.3 KB 257 lines tsx

1// Composants de base du système de design Immo-Ka.23import type { ButtonHTMLAttributes, ReactNode } from "react";4import { Link, type LinkProps } from "react-router";5import { cn } from "@/lib/cn";67// --- Bouton -------------------------------------------------------------------8type Variant = "primary" | "solid" | "soft" | "ghost" | "outline" | "glass";9type Size = "sm" | "md" | "lg";1011const base =12  "inline-flex items-center justify-center gap-2 font-medium whitespace-nowrap select-none " +13  "transition-[background-color,border-color,color,opacity,transform] duration-150 ease-out " +14  "active:scale-[0.98] disabled:opacity-50 disabled:active:scale-100";1516const variants: Record<Variant, string> = {17  primary: "bg-brand text-brand-ink hover:bg-brand-strong",18  solid: "bg-ink text-bg hover:opacity-90",19  soft: "bg-surface-2 text-ink hover:bg-surface-3",20  ghost: "text-ink-2 hover:text-ink hover:bg-surface-2",21  outline: "border border-line-2 text-ink hover:border-ink-3",22  glass: "border border-line bg-surface text-ink hover:border-line-2",23};2425const sizes: Record<Size, string> = {26  sm: "h-9 px-3 text-[0.84rem] rounded-[8px]",27  md: "h-11 px-4 text-[0.92rem] rounded-[10px]",28  lg: "h-12 px-5 text-[0.95rem] rounded-[10px]",29};3031export function buttonClass(variant: Variant = "soft", size: Size = "md", className?: string) {32  return cn(base, variants[variant], sizes[size], className);33}3435interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {36  variant?: Variant;37  size?: Size;38}3940export function Button({ variant = "soft", size = "md", className, type = "button", ...rest }: ButtonProps) {41  return <button type={type} className={buttonClass(variant, size, className)} {...rest} />;42}4344export function ButtonLink({45  variant = "soft",46  size = "md",47  className,48  ...rest49}: LinkProps & { variant?: Variant; size?: Size }) {50  return <Link className={buttonClass(variant, size, className)} {...rest} />;51}5253interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {54  label: string;55  variant?: Variant;56  size?: "sm" | "md" | "lg";57  active?: boolean;58}5960export function IconButton({61  label,62  variant = "ghost",63  size = "md",64  active,65  className,66  type = "button",67  ...rest68}: IconButtonProps) {69  const dim = size === "sm" ? "size-8" : size === "lg" ? "size-12" : "size-10";70  return (71    <button72      type={type}73      aria-label={label}74      title={label}75      aria-pressed={active}76      className={cn(base, variants[variant], dim, "rounded-full shrink-0", active && "text-brand", className)}77      {...rest}78    />79  );80}8182// --- Pastille à bascule (filtres) ---------------------------------------------83interface ChipProps extends ButtonHTMLAttributes<HTMLButtonElement> {84  active?: boolean;85  tone?: "default" | "good";86}8788export function Chip({ active, tone = "default", className, type = "button", ...rest }: ChipProps) {89  return (90    <button91      type={type}92      aria-pressed={active}93      className={cn(94        "inline-flex h-9 shrink-0 items-center gap-1.5 rounded-[8px] border px-3 text-[0.84rem] font-medium",95        "transition-colors duration-150",96        active97          ? tone === "good"98            ? "border-brand bg-brand-soft text-brand"99            : "border-ink bg-ink text-bg"100          : "border-line-2 text-ink-2 hover:border-ink-3 hover:text-ink",101        className,102      )}103      {...rest}104    />105  );106}107108// --- Étiquette ----------------------------------------------------------------109type Tone = "neutral" | "brand" | "good" | "fair" | "high" | "bad";110const tones: Record<Tone, string> = {111  neutral: "bg-surface-2 text-ink-2",112  brand: "bg-brand-soft text-brand",113  good: "bg-good-soft text-good",114  fair: "bg-fair-soft text-fair",115  high: "bg-high-soft text-high",116  bad: "bg-bad-soft text-bad",117};118119export function Badge({120  tone = "neutral",121  className,122  children,123}: {124  tone?: Tone;125  className?: string;126  children: ReactNode;127}) {128  return (129    <span130      className={cn(131        "inline-flex items-center gap-1 rounded-[6px] px-2 py-1 text-[0.72rem] font-medium leading-none",132        tones[tone],133        className,134      )}135    >136      {children}137    </span>138  );139}140141// --- Sélecteur segmenté ---------------------------------------------------------142export function Segmented<T extends string>({143  value,144  onChange,145  options,146  label,147  className,148}: {149  value: T;150  onChange: (v: T) => void;151  options: { value: T; label: ReactNode }[];152  label: string;153  className?: string;154}) {155  return (156    <div role="radiogroup" aria-label={label} className={cn("inline-flex rounded-[10px] bg-surface-2 p-1", className)}>157      {options.map((o) => (158        <button159          key={o.value}160          type="button"161          role="radio"162          aria-checked={value === o.value}163          onClick={() => onChange(o.value)}164          className={cn(165            "inline-flex h-8 items-center gap-1.5 rounded-[7px] px-3 text-[0.83rem] font-medium transition-colors duration-150",166            value === o.value ? "bg-surface text-ink shadow-card" : "text-ink-3 hover:text-ink",167          )}168        >169          {o.label}170        </button>171      ))}172    </div>173  );174}175176// --- Divers -------------------------------------------------------------------177export function Skeleton({ className }: { className?: string }) {178  return <div aria-hidden className={cn("skeleton", className)} />;179}180181export function Kbd({ children }: { children: ReactNode }) {182  return (183    <kbd className="rounded-md border border-line-2 bg-surface-2 px-1.5 py-0.5 font-sans text-[0.68rem] font-medium text-ink-3">184      {children}185    </kbd>186  );187}188189/** Chiffre clé : grande valeur, libellé discret. */190export function Stat({191  value,192  label,193  hint,194  className,195}: {196  value: ReactNode;197  label: ReactNode;198  hint?: ReactNode;199  className?: string;200}) {201  return (202    <div className={className}>203      <div className="num text-[1.75rem] font-semibold leading-none tracking-tight text-ink">{value}</div>204      <div className="mt-1 text-sm text-ink-3">{label}</div>205      {hint && <div className="mt-0.5 text-xs text-ink-3/80">{hint}</div>}206    </div>207  );208}209210/** En-tête de section : sur-titre, titre, texte, action à droite. */211export function SectionHeader({212  eyebrow,213  title,214  text,215  action,216  className,217}: {218  eyebrow?: ReactNode;219  title: ReactNode;220  text?: ReactNode;221  action?: ReactNode;222  className?: string;223}) {224  return (225    <div className={cn("flex flex-wrap items-end justify-between gap-x-8 gap-y-3", className)}>226      <div className="max-w-2xl">227        {eyebrow && <div className="eyebrow mb-2">{eyebrow}</div>}228        <h2 className="text-[1.65rem] sm:text-[2rem]">{title}</h2>229        {text && <p className="mt-2 text-[0.98rem] leading-relaxed text-ink-2">{text}</p>}230      </div>231      {action}232    </div>233  );234}235236/** État vide générique (les états illustrés sont dans brand/EmptyState). */237export function EmptyState({238  icon,239  title,240  text,241  action,242}: {243  icon?: ReactNode;244  title: string;245  text?: ReactNode;246  action?: ReactNode;247}) {248  return (249    <div className="mx-auto flex max-w-sm flex-col items-center px-6 py-14 text-center">250      {icon && <div className="mb-5 grid size-12 place-items-center rounded-[10px] bg-surface-2 text-ink-2">{icon}</div>}251      <h3 className="text-[1.3rem]">{title}</h3>252      {text && <p className="mt-2 text-[0.92rem] leading-relaxed text-ink-3">{text}</p>}253      {action && <div className="mt-6">{action}</div>}254    </div>255  );256}257
Files main
Menu

Theme