Repository Public
1import type { ReactNode } from "react";2import { Icon, type IconName } from "./Icon";3import { LEVEL_LABEL, LEVEL_RANK, accessLabel } from "@/lib/labels";4import type { SessionView } from "@/modules/content-schema";56/** Level shown as text and as one to three dots: never by colour alone. */7export function Level({ level, compact = false }: { level: SessionView["level"]; compact?: boolean }) {8 const rank = LEVEL_RANK[level];9 return (10 <span className="inline-flex items-center gap-1.5 text-sm text-muted">11 <span aria-hidden="true" className="inline-flex gap-[3px]">12 {[1, 2, 3].map((i) => <span key={i} className={`size-1.5 rounded-full ${i <= rank ? "bg-fg" : "bg-line-strong/50"}`} />)}13 </span>14 {compact ? <span className="sr-only">Niveau {LEVEL_LABEL[level].toLowerCase()}</span> : <span>{LEVEL_LABEL[level]}</span>}15 </span>16 );17}1819export function StateBadge({ session }: { session: Pick<SessionView, "access" | "previewOnly"> & { slidesOnly?: boolean; lessonOnly?: boolean } }) {20 const label = accessLabel(session);21 const tone = session.access === "open" ? (session.previewOnly ? "chip-violet" : session.slidesOnly || session.lessonOnly ? "chip-blue" : "chip-teal") : session.access === "archived" ? "" : "chip-amber";22 const icon: IconName = session.access === "open" ? (session.previewOnly ? "layers" : "check") : "clock";23 return <span className={`chip ${tone}`} data-state={session.access}><Icon name={icon} size={13} />{label}</span>;24}2526export function PreviewChip({ children = "Aperçu — contenu non publié" }: { children?: ReactNode }) {27 return <span className="chip chip-violet"><span aria-hidden="true">◆</span>{children}</span>;28}2930export function PageHeader({ eyebrow, title, lede, children }: { eyebrow: string; title: string; lede?: ReactNode; children?: ReactNode }) {31 return (32 <header className="grid-paper border-b border-line">33 <div className="shell py-14 md:py-20">34 <p className="eyebrow">{eyebrow}</p>35 <h1 className="h-page mt-4 max-w-4xl">{title}</h1>36 {lede && <p className="lede mt-5 max-w-2xl">{lede}</p>}37 {children && <div className="mt-7">{children}</div>}38 </div>39 </header>40 );41}4243/** An honest « nothing here yet » block: says why, and where to go instead. Never a disabled fake control. */44export function EmptyState({ icon = "clock", title, children, action }: { icon?: IconName; title: string; children: ReactNode; action?: ReactNode }) {45 return (46 <div className="card grid-paper flex flex-col items-start gap-4 p-7 md:p-10" data-testid="empty-state">47 <span className="grid size-12 place-items-center rounded-full bg-amber-soft text-amber"><Icon name={icon} size={24} /></span>48 <h2 className="text-2xl">{title}</h2>49 <div className="max-w-2xl space-y-3 text-muted">{children}</div>50 {action}51 </div>52 );53}5455export function Section({ id, eyebrow, title, intro, children, className = "" }: { id?: string; eyebrow?: string; title: string; intro?: ReactNode; children: ReactNode; className?: string }) {56 return (57 <section id={id} aria-labelledby={id ? `${id}-titre` : undefined} className={`shell py-14 md:py-20 ${className}`}>58 {eyebrow && <p className="eyebrow">{eyebrow}</p>}59 <h2 id={id ? `${id}-titre` : undefined} className="h-section mt-3 max-w-3xl">{title}</h2>60 {intro && <div className="lede mt-4 max-w-2xl !text-[1.08rem]">{intro}</div>}61 <div className="mt-9">{children}</div>62 </section>63 );64}6566export function Callout({ tone = "blue", title, children }: { tone?: "blue" | "amber" | "teal" | "coral" | "violet"; title?: string; children: ReactNode }) {67 const c = { blue: "border-blue bg-blue-soft", amber: "border-amber bg-amber-soft", teal: "border-teal bg-teal-soft", coral: "border-coral bg-coral-soft", violet: "border-violet bg-violet-soft" }[tone];68 return (69 <div className={`rounded-2xl border-l-4 p-4 md:p-5 ${c}`}>70 {title && <p className="font-semibold">{title}</p>}71 <div className={`space-y-2 text-[0.97rem] ${title ? "mt-1" : ""}`}>{children}</div>72 </div>73 );74}75