Compare commits
4 Commits
feat/issue
...
feat/issue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3de3b2131f | ||
|
|
94b8117c17 | ||
|
|
a3343f898f | ||
|
|
533196dabb |
@@ -32,6 +32,9 @@
|
||||
"layout_menu_close": "Menü schließen",
|
||||
"theme_toggle_to_light": "Zu hellem Design wechseln",
|
||||
"theme_toggle_to_dark": "Zu dunklem Design wechseln",
|
||||
"theme_toggle_label": "Farbschema",
|
||||
"theme_segment_light": "Hell",
|
||||
"theme_segment_dark": "Dunkel",
|
||||
"btn_save": "Speichern",
|
||||
"btn_cancel": "Abbrechen",
|
||||
"btn_confirm": "Bestätigen",
|
||||
@@ -130,8 +133,6 @@
|
||||
"doc_no_scan": "Kein Scan vorhanden",
|
||||
"persons_heading": "Personenverzeichnis",
|
||||
"persons_subtitle": "Durchsuchen Sie den Index aller erfassten Personen im Familienarchiv.",
|
||||
"persons_eyebrow": "Verzeichnis",
|
||||
"persons_lede": "Jede Hand, die schrieb oder genannt wurde — Absender, Empfänger, Erwähnte.",
|
||||
"persons_btn_new": "Neue Person",
|
||||
"persons_search_placeholder": "Namen suchen...",
|
||||
"persons_empty_heading": "Keine Personen gefunden.",
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
"layout_menu_close": "Close menu",
|
||||
"theme_toggle_to_light": "Switch to light mode",
|
||||
"theme_toggle_to_dark": "Switch to dark mode",
|
||||
"theme_toggle_label": "Color scheme",
|
||||
"theme_segment_light": "Light",
|
||||
"theme_segment_dark": "Dark",
|
||||
"btn_save": "Save",
|
||||
"btn_cancel": "Cancel",
|
||||
"btn_confirm": "Confirm",
|
||||
@@ -130,8 +133,6 @@
|
||||
"doc_no_scan": "No scan available",
|
||||
"persons_heading": "Person directory",
|
||||
"persons_subtitle": "Browse the index of all recorded persons in the family archive.",
|
||||
"persons_eyebrow": "Directory",
|
||||
"persons_lede": "Every hand that wrote or was named — senders, recipients, those mentioned.",
|
||||
"persons_btn_new": "New person",
|
||||
"persons_search_placeholder": "Search names...",
|
||||
"persons_empty_heading": "No persons found.",
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
"layout_menu_close": "Cerrar menú",
|
||||
"theme_toggle_to_light": "Cambiar a modo claro",
|
||||
"theme_toggle_to_dark": "Cambiar a modo oscuro",
|
||||
"theme_toggle_label": "Esquema de color",
|
||||
"theme_segment_light": "Claro",
|
||||
"theme_segment_dark": "Oscuro",
|
||||
"btn_save": "Guardar",
|
||||
"btn_cancel": "Cancelar",
|
||||
"btn_confirm": "Confirmar",
|
||||
@@ -130,8 +133,6 @@
|
||||
"doc_no_scan": "No hay escaneo disponible",
|
||||
"persons_heading": "Directorio de personas",
|
||||
"persons_subtitle": "Explore el índice de todas las personas registradas en el archivo familiar.",
|
||||
"persons_eyebrow": "Directorio",
|
||||
"persons_lede": "Cada mano que escribió o fue nombrada — remitentes, destinatarios, mencionados.",
|
||||
"persons_btn_new": "Nueva persona",
|
||||
"persons_search_placeholder": "Buscar nombres...",
|
||||
"persons_empty_heading": "No se encontraron personas.",
|
||||
|
||||
@@ -54,10 +54,11 @@ function setReview(next: boolean) {
|
||||
});
|
||||
}
|
||||
|
||||
// §6 tokens: Montserrat 12px/700 tracking-[.08em] UPPERCASE; 44px touch target
|
||||
const chipBase =
|
||||
'inline-flex min-h-[44px] min-w-[44px] items-center gap-1.5 rounded-sm border px-4 py-2 font-sans text-sm font-semibold transition-colors focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-2 focus-visible:outline-none';
|
||||
const chipActive = 'border-brand-navy bg-brand-navy text-white';
|
||||
const chipInactive = 'border-line bg-surface text-ink hover:bg-muted';
|
||||
'inline-flex min-h-[44px] min-w-[44px] items-center gap-1.5 rounded-sm border px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em] uppercase transition-colors focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:outline-none';
|
||||
const chipActive = 'border-primary bg-primary text-primary-fg';
|
||||
const chipInactive = 'border-line bg-surface text-ink-2 hover:bg-surface-2';
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center">
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
let {
|
||||
eyebrow,
|
||||
title,
|
||||
lede,
|
||||
right
|
||||
}: {
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
lede?: string;
|
||||
right?: Snippet;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div
|
||||
data-testid="page-header-wrapper"
|
||||
style="margin-bottom:30px; display:flex; align-items:flex-end; justify-content:space-between; gap:24px; flex-wrap:wrap"
|
||||
>
|
||||
<div
|
||||
data-testid="page-header-inner"
|
||||
style="border-left:4px solid var(--c-accent); padding-left:18px"
|
||||
>
|
||||
<div
|
||||
data-testid="page-header-eyebrow"
|
||||
style="font-family:var(--font-sans); font-size:12px; font-weight:700; letter-spacing:.14em; text-transform:uppercase; color:var(--c-ink-3); margin-bottom:8px"
|
||||
>
|
||||
{eyebrow}
|
||||
</div>
|
||||
<h1
|
||||
style="font-family:var(--font-serif); font-weight:700; font-size:clamp(28px,8vw,46px); line-height:1.06; color:var(--c-ink); margin:0"
|
||||
>
|
||||
{title}
|
||||
</h1>
|
||||
{#if lede}
|
||||
<p
|
||||
data-testid="page-header-lede"
|
||||
style="font-family:var(--font-serif); font-style:italic; font-size:16px; color:var(--c-ink-2); margin:10px 0 0; max-width:520px"
|
||||
>
|
||||
{lede}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if right}
|
||||
{@render right()}
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,135 +0,0 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
|
||||
import PageHeader from './PageHeader.svelte';
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
describe('PageHeader', () => {
|
||||
// ── Structural / heading-hierarchy assertions ─────────────────────────
|
||||
|
||||
it('renders exactly one h1 containing the title', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const headings = page.getByRole('heading', { level: 1 });
|
||||
await expect.element(headings).toBeInTheDocument();
|
||||
await expect.element(headings).toHaveTextContent('Personen');
|
||||
});
|
||||
|
||||
it('renders the eyebrow as a non-heading element (div or span)', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
// The eyebrow must NOT be a heading of any level
|
||||
const h1 = page.getByRole('heading', { level: 1 });
|
||||
await expect.element(h1).toBeInTheDocument();
|
||||
|
||||
// No h2-h6 headings should be present
|
||||
const h2 = page.getByRole('heading', { level: 2 });
|
||||
await expect.element(h2).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders eyebrow text content', async () => {
|
||||
render(PageHeader, { eyebrow: 'PERSONENVERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const eyebrow = page.getByTestId('page-header-eyebrow');
|
||||
await expect.element(eyebrow).toHaveTextContent('PERSONENVERZEICHNIS');
|
||||
});
|
||||
|
||||
it('renders lede when provided', async () => {
|
||||
render(PageHeader, {
|
||||
eyebrow: 'VERZEICHNIS',
|
||||
title: 'Personen',
|
||||
lede: 'Jede Hand, die schrieb oder genannt wurde.'
|
||||
});
|
||||
|
||||
const lede = page.getByTestId('page-header-lede');
|
||||
await expect.element(lede).toHaveTextContent('Jede Hand, die schrieb oder genannt wurde.');
|
||||
});
|
||||
|
||||
it('does not render lede element when lede prop is omitted', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const lede = page.getByTestId('page-header-lede');
|
||||
await expect.element(lede).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// ── Right snippet ─────────────────────────────────────────────────────
|
||||
|
||||
it('renders the outer wrapper with page-header-wrapper test id', async () => {
|
||||
render(PageHeader, {
|
||||
eyebrow: 'VERZEICHNIS',
|
||||
title: 'Personen'
|
||||
});
|
||||
|
||||
const wrapper = page.getByTestId('page-header-wrapper');
|
||||
await expect.element(wrapper).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// ── Content security: no @html ────────────────────────────────────────
|
||||
|
||||
it('escapes HTML in title (renders literal < as text not tags)', async () => {
|
||||
render(PageHeader, { eyebrow: 'TEST', title: '<script>alert(1)</script>' });
|
||||
|
||||
const h1 = page.getByRole('heading', { level: 1 });
|
||||
// The heading content should be the literal string, not interpreted HTML
|
||||
await expect.element(h1).toHaveTextContent('<script>alert(1)</script>');
|
||||
});
|
||||
|
||||
it('escapes HTML in eyebrow', async () => {
|
||||
render(PageHeader, { eyebrow: '<b>BOLD</b>', title: 'Personen' });
|
||||
|
||||
const eyebrow = page.getByTestId('page-header-eyebrow');
|
||||
await expect.element(eyebrow).toHaveTextContent('<b>BOLD</b>');
|
||||
});
|
||||
|
||||
// ── Design tokens / style ─────────────────────────────────────────────
|
||||
|
||||
it('h1 has font-size set to the clamp expression', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const h1 = page.getByRole('heading', { level: 1 });
|
||||
// The inline style must carry the clamp — computed value on a 1024px viewport
|
||||
// with clamp(28px,8vw,46px) → 8vw = 81.92px > 46px → capped at 46px
|
||||
const el = h1.element() as HTMLElement;
|
||||
const fs = el.style.fontSize || getComputedStyle(el).fontSize;
|
||||
expect(fs).toMatch(/clamp|46px|28px/);
|
||||
});
|
||||
|
||||
it('wrapper has data-testid page-header-wrapper', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const wrapper = page.getByTestId('page-header-wrapper');
|
||||
await expect.element(wrapper).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('inner container inline style includes the 4px accent left border and 18px padding', async () => {
|
||||
render(PageHeader, { eyebrow: 'VERZEICHNIS', title: 'Personen' });
|
||||
|
||||
const inner = page.getByTestId('page-header-inner');
|
||||
const el = inner.element() as HTMLElement;
|
||||
const styleAttr = el.getAttribute('style') ?? '';
|
||||
expect(styleAttr).toContain('border-left:4px solid var(--c-accent)');
|
||||
expect(styleAttr).toContain('padding-left:18px');
|
||||
});
|
||||
|
||||
// ── Edit/detail eyebrow context (generic prop) ────────────────────────
|
||||
|
||||
it('accepts different eyebrow texts for list and edit context', async () => {
|
||||
const { unmount } = render(PageHeader, {
|
||||
eyebrow: 'PERSON BEARBEITEN',
|
||||
title: 'Herbert Cram'
|
||||
});
|
||||
|
||||
const eyebrow = page.getByTestId('page-header-eyebrow');
|
||||
await expect.element(eyebrow).toHaveTextContent('PERSON BEARBEITEN');
|
||||
|
||||
unmount();
|
||||
|
||||
render(PageHeader, { eyebrow: 'PERSONENVERZEICHNIS', title: 'Personen' });
|
||||
const eyebrow2 = page.getByTestId('page-header-eyebrow');
|
||||
await expect.element(eyebrow2).toHaveTextContent('PERSONENVERZEICHNIS');
|
||||
});
|
||||
});
|
||||
55
frontend/src/lib/shared/primitives/SegmentedControl.svelte
Normal file
55
frontend/src/lib/shared/primitives/SegmentedControl.svelte
Normal file
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { radioGroupNav } from '$lib/shared/actions/radioGroupNav';
|
||||
|
||||
interface Option {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
options: Option[];
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
let { options, value, onChange, label = undefined }: Props = $props();
|
||||
|
||||
// Roving tabindex: the active segment gets tabindex=0; all others -1.
|
||||
// If no segment is active yet, fall back to the first so keyboard nav
|
||||
// can enter the control.
|
||||
const rovingFocus = $derived(
|
||||
options.some((o) => o.value === value) ? value : (options[0]?.value ?? '')
|
||||
);
|
||||
</script>
|
||||
|
||||
<!--
|
||||
§6 Segmented Control — single-select, radiogroup + roving tabindex.
|
||||
Callers supply pre-resolved Paraglide strings for all labels.
|
||||
No {@html} is used on option labels (XSS-safe default escaping only).
|
||||
-->
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-label={label}
|
||||
class="inline-flex flex-wrap rounded-sm border border-line md:flex-nowrap"
|
||||
use:radioGroupNav={(v) => onChange(v)}
|
||||
>
|
||||
{#each options as option, i (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
value={option.value}
|
||||
aria-checked={option.value === value}
|
||||
tabindex={option.value === rovingFocus ? 0 : -1}
|
||||
onclick={() => onChange(option.value)}
|
||||
class="min-h-[44px] cursor-pointer px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em]
|
||||
uppercase transition-colors
|
||||
focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-inset
|
||||
{i > 0 ? 'border-l border-line' : ''}
|
||||
{option.value === value
|
||||
? 'bg-primary text-primary-fg'
|
||||
: 'hover:bg-surface-2 bg-surface text-ink-2'}"
|
||||
>{option.label}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,170 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page, userEvent } from 'vitest/browser';
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
const options = [
|
||||
{ value: 'a', label: 'Option A' },
|
||||
{ value: 'b', label: 'Option B' },
|
||||
{ value: 'c', label: 'Option C' }
|
||||
];
|
||||
|
||||
const { default: SegmentedControl } = await import('./SegmentedControl.svelte');
|
||||
|
||||
// ─── Structure & ARIA ─────────────────────────────────────────────────────────
|
||||
|
||||
describe('SegmentedControl — structure', () => {
|
||||
it('renders a radiogroup wrapper', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const group = document.querySelector('[role="radiogroup"]');
|
||||
expect(group).not.toBeNull();
|
||||
});
|
||||
|
||||
it('renders one radio per option with the correct label', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
await expect.element(page.getByRole('radio', { name: 'Option A' })).toBeVisible();
|
||||
await expect.element(page.getByRole('radio', { name: 'Option B' })).toBeVisible();
|
||||
await expect.element(page.getByRole('radio', { name: 'Option C' })).toBeVisible();
|
||||
});
|
||||
|
||||
it('active segment has aria-checked="true", inactive ones "false"', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'b', onChange: vi.fn() } });
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Option B' }))
|
||||
.toHaveAttribute('aria-checked', 'true');
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Option A' }))
|
||||
.toHaveAttribute('aria-checked', 'false');
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Option C' }))
|
||||
.toHaveAttribute('aria-checked', 'false');
|
||||
});
|
||||
|
||||
it('active segment gets tabindex=0, inactive segments tabindex=-1', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const radios = Array.from(document.querySelectorAll('[role="radio"]'));
|
||||
expect(radios[0]?.getAttribute('tabindex')).toBe('0');
|
||||
expect(radios[1]?.getAttribute('tabindex')).toBe('-1');
|
||||
expect(radios[2]?.getAttribute('tabindex')).toBe('-1');
|
||||
});
|
||||
|
||||
it('applies §6 active token classes to the active segment', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const activeRadio = page.getByRole('radio', { name: 'Option A' });
|
||||
await expect.element(activeRadio).toHaveClass(/bg-primary/);
|
||||
await expect.element(activeRadio).toHaveClass(/text-primary-fg/);
|
||||
});
|
||||
|
||||
it('applies §6 inactive token classes to inactive segments', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const inactiveRadio = page.getByRole('radio', { name: 'Option B' });
|
||||
await expect.element(inactiveRadio).toHaveClass(/bg-surface/);
|
||||
await expect.element(inactiveRadio).toHaveClass(/text-ink-2/);
|
||||
});
|
||||
|
||||
it('segment labels are rendered as plain text — no innerHTML injection', async () => {
|
||||
const xssOptions = [{ value: 'x', label: '<img src=x onerror=alert(1)>' }];
|
||||
render(SegmentedControl, { props: { options: xssOptions, value: 'x', onChange: vi.fn() } });
|
||||
// If the label were injected via {@html}, an <img> element would appear
|
||||
const imgs = document.querySelectorAll('img');
|
||||
expect(imgs.length).toBe(0);
|
||||
// The raw text string should appear literally
|
||||
const radio = document.querySelector('[role="radio"]');
|
||||
expect(radio?.textContent).toContain('<img');
|
||||
});
|
||||
|
||||
it('wrapper has border border-line rounded-sm tokens', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const group = document.querySelector('[role="radiogroup"]');
|
||||
expect(group?.className).toMatch(/border-line/);
|
||||
expect(group?.className).toMatch(/rounded-sm/);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Interaction ──────────────────────────────────────────────────────────────
|
||||
|
||||
describe('SegmentedControl — click selection', () => {
|
||||
it('clicking an inactive segment calls onChange with its value', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option B' }).click();
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('b');
|
||||
});
|
||||
|
||||
it('clicking the already-active segment still calls onChange', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('a');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Keyboard ─────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('SegmentedControl — keyboard roving tabindex', () => {
|
||||
it('ArrowRight moves focus and selection to the next segment', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||
await userEvent.keyboard('{ArrowRight}');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('b');
|
||||
});
|
||||
|
||||
it('ArrowLeft moves focus to the previous segment', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'b', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option B' }).click();
|
||||
await userEvent.keyboard('{ArrowLeft}');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('a');
|
||||
});
|
||||
|
||||
it('ArrowRight wraps from last to first', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'c', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option C' }).click();
|
||||
await userEvent.keyboard('{ArrowRight}');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('a');
|
||||
});
|
||||
|
||||
it('ArrowLeft wraps from first to last', async () => {
|
||||
const onChange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||
|
||||
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||
await userEvent.keyboard('{ArrowLeft}');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('c');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Touch target ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe('SegmentedControl — geometry', () => {
|
||||
it('each segment meets the 44px min-height touch target', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const radios = document.querySelectorAll('[role="radio"]');
|
||||
for (const radio of Array.from(radios)) {
|
||||
expect(radio.className).toMatch(/min-h-\[44px\]/);
|
||||
}
|
||||
});
|
||||
|
||||
it('each segment has the px-4 py-[9px] padding classes', async () => {
|
||||
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||
const radios = document.querySelectorAll('[role="radio"]');
|
||||
for (const radio of Array.from(radios)) {
|
||||
expect(radio.className).toMatch(/px-4/);
|
||||
expect(radio.className).toMatch(/py-\[9px\]/);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
|
||||
type Theme = 'light' | 'dark';
|
||||
|
||||
@@ -24,51 +25,31 @@ const themeLabel = $derived(
|
||||
theme === 'dark' ? m.theme_toggle_to_light() : m.theme_toggle_to_dark()
|
||||
);
|
||||
|
||||
function toggle() {
|
||||
theme = theme === 'dark' ? 'light' : 'dark';
|
||||
const themeOptions = $derived([
|
||||
{ value: 'light', label: m.theme_segment_light() },
|
||||
{ value: 'dark', label: m.theme_segment_dark() }
|
||||
]);
|
||||
|
||||
function handleChange(next: string) {
|
||||
if (next !== 'light' && next !== 'dark') return;
|
||||
theme = next as Theme;
|
||||
localStorage.setItem('theme', theme);
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick={toggle}
|
||||
aria-label={themeLabel}
|
||||
title={themeLabel}
|
||||
class="rounded p-1.5 text-white/65 transition-colors hover:bg-white/10 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
|
||||
>
|
||||
{#if theme === 'dark'}
|
||||
<!-- Sun icon — click to go light -->
|
||||
<svg
|
||||
class="h-5 w-5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
d="M12 2v2M12 20v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M2 12h2M20 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<!-- Moon icon — click to go dark -->
|
||||
<svg
|
||||
class="h-5 w-5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
<!--
|
||||
ThemeToggle — binary light/dark segmented control.
|
||||
File kept at $lib/shared/primitives/ThemeToggle.svelte (required by #862).
|
||||
Boot FOUC prevention: a tiny inline script in <head> reads localStorage['theme']
|
||||
and sets data-theme before paint — that script is unchanged by this refactor.
|
||||
The aria-label on the group communicates the toggle purpose to screen readers.
|
||||
-->
|
||||
<div aria-label={themeLabel} title={themeLabel}>
|
||||
<SegmentedControl
|
||||
options={themeOptions}
|
||||
value={theme}
|
||||
onChange={handleChange}
|
||||
label={m.theme_toggle_label()}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -8,38 +8,59 @@ afterEach(() => {
|
||||
localStorage.removeItem('theme');
|
||||
});
|
||||
|
||||
describe('ThemeToggle — label derivation (light mode)', () => {
|
||||
describe('ThemeToggle — renders segments (light mode)', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('theme', 'light');
|
||||
});
|
||||
|
||||
it('aria-label invites switching to dark mode when theme is light', async () => {
|
||||
it('renders a radiogroup with Hell and Dunkel segments', async () => {
|
||||
render(ThemeToggle);
|
||||
const btn = await page.getByRole('button').element();
|
||||
expect(btn.getAttribute('aria-label')).toBe('Zu dunklem Design wechseln');
|
||||
expect(document.querySelector('[role="radiogroup"]')).not.toBeNull();
|
||||
await expect.element(page.getByRole('radio', { name: 'Hell' })).toBeVisible();
|
||||
await expect.element(page.getByRole('radio', { name: 'Dunkel' })).toBeVisible();
|
||||
});
|
||||
|
||||
it('title equals aria-label in light mode', async () => {
|
||||
it('Hell segment is aria-checked="true" in light mode', async () => {
|
||||
render(ThemeToggle);
|
||||
const btn = await page.getByRole('button').element();
|
||||
expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Hell' }))
|
||||
.toHaveAttribute('aria-checked', 'true');
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Dunkel' }))
|
||||
.toHaveAttribute('aria-checked', 'false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ThemeToggle — label derivation (dark mode)', () => {
|
||||
describe('ThemeToggle — renders segments (dark mode)', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
});
|
||||
|
||||
it('aria-label invites switching to light mode when theme is dark', async () => {
|
||||
it('Dunkel segment is aria-checked="true" in dark mode', async () => {
|
||||
render(ThemeToggle);
|
||||
const btn = await page.getByRole('button').element();
|
||||
expect(btn.getAttribute('aria-label')).toBe('Zu hellem Design wechseln');
|
||||
});
|
||||
|
||||
it('title equals aria-label in dark mode', async () => {
|
||||
render(ThemeToggle);
|
||||
const btn = await page.getByRole('button').element();
|
||||
expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Dunkel' }))
|
||||
.toHaveAttribute('aria-checked', 'true');
|
||||
await expect
|
||||
.element(page.getByRole('radio', { name: 'Hell' }))
|
||||
.toHaveAttribute('aria-checked', 'false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ThemeToggle — theme switching', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('theme', 'light');
|
||||
});
|
||||
|
||||
it('clicking Dunkel sets data-theme=dark on documentElement', async () => {
|
||||
render(ThemeToggle);
|
||||
await page.getByRole('radio', { name: 'Dunkel' }).click();
|
||||
expect(document.documentElement.getAttribute('data-theme')).toBe('dark');
|
||||
});
|
||||
|
||||
it('clicking Dunkel persists theme in localStorage', async () => {
|
||||
render(ThemeToggle);
|
||||
await page.getByRole('radio', { name: 'Dunkel' }).click();
|
||||
expect(localStorage.getItem('theme')).toBe('dark');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,14 +42,16 @@ function reset() {
|
||||
</script>
|
||||
|
||||
{#snippet layerToggle(label: string, testid: string, pressed: boolean, toggle: () => void)}
|
||||
<!-- §6 re-skin: bg-primary/text-primary-fg (active) · bg-surface/text-ink-2 (inactive)
|
||||
Typography: Montserrat 12px/700 tracking-[.08em] UPPERCASE; min-h-[44px] touch target -->
|
||||
<button
|
||||
type="button"
|
||||
data-testid={testid}
|
||||
aria-pressed={pressed}
|
||||
onclick={toggle}
|
||||
class="inline-flex min-h-[44px] items-center gap-2 rounded border px-3 font-sans text-sm transition-colors {pressed
|
||||
class="inline-flex min-h-[44px] items-center gap-2 rounded-sm border px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em] uppercase transition-colors focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:outline-none {pressed
|
||||
? 'border-primary bg-primary text-primary-fg'
|
||||
: 'border-line bg-muted text-ink-2 hover:bg-line'}"
|
||||
: 'hover:bg-surface-2 border-line bg-surface text-ink-2'}"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
@@ -73,7 +75,7 @@ function reset() {
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? 'timeline-filter-panel' : undefined}
|
||||
onclick={() => (open = !open)}
|
||||
class="inline-flex min-h-[44px] items-center gap-2 rounded border border-line bg-surface px-4 font-sans text-xs font-bold tracking-widest text-ink-2 uppercase transition-colors hover:bg-muted"
|
||||
class="hover:bg-surface-2 inline-flex min-h-[44px] items-center gap-2 rounded-sm border border-line bg-surface px-4 font-sans text-xs font-bold tracking-[.08em] text-ink-2 uppercase transition-colors"
|
||||
>
|
||||
{hiddenCount === 0
|
||||
? m.timeline_filter_trigger()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
import { radioGroupNav } from '$lib/shared/actions/radioGroupNav';
|
||||
import SegmentedControl from '$lib/shared/primitives/SegmentedControl.svelte';
|
||||
|
||||
type GeschichteType = 'STORY' | 'JOURNEY';
|
||||
|
||||
const TYPES: GeschichteType[] = ['STORY', 'JOURNEY'];
|
||||
|
||||
interface Props {
|
||||
onweiter: (type: GeschichteType) => void;
|
||||
}
|
||||
@@ -15,10 +13,6 @@ let { onweiter }: Props = $props();
|
||||
let selected = $state<GeschichteType | null>(null);
|
||||
let announcement = $state('');
|
||||
|
||||
// Roving-tabindex holder: falls back to the first card so keyboard nav can start
|
||||
// even when nothing is selected (all cards at tabindex=-1 would be a keyboard dead-spot).
|
||||
const rovingFocusType = $derived(selected ?? TYPES[0]);
|
||||
|
||||
function select(type: GeschichteType) {
|
||||
selected = type;
|
||||
announcement = '';
|
||||
@@ -32,15 +26,10 @@ function handleWeiter() {
|
||||
onweiter(selected);
|
||||
}
|
||||
|
||||
const titles: Record<GeschichteType, () => string> = {
|
||||
STORY: m.journey_selector_story_title,
|
||||
JOURNEY: m.journey_selector_journey_title
|
||||
};
|
||||
|
||||
const descs: Record<GeschichteType, () => string> = {
|
||||
STORY: m.journey_selector_story_desc,
|
||||
JOURNEY: m.journey_selector_journey_desc
|
||||
};
|
||||
const typeOptions = [
|
||||
{ value: 'STORY', label: m.journey_selector_story_title() },
|
||||
{ value: 'JOURNEY', label: m.journey_selector_journey_title() }
|
||||
];
|
||||
</script>
|
||||
|
||||
<div>
|
||||
@@ -48,31 +37,14 @@ const descs: Record<GeschichteType, () => string> = {
|
||||
{m.journey_selector_question()}
|
||||
</p>
|
||||
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-labelledby="type-selector-label"
|
||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2"
|
||||
use:radioGroupNav={(v) => {
|
||||
if (TYPES.includes(v as GeschichteType)) select(v as GeschichteType);
|
||||
<SegmentedControl
|
||||
options={typeOptions}
|
||||
value={selected ?? ''}
|
||||
onChange={(v) => {
|
||||
if (v === 'STORY' || v === 'JOURNEY') select(v);
|
||||
}}
|
||||
>
|
||||
{#each TYPES as type (type)}
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
value={type}
|
||||
aria-checked={selected === type}
|
||||
tabindex={type === rovingFocusType ? 0 : -1}
|
||||
onclick={() => select(type)}
|
||||
class="min-h-[64px] cursor-pointer rounded border px-4 py-3 text-left transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring {selected === type
|
||||
? 'border-primary bg-primary text-primary-fg'
|
||||
: 'border-line bg-surface text-ink hover:border-primary/50'}"
|
||||
>
|
||||
<span class="block font-sans text-sm font-bold">{titles[type]()}</span>
|
||||
<span class="mt-1 block font-sans text-xs text-current opacity-70">{descs[type]()}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
label={m.journey_selector_question()}
|
||||
/>
|
||||
|
||||
<div aria-live="polite" aria-atomic="true" class="sr-only">{announcement}</div>
|
||||
|
||||
|
||||
@@ -18,13 +18,18 @@ describe('TypeSelector', () => {
|
||||
await expect.element(page.getByRole('radio', { name: /Lesereise/i })).toBeVisible();
|
||||
});
|
||||
|
||||
it('radiogroup is correctly labelled', async () => {
|
||||
it('radiogroup is correctly labelled (via aria-label or aria-labelledby)', async () => {
|
||||
render(TypeSelector, { props: { onweiter: vi.fn() } });
|
||||
|
||||
const group = document.querySelector('[role="radiogroup"]');
|
||||
const labelledBy = group?.getAttribute('aria-labelledby');
|
||||
// SegmentedControl uses aria-label; the old TypeSelector used aria-labelledby.
|
||||
// Accept either as long as the accessible name is non-empty.
|
||||
const ariaLabel = group?.getAttribute('aria-label') ?? '';
|
||||
const labelledBy = group?.getAttribute('aria-labelledby') ?? '';
|
||||
const labelEl = labelledBy ? document.getElementById(labelledBy) : null;
|
||||
expect(labelEl?.textContent?.trim().length).toBeGreaterThan(0);
|
||||
const hasAccessibleName =
|
||||
ariaLabel.trim().length > 0 || (labelEl?.textContent?.trim().length ?? 0) > 0;
|
||||
expect(hasAccessibleName).toBe(true);
|
||||
});
|
||||
|
||||
it('Weiter button has aria-disabled=true when nothing is selected', async () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { m } from '$lib/paraglide/messages.js';
|
||||
import PersonCard from '$lib/person/PersonCard.svelte';
|
||||
import PersonFilterBar from '$lib/person/PersonFilterBar.svelte';
|
||||
import Pagination from '$lib/shared/primitives/Pagination.svelte';
|
||||
import PageHeader from '$lib/shared/primitives/PageHeader.svelte';
|
||||
import PersonsStatsBar from './PersonsStatsBar.svelte';
|
||||
import PersonsEmptyState from './PersonsEmptyState.svelte';
|
||||
|
||||
let { data } = $props();
|
||||
@@ -53,62 +53,71 @@ const noFiltersActive = $derived(
|
||||
</svelte:head>
|
||||
|
||||
<div class="mx-auto max-w-7xl px-4 py-12 sm:px-6 lg:px-8">
|
||||
<PageHeader eyebrow={m.persons_eyebrow()} title={m.page_title_persons()} lede={m.persons_lede()}>
|
||||
{#snippet right()}
|
||||
<div class="flex shrink-0 items-center gap-3">
|
||||
<!-- Search -->
|
||||
<div class="relative">
|
||||
<label for="search" class="sr-only">{m.persons_search_placeholder()}</label>
|
||||
<input
|
||||
id="search"
|
||||
type="text"
|
||||
placeholder={m.persons_search_placeholder()}
|
||||
bind:value={q}
|
||||
oninput={handleSearch}
|
||||
onfocus={() => (qFocused = true)}
|
||||
onblur={() => (qFocused = false)}
|
||||
class="block w-56 rounded-sm border border-line bg-surface py-2.5 pr-10 pl-4 font-sans text-sm text-ink placeholder-ink-3 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 text-ink-3"
|
||||
>
|
||||
<img
|
||||
src="/degruyter-icons/Simple/Medium-24px/SVG/Action/Mag-Glass-MD.svg"
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="h-4 w-4 opacity-40"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Triage link (transcriber only) -->
|
||||
{#if data.canWrite}
|
||||
<a
|
||||
href="/persons/review"
|
||||
class="inline-flex min-h-[44px] items-center gap-1.5 rounded-sm border border-line bg-surface px-4 py-2 font-sans text-sm font-semibold text-ink transition-colors hover:bg-muted"
|
||||
>
|
||||
{m.persons_toggle_needs_review({ count: data.needsReviewCount })}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
<!-- New person CTA -->
|
||||
{#if data.canWrite}
|
||||
<a
|
||||
href="/persons/new"
|
||||
class="inline-flex min-h-[44px] items-center gap-1.5 rounded-sm bg-primary px-4 py-2.5 font-sans text-sm font-bold tracking-wide text-primary-fg transition-colors hover:bg-primary/80"
|
||||
>
|
||||
<img
|
||||
src="/degruyter-icons/Simple/Medium-24px/SVG/Action/Add/Add-General-MD.svg"
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="h-4 w-4 invert dark:invert-0"
|
||||
/>
|
||||
{m.persons_btn_new()}
|
||||
</a>
|
||||
{/if}
|
||||
<!-- Header: title+stats on left, search+CTA on right -->
|
||||
<div class="mb-6 flex flex-wrap items-end justify-between gap-4 border-b border-ink/10 pb-6">
|
||||
<div>
|
||||
<h1 class="font-serif text-3xl font-medium text-ink">{m.page_title_persons()}</h1>
|
||||
<div class="mt-2">
|
||||
<PersonsStatsBar
|
||||
totalPersons={data.stats.totalPersons ?? 0}
|
||||
totalDocuments={data.stats.totalDocuments ?? 0}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- Search -->
|
||||
<div class="relative">
|
||||
<label for="search" class="sr-only">{m.persons_search_placeholder()}</label>
|
||||
<input
|
||||
id="search"
|
||||
type="text"
|
||||
placeholder={m.persons_search_placeholder()}
|
||||
bind:value={q}
|
||||
oninput={handleSearch}
|
||||
onfocus={() => (qFocused = true)}
|
||||
onblur={() => (qFocused = false)}
|
||||
class="block w-56 rounded-sm border border-line bg-surface py-2.5 pr-10 pl-4 font-sans text-sm text-ink placeholder-ink-3 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 text-ink-3"
|
||||
>
|
||||
<img
|
||||
src="/degruyter-icons/Simple/Medium-24px/SVG/Action/Mag-Glass-MD.svg"
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="h-4 w-4 opacity-40"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Triage link (transcriber only) -->
|
||||
{#if data.canWrite}
|
||||
<a
|
||||
href="/persons/review"
|
||||
class="inline-flex min-h-[44px] items-center gap-1.5 rounded-sm border border-line bg-surface px-4 py-2 font-sans text-sm font-semibold text-ink transition-colors hover:bg-muted"
|
||||
>
|
||||
{m.persons_toggle_needs_review({ count: data.needsReviewCount })}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
<!-- New person CTA -->
|
||||
{#if data.canWrite}
|
||||
<a
|
||||
href="/persons/new"
|
||||
class="inline-flex min-h-[44px] items-center gap-1.5 rounded-sm bg-primary px-4 py-2.5 font-sans text-sm font-bold tracking-wide text-primary-fg transition-colors hover:bg-primary/80"
|
||||
>
|
||||
<img
|
||||
src="/degruyter-icons/Simple/Medium-24px/SVG/Action/Add/Add-General-MD.svg"
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="h-4 w-4 invert dark:invert-0"
|
||||
/>
|
||||
{m.persons_btn_new()}
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filter chips + show-all toggle -->
|
||||
<div class="mb-8">
|
||||
|
||||
Reference in New Issue
Block a user