White base with navy text, punch-red calls to action and blue UI states; placeholder logo mark and favicon; light theme pinned for the Vercel site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162 lines
8.8 KiB
TypeScript
162 lines
8.8 KiB
TypeScript
'use client';
|
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
import type { Course, Locale } from '@lms/data';
|
|
import { useApp } from './store';
|
|
import { tr } from './domain';
|
|
|
|
const PATHS: Record<string, string> = {
|
|
home: 'M3 11l9-7 9 7v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z',
|
|
grid: 'M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z',
|
|
book: 'M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2zM4 21V5M8 7h7',
|
|
help: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6V14M12 17.5v.01',
|
|
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0',
|
|
bell: 'M6 8a6 6 0 1 1 12 0c0 7 3 8 3 8H3s3-1 3-8M10 20a2 2 0 0 0 4 0',
|
|
search: 'M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4',
|
|
play: 'M7 4v16l13-8z',
|
|
pause: 'M7 4h4v16H7zM13 4h4v16h-4z',
|
|
lock: 'M6 11h12v10H6zM8 11V7a4 4 0 0 1 8 0v4',
|
|
check: 'M5 12l5 5 9-10',
|
|
chevron: 'M9 6l6 6-6 6',
|
|
back: 'M15 6l-6 6 6 6',
|
|
x: 'M6 6l12 12M18 6L6 18',
|
|
chart: 'M4 20V10M10 20V4M16 20v-7M22 20H2',
|
|
users: 'M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM2 21a7 7 0 0 1 14 0M16 3.5a4 4 0 0 1 0 7.5M22 21a7 7 0 0 0-4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5M4 20h16',
|
|
phone: 'M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2',
|
|
chat: 'M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z',
|
|
rewind: 'M11 19l-9-7 9-7zM22 19l-9-7 9-7z',
|
|
forward: 'M13 19l9-7-9-7zM2 19l9-7-9-7z',
|
|
expand: 'M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5',
|
|
comment: 'M4 4h16v12H8l-4 4z',
|
|
globe: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18',
|
|
clock: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2',
|
|
calendar: 'M4 6h16v14H4zM4 10h16M8 3v4M16 3v4',
|
|
share: 'M4 12v7a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-7M16 6l-4-4-4 4M12 2v13',
|
|
video: 'M3 6h12v12H3zM15 10l6-3v10l-6-3',
|
|
logout: 'M15 4h4a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-4M10 17l5-5-5-5M15 12H3',
|
|
sparkle: 'M12 3l2 6 6 2-6 2-2 6-2-6-6-2 6-2z',
|
|
brush: 'M14 4l6 6-8 8-6-6zM6 12l-3 7 7-3',
|
|
};
|
|
|
|
export function Icon({ name, size = 20, label }: { name: keyof typeof PATHS | string; size?: number; label?: string }) {
|
|
return (
|
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden={label ? undefined : true} role={label ? 'img' : undefined} aria-label={label}>
|
|
<path d={PATHS[name] ?? ''} />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
// Placeholder brand mark until the real logo arrives: navy tile, frosted-blue wave, punch-red dot.
|
|
export function Logo({ size = 34 }: { size?: number }) {
|
|
return (
|
|
<span className="logo" aria-hidden>
|
|
<svg width={size} height={size} viewBox="0 0 34 34">
|
|
<rect width="34" height="34" rx="10" fill="#1D3557" />
|
|
<path d="M7 22c3.5-6 7-6 10 0s6.5 6 10 0" fill="none" stroke="#A8DADC" strokeWidth="3" strokeLinecap="round" />
|
|
<circle cx="23.5" cy="11" r="3.5" fill="#E63946" />
|
|
</svg>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
const TONES = ['rose', 'clay', 'plum', 'sand', 'sage', 'ink'];
|
|
|
|
export function Cover({ course, locale, badge }: { course: Course; locale: Locale; badge?: ReactNode }) {
|
|
const { ds } = useApp();
|
|
// No image → the title itself, set in Ge'ez serif, is the cover (§11.2: the script is the visual identity).
|
|
// Shows the title in the other script from the page's language, so the cover adds a second language instead of repeating the card title.
|
|
const other = locale === 'am' || locale === 'ti' ? 'en' : 'am';
|
|
const title = course.translations[other]?.title ?? tr(course.translations, locale)?.title ?? '';
|
|
const tone = course.coverTone && TONES.includes(course.coverTone) ? course.coverTone : 'ink';
|
|
return (
|
|
<div className={`cover tone-${tone} ${course.coverAssetId ? 'has-img' : ''}`}>
|
|
{course.coverAssetId && <img src={ds.assetUrl(course.coverAssetId)} alt="" />}
|
|
{badge}
|
|
<span className="ttl" lang={other} aria-hidden>{title}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Empty({ children, action }: { children: ReactNode; action?: ReactNode }) {
|
|
return <div className="empty"><p>{children}</p>{action}</div>;
|
|
}
|
|
|
|
export function Skeleton({ h = 120, n = 1 }: { h?: number; n?: number }) {
|
|
return <div className="stack" aria-busy="true" aria-live="polite">{Array.from({ length: n }, (_, i) => <div key={i} className="skel" style={{ height: h }} />)}</div>;
|
|
}
|
|
|
|
export function Modal({ title, onClose, children }: { title: string; onClose(): void; children: ReactNode }) {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
useEffect(() => {
|
|
const k = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
|
addEventListener('keydown', k);
|
|
ref.current?.querySelector<HTMLElement>('input,select,textarea,button')?.focus();
|
|
return () => removeEventListener('keydown', k);
|
|
}, [onClose]);
|
|
return (
|
|
<div className="modal-back" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
|
<div className="modal" role="dialog" aria-modal="true" aria-label={title} ref={ref}>
|
|
<div className="row-between"><h2 style={{ fontSize: 'var(--fs-lg)' }}>{title}</h2><button className="icon-btn" onClick={onClose} aria-label="Close"><Icon name="x" /></button></div>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Ring({ pct, size = 56 }: { pct: number; size?: number }) {
|
|
const r = 24, c = 2 * Math.PI * r;
|
|
return (
|
|
<svg className="ring" width={size} height={size} viewBox="0 0 56 56" role="img" aria-label={`${pct}%`}>
|
|
<circle className="bg" cx="28" cy="28" r={r} />
|
|
<circle className="fg" cx="28" cy="28" r={r} strokeDasharray={c} strokeDashoffset={c * (1 - pct / 100)} />
|
|
<text x="28" y="32" textAnchor="middle" fontSize="13" fontWeight="700" fill="currentColor">{pct}%</text>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
const PILL_KIND: Record<string, string> = {
|
|
PAID: 'ok', ACTIVE: 'ok', PUBLISHED: 'ok', RESOLVED: 'ok', READY: 'ok', SENT: 'ok',
|
|
PENDING: 'warn', OPEN: 'warn', IN_PROGRESS: 'info', DRAFT: 'info', PROCESSING: 'info', UPLOADING: 'info', SCHEDULED: 'info',
|
|
FAILED: 'bad', EXPIRED: 'bad', DEACTIVATED: 'bad', CANCELLED: '', REFUNDED: 'info', ARCHIVED: '', CLOSED: '', NONE: '',
|
|
};
|
|
export function StatusPill({ status, label }: { status: string; label?: string }) {
|
|
const k = PILL_KIND[status];
|
|
return <span className={`pill ${k ? 'pill-' + k : ''}`}>{label ?? status.replace(/_/g, ' ').toLowerCase().replace(/^./, (c) => c.toUpperCase())}</span>;
|
|
}
|
|
|
|
/** "Leave feedback" — opens a Claude comment pinned to the current screen (§18.6). Hidden when comments are unavailable. */
|
|
export function FeedbackButton({ label, target }: { label: string; target: () => Element | null }) {
|
|
const { ds } = useApp();
|
|
const [ok, setOk] = useState(false);
|
|
useEffect(() => { ds.feedbackAvailable().then(setOk); }, [ds]);
|
|
if (!ok) return null;
|
|
return <button className="btn btn-ghost btn-sm feedback-btn" aria-label={label} title={label} onClick={() => { const el = target(); if (el) ds.feedback(el); }}><Icon name="comment" size={16} /><span className="lbl">{label}</span></button>;
|
|
}
|
|
|
|
export function CopyText({ text, copyLabel, copiedLabel }: { text: string; copyLabel: string; copiedLabel: string }) {
|
|
const [done, setDone] = useState(false);
|
|
return (
|
|
<button className="btn btn-ghost btn-sm" onClick={() => {
|
|
navigator.clipboard?.writeText(text).then(() => setDone(true), () => setDone(false));
|
|
}}>{done ? copiedLabel : copyLabel}</button>
|
|
);
|
|
}
|
|
|
|
// Gregorian, en-GB digits in every locale for the demo; Ethiopian calendar is P2 (§12).
|
|
export const fmtDate = (iso?: string | null) =>
|
|
iso ? new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }) : '—';
|
|
export const fmtDateTime = (iso?: string | null) =>
|
|
iso ? new Date(iso).toLocaleString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }) : '—';
|