Farben, Schrift, Logo und Symbole folgen jetzt dem CD Manual 2022. An der Logik aendert sich nichts: keine Migration, keine Abfrage, keine Berechtigung. Die zwei Markenfarben stehen in §1.1 als #F69686 (Rosa) und #164194 (Blau). Welche davon was traegt, ist nicht gewaehlt, sondern nachgerechnet: Weiss auf Rosa kommt auf 2.18:1 und faellt damit auch fuer Grossschrift durch, Blau auf Rosa auf 4.34:1 und reicht fuer das Logo, nicht fuer Text. Schwarz auf Rosa sind 7.47:1, Weiss auf Blau 9.47:1. Rosa ist deshalb Flaeche, Blau ist Interaktion — zwei Skalen, brand-* und accent-*, statt einer geteilten. Von den 26 Stellen mit brand-50/100/200 sind nur sieben auf accent gewandert. Der Rest meint einen Zustand und keinen Markenton: die Zeile unter dem Zeiger, der gewaehlte Listeneintrag, der aktive Menuepunkt. Gegen die warme Seitenflaeche ist ein kuehler Ton dort deutlicher, und Blau heisst in dieser Oberflaeche ab jetzt "reagiert auf dich". Nach accent gingen die Faelle ohne eigene Bedeutung — "Geplant", "Offen", der neutrale Protokoll-Chip — und die offene Planstelle im Organigramm, die vorher ein blasses Blau war und damit wie eine schwaechere Person aussah. Die Funktionsfarben bleiben, was sie sind. Das Manual regelt die Identitaet, nicht die Rueckmeldung: Rot heisst Fehler, weil die Benutzerin das mitbringt. `info` bleibt bewusst tuerkis — Blau saehe ab jetzt bedienbar aus, und gemessen kaeme ein blaues info dem violetten Chip auf dE 6.8 nahe, also nicht unterscheidbar. Violett ist dabei nachgezogen: gegen den Fehler-Chip stand es bei dE 8.0, "Austritt" und "Befoerderung" waren im Vorbeigehen dieselbe blasse Flaeche. Jetzt dE 15.0. Die Schrift ist Barlow. Nachgezaehlt ist das Manual zu 95 % in DIN gesetzt (Regular 79 %, Bold 16 %); Helvetica Neue steht nur in den Visitenkarten und im Claim. DIN laesst sich nicht ausliefern — eine Drucklizenz deckt keinen Webfont —, und die freien Nachbauten der DIN 1451 sind Schilderschriften, bei 14 px in einer langen Tabelle schlechter lesbar als das, was sie ersetzen. Die Variable heisst --font-din und nicht --font-barlow: liegt eines Tages eine Web-Lizenz vor, ist der Wechsel diese eine Deklaration. Nebenbei zwei Dinge repariert, die vorher schon falsch waren. Die Umrandung von Eingabefeldern, Knoepfen und Suchfeldern lag bei 1.30:1 und damit unter den 3:1, die WCAG 1.4.11 fuer Bedienelemente verlangt; border-strong bringt 3.56:1. Und das mitgelieferte favicon.ico liess sich gar nicht bauen: eingebettet waren 24-Bit-RGB-PNG, waehrend der Kopf 32 bpp behauptete. Alle Rastersymbole liegen jetzt als RGBA vor, und ihr Blau ist auf den CD-Wert gezogen — samt der kantengeglaetteten Raender, indem je Pixel der Blauanteil bestimmt und neu gemischt wurde. Das Logo ist das Markenlogo (§4.1), nicht das Unternehmenslogo, das §3.2 fuer eine Anwendung mit der AG als Absender vorsaehe — es liegt nicht vor. Der Freiraum X/3 steckt im Bauteil selbst und nicht in den Aufrufstellen, sonst haengt seine Einhaltung daran, dass jede einzelne daran denkt. docs/farbschema.html zeigt Token, Kontraste und Bauteile nebeneinander und laesst sich ohne Server oeffnen. Nicht im Browser gesehen: Anmeldung laeuft ueber das Firmenkonto und die Datenbank ist von hier nicht erreichbar. Lint, Typen, Schemaabgleich, 524 Tests und der Build sind sauber. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
190 lines
6.8 KiB
TypeScript
190 lines
6.8 KiB
TypeScript
"use client";
|
|
|
|
import { Search, X } from "lucide-react";
|
|
import { useEffect, useId, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
|
|
|
type LookupProps<T> = {
|
|
placeholder?: string;
|
|
onSearch: (query: string) => Promise<T[]>;
|
|
renderResult: (item: T) => ReactNode;
|
|
onSelect: (item: T) => void;
|
|
minChars?: number;
|
|
id?: string;
|
|
"aria-describedby"?: string;
|
|
"aria-invalid"?: true;
|
|
};
|
|
|
|
// Generic async search-select used by the position lookup (hire wizard),
|
|
// manager/superior lookup (create position), and the reorg workbench.
|
|
//
|
|
// Implements the combobox contract rather than just looking like one: it was
|
|
// a plain text input with a div of clickable buttons underneath, so a
|
|
// keyboard user could type but never reach a result, and a screen reader was
|
|
// never told a list had appeared. Arrow keys move the selection, Enter takes
|
|
// it, Escape closes without also closing the surrounding dialog.
|
|
export function Lookup<T>({
|
|
placeholder = "Suchen…",
|
|
onSearch,
|
|
renderResult,
|
|
onSelect,
|
|
minChars = 2,
|
|
id: idProp,
|
|
"aria-describedby": describedBy,
|
|
"aria-invalid": invalid,
|
|
}: LookupProps<T>) {
|
|
const generatedId = useId();
|
|
const id = idProp ?? generatedId;
|
|
const [query, setQuery] = useState("");
|
|
const [results, setResults] = useState<T[]>([]);
|
|
const [open, setOpen] = useState(false);
|
|
const [activeIndex, setActiveIndex] = useState(0);
|
|
// Derived from "have we finished searching for the current query yet",
|
|
// rather than a separate state flag flipped synchronously at the top of
|
|
// the effect below — the effect only ever sets state from the async
|
|
// search's own completion callback now.
|
|
const [lastSearchedQuery, setLastSearchedQuery] = useState<string | null>(null);
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
const listRef = useRef<HTMLDivElement>(null);
|
|
|
|
const tooShort = query.trim().length < minChars;
|
|
const loading = !tooShort && lastSearchedQuery !== query.trim();
|
|
|
|
useEffect(() => {
|
|
if (tooShort) return;
|
|
let cancelled = false;
|
|
const timeout = setTimeout(() => {
|
|
onSearch(query.trim()).then((res) => {
|
|
if (cancelled) return;
|
|
setResults(res);
|
|
setActiveIndex(0);
|
|
setOpen(true);
|
|
setLastSearchedQuery(query.trim());
|
|
});
|
|
}, 200);
|
|
return () => {
|
|
cancelled = true;
|
|
clearTimeout(timeout);
|
|
};
|
|
}, [query, minChars, onSearch, tooShort]);
|
|
|
|
// Derived rather than reset via effect: once the query drops below
|
|
// minChars, hide the dropdown and any stale results immediately without
|
|
// needing a synchronous setState inside the effect above.
|
|
const showDropdown = open && !tooShort;
|
|
const visibleResults = tooShort ? [] : results;
|
|
const selectable = loading ? [] : visibleResults;
|
|
|
|
useEffect(() => {
|
|
function onClickOutside(e: MouseEvent) {
|
|
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
|
|
setOpen(false);
|
|
}
|
|
}
|
|
document.addEventListener("mousedown", onClickOutside);
|
|
return () => document.removeEventListener("mousedown", onClickOutside);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!showDropdown) return;
|
|
listRef.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
|
|
}, [activeIndex, showDropdown]);
|
|
|
|
function reset() {
|
|
setQuery("");
|
|
setResults([]);
|
|
setOpen(false);
|
|
setActiveIndex(0);
|
|
}
|
|
|
|
function choose(item: T) {
|
|
onSelect(item);
|
|
reset();
|
|
}
|
|
|
|
function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
|
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
if (selectable.length === 0) return;
|
|
e.preventDefault();
|
|
const delta = e.key === "ArrowDown" ? 1 : -1;
|
|
setActiveIndex((i) => (i + delta + selectable.length) % selectable.length);
|
|
} else if (e.key === "Enter") {
|
|
if (showDropdown && selectable[activeIndex]) {
|
|
e.preventDefault();
|
|
choose(selectable[activeIndex]);
|
|
}
|
|
} else if (e.key === "Escape") {
|
|
if (showDropdown) {
|
|
// Without this the Escape also reaches Modal/SlideOver and closes
|
|
// the whole dialog behind the dropdown.
|
|
e.stopPropagation();
|
|
setOpen(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
const listId = `${id}-listbox`;
|
|
|
|
return (
|
|
<div ref={containerRef} className="relative">
|
|
<div className="flex items-center gap-2 rounded border border-border-strong bg-white px-3 py-2 focus-within:outline-2 focus-within:outline-offset-1 focus-within:outline-brand-500">
|
|
<Search className="h-4 w-4 shrink-0 text-ink-muted" aria-hidden />
|
|
<input
|
|
id={id}
|
|
role="combobox"
|
|
aria-expanded={showDropdown}
|
|
aria-controls={listId}
|
|
aria-activedescendant={showDropdown && selectable[activeIndex] ? `${id}-option-${activeIndex}` : undefined}
|
|
aria-autocomplete="list"
|
|
aria-describedby={describedBy}
|
|
aria-invalid={invalid}
|
|
autoComplete="off"
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
onKeyDown={onKeyDown}
|
|
placeholder={placeholder}
|
|
className="w-full text-sm outline-none placeholder:text-ink-muted"
|
|
/>
|
|
{query && (
|
|
<button type="button" onClick={reset} aria-label="Zurücksetzen" className="rounded p-0.5 hover:bg-surface">
|
|
<X className="h-4 w-4 text-ink-muted" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
{/* Announces "Suche…" / result count without stealing focus. */}
|
|
<span aria-live="polite" className="sr-only">
|
|
{showDropdown ? (loading ? "Suche läuft" : `${visibleResults.length} Treffer`) : ""}
|
|
</span>
|
|
{showDropdown && (
|
|
<div
|
|
ref={listRef}
|
|
id={listId}
|
|
role="listbox"
|
|
className="absolute z-20 mt-1 max-h-64 w-full overflow-y-auto rounded border border-border bg-white shadow-[var(--shadow-card-hover)]"
|
|
>
|
|
{loading && <div className="px-3 py-2 text-sm text-ink-muted">Suche…</div>}
|
|
{!loading && visibleResults.length === 0 && <div className="px-3 py-2 text-sm text-ink-muted">Keine Treffer</div>}
|
|
{!loading &&
|
|
visibleResults.map((item, i) => (
|
|
<button
|
|
key={i}
|
|
id={`${id}-option-${i}`}
|
|
role="option"
|
|
aria-selected={i === activeIndex}
|
|
data-active={i === activeIndex}
|
|
type="button"
|
|
// Mouse down would blur the input and close the list before
|
|
// the click landed.
|
|
onMouseDown={(e) => e.preventDefault()}
|
|
onMouseEnter={() => setActiveIndex(i)}
|
|
onClick={() => choose(item)}
|
|
className={`block w-full px-3 py-2 text-left text-sm ${i === activeIndex ? "bg-brand-100" : "hover:bg-surface"}`}
|
|
>
|
|
{renderResult(item)}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|