SPB Git

Repository Public

common.tsx 21.5 KB 305 lines tsx

1// Shared UI primitives: icons, logo, dialog (focus trap), toasts, confirmation host, fields, secret rendering.2import { type ReactNode, useEffect, useId, useRef, useState } from "react";3import { confirmAction, copyText, dismissToast, errText, hueOf, isSecurity, useConfirmRequest, useToasts } from "../state.ts";45// ── icons (original, 24-px grid, stroke) ──────────────────────────────────────────────────────────────────────6const ICONS = {7  search: "M10.5 4a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM20 20l-4.6-4.6",8  plus: "M12 5v14M5 12h14",9  lock: "M7 11V8a5 5 0 0 1 10 0v3M6 11h12a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM12 15v2",10  star: "M12 3.5l2.6 5.4 5.9.8-4.3 4.1 1 5.9-5.2-2.8-5.2 2.8 1-5.9L3.5 9.7l5.9-.8z",11  key: "M7.5 12.5a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM10.3 13.7L20 4M16 8l2.5 2.5M18.5 5.5L21 8",12  login: "M15 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM3 20c1-3.5 4.3-5 8-5 1.2 0 2.3.15 3.3.5M17 16v5M14.5 18.5h5",13  passkey: "M9 4.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7zM2.5 20c.4-3.6 3-5.5 6.5-5.5 1.3 0 2.5.3 3.5.8M17.5 11a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5zM17.5 16v5.5M17.5 19h2",14  card: "M3 7a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2zM3 10h18M7 15h4",15  note: "M6 3h9l4 4v13a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zM14 3v5h5M8.500 12h7M8.500 16h5",16  doc: "M7 3h8l4 4v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zM9 9h2M9 13h6M9 17h6",17  code: "M8 8l-4 4 4 4M16 8l4 4-4 4M13.500 5l-3 14",18  clock: "M12 3.500a8.500 8.500 0 1 0 0 17 8.500 8.500 0 0 0 0-17zM12 7.500V12l3 2",19  shield: "M12 3l7 2.500V11c0 4.500-2.900 8.300-7 10-4.100-1.700-7-5.500-7-10V5.500zM9 12l2.200 2.200L15.500 10",20  device: "M5 5h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zM2.500 19.500h19M10 16v3.500M14 16v3.500",21  activity: "M3 12h4l2.500-7 4 14 2.500-7h5",22  bot: "M12 3v3M7 6h10a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2zM2.500 11v3M21.500 11v3M9.500 11v1.500M14.500 11v1.500M9.500 15h5",23  trash: "M4 7h16M9 7V4.500h6V7M6.500 7l.8 12a1 1 0 0 0 1 1h7.400a1 1 0 0 0 1-1l.8-12M10 11v5.500M14 11v5.500",24  gear: "M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM12 3v2.500M12 18.500V21M3 12h2.500M18.500 12H21M5.600 5.600l1.800 1.800M16.600 16.600l1.800 1.800M5.600 18.400l1.800-1.800M16.600 7.400l1.800-1.800",25  tag: "M3.500 4.500h7.500l9 9-7.500 7.500-9-9zM8 9a1 1 0 1 0 0 .010",26  vault: "M5 4h14a1.500 1.500 0 0 1 1.500 1.500v12A1.500 1.500 0 0 1 19 19H5a1.500 1.500 0 0 1-1.500-1.500v-12A1.500 1.500 0 0 1 5 4zM12 8.500a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM12 11.500v-3M7 19v2M17 19v2",27  share: "M12 15V3.500M8 7l4-3.500L16 7M5 12v7a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-7",28  copy: "M9 9h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1V10a1 1 0 0 1 1-1zM16 9V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3",29  eye: "M2.500 12S6 5.500 12 5.500 21.500 12 21.500 12 18 18.500 12 18.500 2.500 12 2.500 12zM12 9.500a2.500 2.500 0 1 0 0 5 2.500 2.500 0 0 0 0-5z",30  eyeOff: "M4 4l16 16M9.900 5.800A9 9 0 0 1 12 5.500c6 0 9.500 6.500 9.500 6.500a15 15 0 0 1-2.700 3.500M6.200 7.300A15 15 0 0 0 2.500 12S6 18.500 12 18.500a9 9 0 0 0 3.600-.8M10 10a2.800 2.800 0 0 0 4 4",31  edit: "M4 20h4L19.500 8.500l-4-4L4 16zM13.500 6.500l4 4",32  back: "M15 5l-7 7 7 7",33  menu: "M4 7h16M4 12h16M4 17h16",34  x: "M6 6l12 12M18 6L6 18",35  check: "M5 12.500l4.500 4.500L19 7.500",36  alert: "M12 3.500l9.500 16.500h-19zM12 10v4.500M12 17.500v.010",37  info: "M12 3.500a8.500 8.500 0 1 0 0 17 8.500 8.500 0 0 0 0-17zM12 11v5.500M12 7.800v.010",38  refresh: "M20 5v5h-5M4 19v-5h5M19.200 10A7.500 7.500 0 0 0 5.800 8M4.800 14a7.500 7.500 0 0 0 13.400 2",39  download: "M12 3.500V15M8 11.500l4 3.500 4-3.500M5 19.500h14",40  upload: "M12 15V3.500M8 7l4-3.500L16 7M5 19.500h14",41  link: "M10 14a4 4 0 0 0 5.700 0l3-3a4 4 0 0 0-5.700-5.700l-1 1M14 10a4 4 0 0 0-5.700 0l-3 3A4 4 0 0 0 11 18.700l1-1",42  chevron: "M9 6l6 6-6 6",43  external: "M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5",44  user: "M16 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM4 20.500c1-3.800 4.300-5.500 8-5.500s7 1.700 8 5.500",45  users: "M13 8a3.500 3.500 0 1 1-7 0 3.500 3.500 0 0 1 7 0zM2.500 20c.8-3.300 3.500-5 7-5s6.200 1.700 7 5M16 4.800a3.500 3.500 0 0 1 0 6.400M18.500 15.500c1.700.8 2.700 2.300 3 4.500",46  wifi: "M2.500 9.500a14 14 0 0 1 19 0M5.500 13a9.500 9.500 0 0 1 13 0M8.700 16.300a5 5 0 0 1 6.600 0M12 19.500v.010",47  grid: "M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z",48  dice: "M5 4h14a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zM8.500 8.500v.010M15.500 8.500v.010M12 12v.010M8.500 15.500v.010M15.500 15.500v.010",49  print: "M7 8V3.500h10V8M7 17H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1h-2M7 14h10v6.500H7z",50  restore: "M4 5v5h5M4.800 14a7.500 7.500 0 1 0 1-6.500L4 10",51  move: "M4 7h6l2 2.500h8V19a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1zM10 14.500h5M13 12.500l2 2-2 2",52  sort: "M7 5v14M4 16l3 3 3-3M17 19V5M14 8l3-3 3 3",53  power: "M12 3.500v8M7 6.500a7.500 7.500 0 1 0 10 0",54  qr: "M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h2.500v2.500H14zM17.500 17.500H20V20h-2.500zM14 19.500v.010M20 14v.010",55  inbox: "M4 13l2.500-8h11L20 13v6a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1zM4 13h4.500l1 2.500h5l1-2.500H20",56  id: "M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zM9 10a1.800 1.800 0 1 0 0 3.600A1.800 1.800 0 0 0 9 10zM6 16.500c.5-1.300 1.600-2 3-2s2.500.7 3 2M15 10h3.500M15 13.500h3.500",57  db: "M5 6.500C5 5 8.100 4 12 4s7 1 7 2.500S15.900 9 12 9 5 8 5 6.500zM5 6.500v11C5 19 8.100 20 12 20s7-1 7-2.500v-11M5 12c0 1.500 3.100 2.500 7 2.500s7-1 7-2.500",58  cert: "M6 3.500h12a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1h-3M9 15H6a1 1 0 0 1-1-1V4.500a1 1 0 0 1 1-1zM12 12a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM10.300 17.500V21l1.700-1 1.700 1v-3.500M8.500 7.500h7",59  terminal: "M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zM7 9.500l3 2.500-3 2.500M12.500 15H17",60  sun: "M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2.500v2M12 19.500v2M2.500 12h2M19.500 12h2M5.300 5.300l1.400 1.400M17.300 17.300l1.400 1.400M5.300 18.700l1.400-1.400M17.300 6.700l1.400-1.400",61  more: "M6 12v.010M12 12v.010M18 12v.010",62} as const;63export type IconName = keyof typeof ICONS;6465export function Icon({ name, size = 18, fill = false, className }: { name: IconName; size?: number; fill?: boolean; className?: string }) {66  return (67    <svg className={`icon${className ? " " + className : ""}`} viewBox="0 0 24 24" width={size} height={size} fill={fill ? "currentColor" : "none"} stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false">68      <path d={ICONS[name]} />69    </svg>70  );71}7273/** The SP Vault mark: a keyhole (circle over a narrow trapezoid) inside a rounded square. */74export function Logo({ size = 32 }: { size?: number }) {75  return (76    <svg className="logo" viewBox="0 0 64 64" width={size} height={size} role="img" aria-label="SP Vault">77      <rect className="logo-plate" x="4" y="4" width="56" height="56" rx="15" />78      <rect className="logo-ring" x="5.500" y="5.500" width="53" height="53" rx="13.500" fill="none" strokeWidth="3" />79      <circle className="logo-key" cx="32" cy="26" r="9" />80      <path className="logo-key" d="M28.500 30h7l3.500 17h-14z" />81    </svg>82  );83}84export function Brand({ size = 28 }: { size?: number }) {85  return <span className="brand"><Logo size={size} /><span className="brand-name">SP Vault</span></span>;86}8788// ── buttons ───────────────────────────────────────────────────────────────────────────────────────────────────89type BtnProps = { variant?: "primary" | "danger" | "ghost" | "default"; small?: boolean; busy?: boolean; icon?: IconName; children?: ReactNode } & React.ButtonHTMLAttributes<HTMLButtonElement>;90export function Btn({ variant = "default", small, busy, icon, children, className, disabled, type, ...rest }: BtnProps) {91  return (92    <button type={type ?? "button"} className={`btn ${variant}${small ? " small" : ""}${className ? " " + className : ""}`} disabled={disabled || busy} aria-busy={busy || undefined} {...rest}>93      {busy ? <span className="spinner" aria-hidden="true" /> : icon ? <Icon name={icon} size={small ? 15 : 17} /> : null}94      {children != null && <span>{children}</span>}95    </button>96  );97}98export function IconBtn({ icon, label, active, className, fill, ...rest }: { icon: IconName; label: string; active?: boolean; fill?: boolean } & React.ButtonHTMLAttributes<HTMLButtonElement>) {99  return <button type="button" className={`icon-btn${active ? " active" : ""}${className ? " " + className : ""}`} aria-label={label} title={label} {...rest}><Icon name={icon} fill={fill} /></button>;100}101102/** Runs an async action with a busy flag and an error message (rendered by the caller with <ErrorText/>). */103export function useAction(): { busy: boolean; error: string; run: <T>(fn: () => Promise<T>) => Promise<T | undefined>; setError: (s: string) => void } {104  const [busy, setBusy] = useState(false), [error, setError] = useState("");105  const alive = useRef(true);106  useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);107  const run = async <T,>(fn: () => Promise<T>): Promise<T | undefined> => {108    setBusy(true); setError("");109    try { return await fn(); }110    catch (e) { if (alive.current) setError(errText(e)); return undefined; }111    finally { if (alive.current) setBusy(false); }112  };113  return { busy, error, run, setError };114}115116/** Errors are always rendered as text. SECURITY: messages get the prominent, persistent style. */117export function ErrorText({ text }: { text: string }) {118  if (!text) return null;119  const sec = isSecurity(text);120  return (121    <div className={`callout ${sec ? "security" : "danger"}`} role="alert">122      <Icon name="alert" />123      <div>{sec && <strong className="callout-title">Security warning</strong>}<p>{sec ? text.replace(/^SECURITY:\s*/, "") : text}</p></div>124    </div>125  );126}127export function Callout({ kind = "info", title, children, icon }: { kind?: "info" | "warn" | "danger" | "security" | "ok"; title?: string; children: ReactNode; icon?: IconName }) {128  return (129    <div className={`callout ${kind}`} role={kind === "danger" || kind === "security" ? "alert" : "note"}>130      <Icon name={icon ?? (kind === "info" ? "info" : kind === "ok" ? "check" : "alert")} />131      <div>{title && <strong className="callout-title">{title}</strong>}{children}</div>132    </div>133  );134}135136// ── dialog with focus trap ────────────────────────────────────────────────────────────────────────────────────137const dialogStack: symbol[] = [];138const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';139export function Dialog({ title, onClose, children, wide, footer, danger }: { title: string; onClose: () => void; children: ReactNode; wide?: boolean; footer?: ReactNode; danger?: boolean }) {140  const ref = useRef<HTMLDivElement>(null), id = useId();141  const close = useRef(onClose); close.current = onClose;142  useEffect(() => {143    const prev = document.activeElement as HTMLElement | null, el = ref.current!, me = Symbol("dialog");144    dialogStack.push(me);145    const first = el.querySelector<HTMLElement>("[data-autofocus]") ?? el.querySelector<HTMLElement>(".dialog-body " + FOCUSABLE.split(",").join(",.dialog-body ")) ?? el.querySelector<HTMLElement>(FOCUSABLE);146    (first ?? el).focus();147    const onKey = (e: KeyboardEvent) => {148      if (dialogStack[dialogStack.length - 1] !== me) return; // only the topmost dialog reacts149      if (e.key === "Escape") { e.stopImmediatePropagation(); e.preventDefault(); close.current(); return; }150      if (e.key !== "Tab") return;151      const nodes = [...el.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((n) => n.offsetParent !== null);152      if (!nodes.length) { e.preventDefault(); return; }153      const a = nodes[0]!, z = nodes[nodes.length - 1]!;154      if (e.shiftKey && (document.activeElement === a || !el.contains(document.activeElement))) { e.preventDefault(); z.focus(); }155      else if (!e.shiftKey && (document.activeElement === z || !el.contains(document.activeElement))) { e.preventDefault(); a.focus(); }156    };157    document.addEventListener("keydown", onKey, true);158    return () => { document.removeEventListener("keydown", onKey, true); const i = dialogStack.indexOf(me); if (i >= 0) dialogStack.splice(i, 1); if (prev?.isConnected) prev.focus(); };159  }, []);160  return (161    <div className="dialog-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }}>162      <div ref={ref} className={`dialog${wide ? " wide" : ""}${danger ? " danger" : ""}`} role="dialog" aria-modal="true" aria-labelledby={id} tabIndex={-1}>163        <header className="dialog-head"><h2 id={id}>{title}</h2><IconBtn icon="x" label="Close" onClick={onClose} /></header>164        <div className="dialog-body">{children}</div>165        {footer && <footer className="dialog-foot">{footer}</footer>}166      </div>167    </div>168  );169}170171export function ConfirmHost() {172  const req = useConfirmRequest();173  const [typed, setTyped] = useState("");174  useEffect(() => setTyped(""), [req]);175  if (!req) return null;176  const lines = Array.isArray(req.body) ? req.body : [req.body];177  const ready = !req.typeToConfirm || typed.trim() === req.typeToConfirm;178  return (179    <Dialog title={req.title} onClose={() => req.resolve(false)} danger={req.danger}180      footer={<><Btn onClick={() => req.resolve(false)}>Cancel</Btn><Btn variant={req.danger ? "danger" : "primary"} disabled={!ready} onClick={() => req.resolve(true)} data-testid="confirm-ok">{req.confirmLabel}</Btn></>}>181      <div className="stack">182        {lines.map((l, i) => <p key={i}>{l}</p>)}183        {req.typeToConfirm && <Field label={`Type ${req.typeToConfirm} to confirm`}><input className="input mono" value={typed} onChange={(e) => setTyped(e.target.value)} autoComplete="off" spellCheck={false} data-autofocus data-testid="confirm-type" /></Field>}184      </div>185    </Dialog>186  );187}188export { confirmAction };189190export function ToastHost() {191  const list = useToasts();192  return (193    <div className="toasts" role="status" aria-live="polite" aria-atomic="false">194      {list.map((t) => (195        <div key={t.id} className={`toast ${t.kind}${isSecurity(t.text) ? " security" : ""}`} data-testid="toast">196          <Icon name={t.kind === "ok" ? "check" : t.kind === "danger" ? "alert" : "info"} size={16} />197          <span>{t.text}</span>198          <button type="button" className="toast-x" aria-label="Dismiss" onClick={() => dismissToast(t.id)}><Icon name="x" size={14} /></button>199        </div>200      ))}201    </div>202  );203}204205// ── form fields ───────────────────────────────────────────────────────────────────────────────────────────────206export function Field({ label, hint, error, children, className }: { label: ReactNode; hint?: ReactNode; error?: string; children: ReactNode; className?: string }) {207  return (208    <label className={`field${className ? " " + className : ""}`}>209      <span className="field-label">{label}</span>210      {children}211      {error ? <span className="field-error" role="alert">{error}</span> : hint ? <span className="field-hint">{hint}</span> : null}212    </label>213  );214}215export function Segmented<T extends string>({ value, options, onChange, label }: { value: T; options: { value: T; label: string }[]; onChange: (v: T) => void; label: string }) {216  return (217    <div className="segmented" role="radiogroup" aria-label={label}>218      {options.map((o) => <button key={o.value} type="button" role="radio" aria-checked={o.value === value} className={o.value === value ? "on" : ""} onClick={() => onChange(o.value)}>{o.label}</button>)}219    </div>220  );221}222export function Toggle({ checked, onChange, label }: { checked: boolean; onChange: (v: boolean) => void; label: string }) {223  return <label className="toggle"><input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked)} /><span className="toggle-track" aria-hidden="true" /><span>{label}</span></label>;224}225226// ── secrets ───────────────────────────────────────────────────────────────────────────────────────────────────227export const MASK = "••••••••••••";228/** Revealed secret with distinct colouring for digits and symbols (also distinguishable by weight, not colour alone). */229export function SecretText({ value }: { value: string }) {230  if (value.length > 600) return <span className="secret-text">{value}</span>;231  return (232    <span className="secret-text">233      {[...value].map((c, i) => <span key={i} className={/\d/.test(c) ? "c-d" : /[\p{L}\s]/u.test(c) ? "c-l" : "c-s"}>{c}</span>)}234    </span>235  );236}237/** Read-only secret row: masked by default (the value is not in the DOM until revealed), explicit Reveal and Copy. */238export function SecretValue({ value, label, multiline }: { value: string; label: string; multiline?: boolean }) {239  const [shown, setShown] = useState(false);240  useEffect(() => { if (!shown) return; const t = setTimeout(() => setShown(false), 60_000); return () => clearTimeout(t); }, [shown]);241  return (242    <div className="value-row">243      <div className={`value mono${multiline ? " multiline" : ""}`} data-testid={`secret-${label}`} data-masked={!shown}>244        {shown ? <SecretText value={value} /> : <span className="mask" aria-label={`${label} hidden`}>{MASK}</span>}245      </div>246      <div className="value-actions">247        <IconBtn icon={shown ? "eyeOff" : "eye"} label={shown ? `Hide ${label}` : `Reveal ${label}`} aria-pressed={shown} onClick={() => setShown(!shown)} />248        <IconBtn icon="copy" label={`Copy ${label}`} onClick={() => copyText(value, label)} />249      </div>250    </div>251  );252}253export function CopyValue({ value, label, mono, multiline, children }: { value: string; label: string; mono?: boolean; multiline?: boolean; children?: ReactNode }) {254  return (255    <div className="value-row">256      <div className={`value${mono ? " mono" : ""}${multiline ? " multiline" : ""}`}>{children ?? value}</div>257      <div className="value-actions"><IconBtn icon="copy" label={`Copy ${label}`} onClick={() => copyText(value, label, false)} /></div>258    </div>259  );260}261262// ── misc ──────────────────────────────────────────────────────────────────────────────────────────────────────263export function Monogram({ title, icon, size = 36 }: { title: string; icon?: IconName; size?: number }) {264  const letter = [...(title.trim() || "?")][0]!.toUpperCase();265  return <span className="monogram" style={{ "--hue": hueOf(title), "--size": `${size}px` } as React.CSSProperties} aria-hidden="true">{icon ? <Icon name={icon} size={Math.round(size * 0.5)} /> : letter}</span>;266}267export function Badge({ kind = "neutral", children, icon }: { kind?: "neutral" | "accent" | "brass" | "danger" | "ok"; children: ReactNode; icon?: IconName }) {268  return <span className={`badge ${kind}`}>{icon && <Icon name={icon} size={12} />}{children}</span>;269}270export function Empty({ icon, title, children, action }: { icon: IconName; title: string; children?: ReactNode; action?: ReactNode }) {271  return (272    <div className="empty">273      <span className="empty-mark"><Icon name={icon} size={30} /></span>274      <h3>{title}</h3>275      {children && <p>{children}</p>}276      {action}277    </div>278  );279}280export function Skeleton({ rows = 4 }: { rows?: number }) {281  return <div className="skeleton-list" aria-busy="true" aria-label="Loading">{Array.from({ length: rows }, (_, i) => <div key={i} className="skeleton-row"><span className="skeleton sk-avatar" /><span className="sk-lines"><span className="skeleton sk-a" /><span className="skeleton sk-b" /></span></div>)}</div>;282}283export function PageHead({ title, sub, actions, onBack }: { title: string; sub?: ReactNode; actions?: ReactNode; onBack?: () => void }) {284  return (285    <header className="page-head">286      {onBack && <IconBtn icon="back" label="Back" className="only-mobile" onClick={onBack} />}287      <div className="page-head-text"><h1>{title}</h1>{sub && <p>{sub}</p>}</div>288      {actions && <div className="page-head-actions">{actions}</div>}289    </header>290  );291}292export function Section({ title, children, actions, danger }: { title: string; children: ReactNode; actions?: ReactNode; danger?: boolean }) {293  return (294    <section className={`section${danger ? " danger-zone" : ""}`}>295      <div className="section-head"><h2>{title}</h2>{actions}</div>296      {children}297    </section>298  );299}300/** Groups of the form 1234 5678 → spans for a fingerprint. */301export function Fingerprint({ value, big }: { value: string; big?: boolean }) {302  return <span className={`fingerprint mono${big ? " big" : ""}`}>{value.split(" ").map((g, i) => <span key={i}>{g}</span>)}</span>;303}304export const EXPIRY_OPTIONS = [{ value: 3600, label: "1 hour" }, { value: 86400, label: "1 day" }, { value: 7 * 86400, label: "7 days" }, { value: 30 * 86400, label: "30 days" }];305
Files main
Menu

Theme