[244] 3D-Darstellungsarten: Dropdown mit Gruppen, Icons und Kurzerklärung
Gemeinsames Dropdown rückwärtskompatibel um group/icon/hint/shortcut erweitert; 3D-Menü in Linien, Flächen, Rendern gegliedert (de + en). 2D-Plan unverändert.
This commit is contained in:
7 files changed
+237
-43
No files matched your search
@@ -0,0 +1,55 @@
|
||||
// [244] Dropdown: Gruppen, Icons, Zweitzeile, Kürzel; ohne diese Felder unverändert. Darstellungsarten im 3D gruppiert.
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DropdownRows, optionRows } from "./Dropdown";
|
||||
import { renderModeOptions } from "./TopBar";
|
||||
import { t } from "../i18n";
|
||||
|
||||
const html = (rows: ReturnType<typeof optionRows>) =>
|
||||
renderToStaticMarkup(createElement(DropdownRows, { rows, activeIdx: -1, onHover: () => {}, onSelect: () => {} }));
|
||||
|
||||
describe("Dropdown [244]", () => {
|
||||
it("ohne Gruppen: keine Überschrift, kein Icon, kein Trenner (rückwärtskompatibel)", () => {
|
||||
const rows = optionRows([{ value: "a", label: "A" }, { value: "b", label: "B" }], "b");
|
||||
expect(rows).toHaveLength(2);
|
||||
const h = html(rows);
|
||||
expect(h).not.toContain("tb-dd-heading");
|
||||
expect(h).not.toContain("tb-dd-icon");
|
||||
expect(h).not.toContain("separator");
|
||||
expect(h).toContain('aria-selected="true"');
|
||||
});
|
||||
|
||||
it("Gruppen: Überschrift je Gruppe, Trenner nur dazwischen", () => {
|
||||
const rows = optionRows([
|
||||
{ value: "a", label: "A", group: "G1" }, { value: "b", label: "B", group: "G1" }, { value: "c", label: "C", group: "G2" },
|
||||
]);
|
||||
expect(rows.filter((r) => r.divider)).toHaveLength(1);
|
||||
expect(rows.filter((r) => r.heading !== undefined).map((r) => r.heading)).toEqual(["G1", "G2"]);
|
||||
const h = html(rows);
|
||||
expect(h.match(/role="separator"/g)).toHaveLength(1);
|
||||
expect(h).toContain(">G1<");
|
||||
});
|
||||
|
||||
it("Icon, Zweitzeile, Tooltip, Kürzel und Häkchen", () => {
|
||||
const h = html(optionRows([{ value: "a", label: "A", icon: "view_in_ar", hint: "Erklärung", shortcut: "W" }], "a"));
|
||||
expect(h).toContain("material-symbols-outlined tb-dd-icon");
|
||||
expect(h).toContain(">view_in_ar<");
|
||||
expect(h).toContain('class="tb-dd-hint">Erklärung<');
|
||||
expect(h).toContain('title="Erklärung"');
|
||||
expect(h).toContain(">W</kbd>");
|
||||
expect(h).toContain("tb-dd-check");
|
||||
});
|
||||
|
||||
it("3D-Darstellungsarten: alle acht, drei Gruppen, Pathtracing erklärt", () => {
|
||||
const opts = renderModeOptions();
|
||||
expect(opts.map((o) => o.value).sort()).toEqual(
|
||||
["contour", "hidden", "pathtrace", "shaded", "shaded-edges", "textured", "white", "wireframe"],
|
||||
);
|
||||
expect(new Set(opts.map((o) => o.group)).size).toBe(3);
|
||||
expect(opts.every((o) => o.icon && o.hint)).toBe(true);
|
||||
const h = html(optionRows(opts, "pathtrace"));
|
||||
expect(h).toContain(t("display.style.pathtrace.tip"));
|
||||
expect(h).toContain(t("display.group.lines"));
|
||||
});
|
||||
});
|
||||
+100
-32
@@ -26,6 +26,14 @@ export interface DropdownOption {
|
||||
label: string;
|
||||
/** Ausgegraut, nicht wählbar. */
|
||||
disabled?: boolean;
|
||||
/** [244] Material-Symbols-Name (z. B. "view_in_ar") vor dem Label. */
|
||||
icon?: string;
|
||||
/** [244] Zweitzeile (kurze Erklärung); zugleich Tooltip der Zeile. */
|
||||
hint?: string;
|
||||
/** [244] Kürzel, rechts als Taste angezeigt. */
|
||||
shortcut?: string;
|
||||
/** [244] Gruppentitel: aufeinanderfolgende Optionen mit gleicher Gruppe stehen unter einer Überschrift mit Trennlinie. */
|
||||
group?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +54,93 @@ export interface DropdownItem {
|
||||
active?: boolean;
|
||||
/** Reiner Trenner (1px Linie); ignoriert alle anderen Felder. */
|
||||
divider?: boolean;
|
||||
/** [244] Gruppenüberschrift (nicht wählbar). */
|
||||
heading?: string;
|
||||
/** [244] Material-Symbols-Name vor dem Label. */
|
||||
icon?: string;
|
||||
/** [244] Zweitzeile + Tooltip. */
|
||||
hint?: string;
|
||||
/** [244] Kürzel rechts. */
|
||||
shortcut?: string;
|
||||
}
|
||||
|
||||
/** Nicht wählbare Zeile (Trenner, Überschrift). */
|
||||
const isInert = (r: DropdownItem) => !!r.divider || r.heading !== undefined;
|
||||
|
||||
/** Zeilenliste aus Optionen; bei `group` mit Überschrift und Trennlinie dazwischen ([244]). */
|
||||
export function optionRows(options: DropdownOption[], value?: string, onChange?: (v: string) => void): DropdownItem[] {
|
||||
const rows: DropdownItem[] = [];
|
||||
let group: string | undefined;
|
||||
for (const o of options) {
|
||||
if (o.group !== undefined && o.group !== group) {
|
||||
if (rows.length > 0) rows.push({ divider: true });
|
||||
rows.push({ heading: o.group });
|
||||
}
|
||||
group = o.group;
|
||||
rows.push({
|
||||
label: o.label,
|
||||
disabled: o.disabled,
|
||||
active: o.value === value,
|
||||
icon: o.icon,
|
||||
hint: o.hint,
|
||||
shortcut: o.shortcut,
|
||||
onSelect: () => onChange?.(o.value),
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Die Zeilen des Popovers (rein darstellend, damit testbar). */
|
||||
export function DropdownRows({
|
||||
rows,
|
||||
activeIdx,
|
||||
onHover,
|
||||
onSelect,
|
||||
}: {
|
||||
rows: DropdownItem[];
|
||||
activeIdx: number;
|
||||
onHover: (i: number) => void;
|
||||
onSelect: (row: DropdownItem) => void;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{rows.map((row, i) =>
|
||||
row.divider ? (
|
||||
<div key={`div-${i}`} className="ctx-divider" role="separator" />
|
||||
) : row.heading !== undefined ? (
|
||||
<div key={`head-${i}`} className="tb-dd-heading" role="presentation">
|
||||
{row.heading}
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
key={`row-${i}`}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={!!row.active}
|
||||
title={row.hint}
|
||||
className={`ctx-item tb-dd-item${row.danger ? " danger" : ""}${row.hint ? " has-hint" : ""}${
|
||||
i === activeIdx ? " is-active" : ""
|
||||
}`}
|
||||
disabled={row.disabled}
|
||||
onMouseEnter={() => !row.disabled && onHover(i)}
|
||||
onClick={() => onSelect(row)}
|
||||
>
|
||||
<span className="tb-dd-check-slot">{row.active && <Check />}</span>
|
||||
{row.icon && (
|
||||
<span className="material-symbols-outlined tb-dd-icon" aria-hidden="true">
|
||||
{row.icon}
|
||||
</span>
|
||||
)}
|
||||
<span className="tb-dd-text">
|
||||
<span className="ctx-item-label">{row.label}</span>
|
||||
{row.hint && <span className="tb-dd-hint">{row.hint}</span>}
|
||||
</span>
|
||||
{row.shortcut && <kbd className="tb-dd-kbd">{row.shortcut}</kbd>}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export interface DropdownProps {
|
||||
@@ -146,21 +241,14 @@ export function Dropdown({
|
||||
|
||||
// Einheitliche Zeilenliste: im Wert-Modus aus `options`, im Aktions-Modus aus
|
||||
// `items`. So teilen beide Modi dieselbe Render-/Tastatur-Logik.
|
||||
const rows: DropdownItem[] = items
|
||||
? items
|
||||
: (options ?? []).map((o) => ({
|
||||
label: o.label,
|
||||
disabled: o.disabled,
|
||||
active: o.value === value,
|
||||
onSelect: () => onChange?.(o.value),
|
||||
}));
|
||||
const rows: DropdownItem[] = items ? items : optionRows(options ?? [], value, onChange);
|
||||
|
||||
// Trigger-Label: Wert-Modus → Label der aktiven Option; sonst `placeholder`.
|
||||
const current = options?.find((o) => o.value === value);
|
||||
const triggerLabel = current?.label ?? placeholder ?? "";
|
||||
|
||||
// Index der ersten auswählbaren Zeile (für Tastatur-Start).
|
||||
const firstSelectable = rows.findIndex((r) => !r.divider && !r.disabled);
|
||||
const firstSelectable = rows.findIndex((r) => !isInert(r) && !r.disabled);
|
||||
|
||||
const place = () => {
|
||||
const r = btnRef.current?.getBoundingClientRect();
|
||||
@@ -183,7 +271,7 @@ export function Dropdown({
|
||||
};
|
||||
|
||||
const selectRow = (row: DropdownItem) => {
|
||||
if (row.disabled || row.divider) return;
|
||||
if (row.disabled || isInert(row)) return;
|
||||
row.onSelect?.();
|
||||
close();
|
||||
};
|
||||
@@ -244,7 +332,7 @@ export function Dropdown({
|
||||
for (let n = 0; n < rows.length; n++) {
|
||||
i = (i + dir + rows.length) % rows.length;
|
||||
const row = rows[i];
|
||||
if (row && !row.divider && !row.disabled) {
|
||||
if (row && !isInert(row) && !row.disabled) {
|
||||
setActiveIdx(i);
|
||||
return;
|
||||
}
|
||||
@@ -283,27 +371,7 @@ export function Dropdown({
|
||||
style={{ left: pos.left, top: pos.top, minWidth: pos.minWidth }}
|
||||
onContextMenu={(e) => e.preventDefault()}
|
||||
>
|
||||
{rows.map((row, i) =>
|
||||
row.divider ? (
|
||||
<div key={`div-${i}`} className="ctx-divider" role="separator" />
|
||||
) : (
|
||||
<button
|
||||
key={`row-${i}`}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={!!row.active}
|
||||
className={`ctx-item tb-dd-item${row.danger ? " danger" : ""}${
|
||||
i === activeIdx ? " is-active" : ""
|
||||
}`}
|
||||
disabled={row.disabled}
|
||||
onMouseEnter={() => !row.disabled && setActiveIdx(i)}
|
||||
onClick={() => selectRow(row)}
|
||||
>
|
||||
<span className="tb-dd-check-slot">{row.active && <Check />}</span>
|
||||
<span className="ctx-item-label">{row.label}</span>
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
<DropdownRows rows={rows} activeIdx={activeIdx} onHover={setActiveIdx} onSelect={selectRow} />
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
|
||||
+21
-10
@@ -199,6 +199,26 @@ function ComboMenu({
|
||||
/** Die vier oberen Iso-Oktanten (untere vier bleiben im Hochbau ungenutzt). */
|
||||
const ISO_VARIANTS: View3d[] = ["iso", "isoFrontLeft", "isoBackRight", "isoBackLeft"];
|
||||
|
||||
/** [244] Darstellungsarten im 3D: gruppiert, mit Icon und Kurzerklärung. */
|
||||
export function renderModeOptions(): DropdownOption[] {
|
||||
const lines = t("display.group.lines");
|
||||
const faces = t("display.group.faces");
|
||||
const render = t("display.group.render");
|
||||
const o = (value: RenderMode, key: string, icon: string, group: string): DropdownOption => ({
|
||||
value, label: t(`display.style.${key}`), hint: t(`display.style.${key}.tip`), icon, group,
|
||||
});
|
||||
return [
|
||||
o("wireframe", "wireframe", "deployed_code", lines),
|
||||
o("hidden", "hidden", "visibility_off", lines),
|
||||
o("contour", "contour", "border_style", lines),
|
||||
o("shaded", "shaded", "view_in_ar", faces),
|
||||
o("shaded-edges", "shadedEdges", "select_all", faces),
|
||||
o("textured", "textured", "texture", faces),
|
||||
o("white", "white", "circle", faces),
|
||||
o("pathtrace", "pathtrace", "auto_awesome", render),
|
||||
];
|
||||
}
|
||||
|
||||
/** Häkchen vor der aktiven Iso-Zeile (gleiche Glyphe wie `Dropdown`s Check). */
|
||||
function IsoCheck() {
|
||||
return (
|
||||
@@ -1257,16 +1277,7 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
disabled={!renderModeEnabled}
|
||||
onChange={(v) => onRenderMode(v as RenderMode)}
|
||||
title={t("display.style.hint")}
|
||||
options={[
|
||||
{ value: "shaded", label: t("display.style.shaded") },
|
||||
{ value: "shaded-edges", label: t("display.style.shadedEdges") },
|
||||
{ value: "white", label: t("display.style.white") },
|
||||
{ value: "contour", label: t("display.style.contour") },
|
||||
{ value: "textured", label: t("display.style.textured") },
|
||||
{ value: "wireframe", label: t("display.style.wireframe") },
|
||||
{ value: "hidden", label: t("display.style.hidden") },
|
||||
{ value: "pathtrace", label: t("display.style.pathtrace") },
|
||||
]}
|
||||
options={renderModeOptions()}
|
||||
/>
|
||||
) : (
|
||||
<Dropdown
|
||||
|
||||
Reference in new issue
Block a user