SPB Git

Repository Public

TabBar.tsx 6.4 KB 244 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/components/nav/TabBar.tsx9 * Module           : components10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-2512 * Last Modified    : 2026-08-2513 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142"use client";43// Barre d'onglets mobile (le CSS global src/styles/tabbar.css est importé par layout.tsx).44import type { CSSProperties, ReactElement } from "react";45import Link from "next/link";4647export type TabIcon =48  | "compass" | "search" | "heart" | "user" | "map" | "pin" | "tag"49  | "home" | "grid" | "store" | "basket" | "target" | "trendup"50  | "receipt" | "book" | "chart" | "calendar";5152const ICONS: Record<TabIcon, ReactElement> = {53  compass: (54    <>55      <circle cx="12" cy="12" r="9" />56      <path d="m15.5 8.5-2.2 5-4.8 2 2.2-5 4.8-2z" />57    </>58  ),59  search: (60    <>61      <circle cx="11" cy="11" r="7" />62      <path d="m20.5 20.5-4.2-4.2" />63    </>64  ),65  heart: (66    <path d="M12 20.5S4.5 15.8 2.6 11.4A5.3 5.3 0 0 1 12 6.6a5.3 5.3 0 0 1 9.4 4.8C19.5 15.8 12 20.5 12 20.5z" />67  ),68  user: (69    <>70      <circle cx="12" cy="8.2" r="3.7" />71      <path d="M4.5 20.2a7.5 7.5 0 0 1 15 0" />72    </>73  ),74  map: (75    <>76      <path d="M9 4 3.5 6v14L9 18l6 2 5.5-2V4L15 6 9 4z" />77      <path d="M9 4v14M15 6v14" />78    </>79  ),80  pin: (81    <>82      <path d="M12 21s-7-5.6-7-11a7 7 0 0 1 14 0c0 5.4-7 11-7 11z" />83      <circle cx="12" cy="10" r="2.6" />84    </>85  ),86  tag: (87    <>88      <path d="M20.6 13.4 12 22 2 12V2h10l8.6 8.6a2 2 0 0 1 0 2.8z" />89      <circle cx="7" cy="7" r="1.6" />90    </>91  ),92  home: (93    <>94      <path d="m3.5 10.5 8.5-7 8.5 7" />95      <path d="M5.5 9v11h13V9" />96    </>97  ),98  grid: (99    <>100      <rect x="4" y="4" width="7" height="7" rx="1.5" />101      <rect x="13" y="4" width="7" height="7" rx="1.5" />102      <rect x="4" y="13" width="7" height="7" rx="1.5" />103      <rect x="13" y="13" width="7" height="7" rx="1.5" />104    </>105  ),106  store: (107    <>108      <path d="M4.5 9.5 6 4.5h12l1.5 5" />109      <path d="M5 9.5h14V20H5V9.5z" />110      <path d="M10 20v-5h4v5" />111    </>112  ),113  basket: (114    <>115      <path d="M4 9h16l-1.6 10a2 2 0 0 1-2 1.7H7.6a2 2 0 0 1-2-1.7L4 9z" />116      <path d="M8.5 9 12 3l3.5 6" />117    </>118  ),119  target: (120    <>121      <circle cx="12" cy="12" r="8.5" />122      <circle cx="12" cy="12" r="4.5" />123      <circle cx="12" cy="12" r="0.8" />124    </>125  ),126  trendup: (127    <>128      <path d="m3.5 16.5 5.5-5.5 3.5 3.5 7.5-7.5" />129      <path d="M14.5 7H20v5.5" />130    </>131  ),132  receipt: (133    <>134      <path d="M6 3.5h12V21l-2-1.4-2 1.4-2-1.4-2 1.4-2-1.4L6 21V3.5z" />135      <path d="M9 8h6M9 11.5h6M9 15h4" />136    </>137  ),138  book: (139    <>140      <path d="M12 6.5C10.5 5 8.5 4.5 5.5 4.5H3.5V19h2c3 0 5 .5 6.5 2 1.5-1.5 3.5-2 6.5-2h2V4.5h-2c-3 0-5 .5-6.5 2z" />141      <path d="M12 6.5V21" />142    </>143  ),144  chart: (145    <>146      <path d="M4 20h16" />147      <path d="M7.5 20v-6M12 20V9M16.5 20v-4" />148    </>149  ),150  calendar: (151    <>152      <rect x="3.5" y="5" width="17" height="15.5" rx="2" />153      <path d="M8 3v4M16 3v4M3.5 10h17" />154    </>155  ),156};157158export function TabIco({ name, size = 21 }: { name: TabIcon; size?: number }) {159  return (160    <svg161      width={size}162      height={size}163      viewBox="0 0 24 24"164      fill="none"165      stroke="currentColor"166      strokeWidth={1.7}167      strokeLinecap="round"168      strokeLinejoin="round"169      aria-hidden="true"170    >171      {ICONS[name]}172    </svg>173  );174}175176export type Tab = {177  label: string;178  icon: TabIcon;179  /** route interne (react-router Link) */180  to?: string;181  /** lien externe  */182  href?: string;183  /** action locale (ex. ouvrir la recherche) — rend un <button> */184  onPress?: () => void;185  /** complément d'un lien `to` (ex. focus d'un champ une fois arrivé) */186  onClick?: () => void;187  active?: boolean;188};189190export default function TabBar({191  tabs,192  theme = "light",193  accent,194  className,195}: {196  tabs: Tab[];197  theme?: "light" | "dark";198  /** couleur signature de la marque (défaut : var(--accent) du site) */199  accent?: string;200  className?: string;201}) {202  const cls =203    "vp-tabbar" +204    (theme === "dark" ? " vp-tabbar--dark" : "") +205    (className ? " " + className : "");206  const style = accent ? ({ "--tb-accent": accent } as CSSProperties) : undefined;207  return (208    <nav className={cls} style={style} aria-label="Navigation mobile">209      {tabs.map((t) => {210        const inner = (211          <>212            <TabIco name={t.icon} />213            {t.label}214          </>215        );216        const c = t.active ? "active" : "";217        if (t.to)218          return (219            <Link220              key={t.label}221              href={t.to}222              className={c}223              onClick={t.onClick}224              aria-current={t.active ? "page" : undefined}225            >226              {inner}227            </Link>228          );229        if (t.href)230          return (231            <a key={t.label} href={t.href} className={c} target="_blank" rel="noreferrer">232              {inner}233            </a>234          );235        return (236          <button key={t.label} type="button" className={c} onClick={t.onPress}>237            {inner}238          </button>239        );240      })}241    </nav>242  );243}244
Files main
Menu

Theme