Compare commits

..

4 Commits

Author SHA1 Message Date
Marcel
3de3b2131f refactor(shared): re-skin PersonFilterBar + TimelineFilters to §6 tokens
All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 6m7s
CI / OCR Service Tests (pull_request) Successful in 23s
CI / Backend Unit Tests (pull_request) Successful in 6m58s
CI / fail2ban Regex (pull_request) Successful in 49s
CI / Semgrep Security Scan (pull_request) Successful in 27s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m12s
SDD Gate / RTM Check (pull_request) Successful in 14s
SDD Gate / Contract Validate (pull_request) Successful in 24s
SDD Gate / Constitution Impact (pull_request) Successful in 19s
Refs #857
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 19:03:11 +02:00
Marcel
94b8117c17 refactor(shared): re-skin ThemeToggle onto SegmentedControl (§6 tokens)
Adds theme_segment_light/dark/label i18n keys (de/en/es).

Refs #857
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 19:02:44 +02:00
Marcel
a3343f898f refactor(geschichten): migrate TypeSelector onto SegmentedControl primitive
Refs #857
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 19:02:17 +02:00
Marcel
533196dabb feat(shared): add SegmentedControl primitive — §6 inline-flex, active=navy, radiogroup
Refs #857
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 19:01:51 +02:00
21 changed files with 396 additions and 289 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -1,12 +1,11 @@
<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import { formatDate } from '$lib/shared/utils/date';
import { formatDocumentStatus } from '$lib/document/documentStatusLabel';
import { getInitials, personAvatarColor } from '$lib/person/personFormat';
import RelationshipPill from '$lib/person/relationship/RelationshipPill.svelte';
import DocumentDate from './DocumentDate.svelte';
import DocumentStatusChip from './DocumentStatusChip.svelte';
import type { DatePrecision } from '$lib/shared/utils/documentDate';
import type { DocumentStatus } from '$lib/document/documentStatusLabel';
type Person = { id: string; firstName?: string | null; lastName: string; displayName: string };
type Tag = { id: string; name: string };
@@ -23,7 +22,7 @@ type Props = {
metaDateEnd?: string | null;
metaDateRaw?: string | null;
location: string | null;
status: DocumentStatus;
status: string;
sender: Person | null;
receivers: Person[];
tags: Tag[];
@@ -69,6 +68,7 @@ function formatGeschichteDate(g: GeschichteSummary): string {
}
const displayLocation = $derived(location ?? '—');
const statusLabel = $derived(formatDocumentStatus(status));
const visibleReceivers = $derived(receivers.slice(0, VISIBLE_RECEIVER_LIMIT));
const hiddenReceiverCount = $derived(Math.max(0, receivers.length - VISIBLE_RECEIVER_LIMIT));
const hasPersons = $derived(sender !== null || receivers.length > 0);
@@ -131,7 +131,7 @@ function getFullName(person: Person): string {
</div>
<div>
<dt class="font-sans text-xs font-medium text-ink-3">{m.doc_details_field_status()}</dt>
<dd class="text-ink"><DocumentStatusChip status={status} /></dd>
<dd class="text-ink">{statusLabel}</dd>
</div>
</dl>
</div>

View File

@@ -1,8 +1,7 @@
<script lang="ts">
import StatusDot from '$lib/shared/primitives/StatusDot.svelte';
import {
formatDocumentStatus,
statusDotColor,
statusDotClass,
type DocumentStatus
} from '$lib/document/documentStatusLabel';
@@ -12,10 +11,12 @@ type Props = {
let { status }: Props = $props();
const color = $derived(statusDotColor(status));
const dotClass = $derived(statusDotClass(status));
const label = $derived(formatDocumentStatus(status));
</script>
<span data-testid="status-chip" class="inline-flex shrink-0 items-center">
<StatusDot color={color} label={label} />
</span>
<span
class="hidden shrink-0 md:block {dotClass} h-4 w-4 rounded-full"
title={label}
aria-label={label}
></span>

View File

@@ -6,63 +6,45 @@ import DocumentStatusChip from './DocumentStatusChip.svelte';
afterEach(cleanup);
describe('DocumentStatusChip', () => {
it('renders the placeholder label for PLACEHOLDER status', async () => {
it('renders the placeholder label and gray dot for PLACEHOLDER status', async () => {
render(DocumentStatusChip, { props: { status: 'PLACEHOLDER' } });
// CSS uppercase is visual only; DOM textContent returns the Paraglide string.
await expect.element(page.getByText('Platzhalter')).toBeInTheDocument();
const dot = await page.getByTitle('Platzhalter').element();
expect(dot.classList.contains('bg-gray-400')).toBe(true);
});
it('renders the uploaded label for UPLOADED status', async () => {
it('renders the uploaded label and emerald dot for UPLOADED status', async () => {
render(DocumentStatusChip, { props: { status: 'UPLOADED' } });
await expect.element(page.getByText('Hochgeladen')).toBeInTheDocument();
const dot = await page.getByTitle('Hochgeladen').element();
expect(dot.classList.contains('bg-emerald-500')).toBe(true);
});
it('renders the transcribed label for TRANSCRIBED status', async () => {
it('renders the transcribed label and blue dot for TRANSCRIBED status', async () => {
render(DocumentStatusChip, { props: { status: 'TRANSCRIBED' } });
await expect.element(page.getByText('Transkribiert')).toBeInTheDocument();
const dot = await page.getByTitle('Transkribiert').element();
expect(dot.classList.contains('bg-blue-400')).toBe(true);
});
it('renders the reviewed label for REVIEWED status', async () => {
it('renders the reviewed label and amber dot for REVIEWED status', async () => {
render(DocumentStatusChip, { props: { status: 'REVIEWED' } });
await expect.element(page.getByText('Geprüft')).toBeInTheDocument();
const dot = await page.getByTitle('Geprüft').element();
expect(dot.classList.contains('bg-amber-400')).toBe(true);
});
it('renders the archived label for ARCHIVED status', async () => {
it('renders the archived label and dark emerald dot for ARCHIVED status', async () => {
render(DocumentStatusChip, { props: { status: 'ARCHIVED' } });
await expect.element(page.getByText('Archiviert')).toBeInTheDocument();
const dot = await page.getByTitle('Archiviert').element();
expect(dot.classList.contains('bg-emerald-600')).toBe(true);
});
it('renders the dot as an aria-hidden element (decorative)', async () => {
it('exposes the status as both a title tooltip and an aria-label', async () => {
render(DocumentStatusChip, { props: { status: 'UPLOADED' } });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot).not.toBeNull();
});
it('label AND dot are visible at all breakpoints — no hidden class on chip root', async () => {
render(DocumentStatusChip, { props: { status: 'PLACEHOLDER' } });
const root = document.querySelector('[data-testid="status-chip"]');
expect(root).not.toBeNull();
// The chip root must NOT have "hidden" class
expect(root?.className).not.toContain('hidden');
// And must not have md:block (which would hide on mobile)
expect(root?.className).not.toContain('md:block');
});
it('uses sage token for ARCHIVED status', async () => {
render(DocumentStatusChip, { props: { status: 'ARCHIVED' } });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot?.getAttribute('style')).toContain('var(--c-tag-sage)');
});
it('uses amber token for UPLOADED status', async () => {
render(DocumentStatusChip, { props: { status: 'UPLOADED' } });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot?.getAttribute('style')).toContain('var(--c-tag-amber)');
});
it('uses slate token for PLACEHOLDER status', async () => {
render(DocumentStatusChip, { props: { status: 'PLACEHOLDER' } });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot?.getAttribute('style')).toContain('var(--c-tag-slate)');
const dot = await page.getByTitle('Hochgeladen').element();
expect(dot.getAttribute('aria-label')).toBe('Hochgeladen');
});
});

View File

@@ -9,7 +9,6 @@ import DocumentTopBarActions from './DocumentTopBarActions.svelte';
import DocumentMobileMenu from './DocumentMobileMenu.svelte';
import BackButton from '$lib/shared/primitives/BackButton.svelte';
import type { DatePrecision } from '$lib/shared/utils/documentDate';
import type { DocumentStatus } from '$lib/document/documentStatusLabel';
type Person = { id: string; firstName?: string | null; lastName: string; displayName: string };
type Tag = { id: string; name: string };
@@ -27,7 +26,7 @@ type Doc = {
filePath?: string | null;
contentType?: string | null;
location?: string | null;
status?: DocumentStatus | null;
status?: string | null;
tags?: Tag[] | null;
hasTranscription?: boolean;
};

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { formatDocumentStatus, statusDotColor } from './documentStatusLabel';
import { formatDocumentStatus, statusDotClass } from './documentStatusLabel';
describe('formatDocumentStatus', () => {
it('maps PLACEHOLDER to correct label', () => {
@@ -27,24 +27,24 @@ describe('formatDocumentStatus', () => {
});
});
describe('statusDotColor — 5→3 semantic token mapping', () => {
it('PLACEHOLDER → --c-tag-slate (new/draft)', () => {
expect(statusDotColor('PLACEHOLDER')).toBe('var(--c-tag-slate)');
describe('statusDotClass', () => {
it('PLACEHOLDER → bg-gray-400', () => {
expect(statusDotClass('PLACEHOLDER')).toBe('bg-gray-400');
});
it('UPLOADED → --c-tag-amber (in-progress)', () => {
expect(statusDotColor('UPLOADED')).toBe('var(--c-tag-amber)');
it('UPLOADED → bg-emerald-500', () => {
expect(statusDotClass('UPLOADED')).toBe('bg-emerald-500');
});
it('TRANSCRIBED → --c-tag-sage (done/confirmed)', () => {
expect(statusDotColor('TRANSCRIBED')).toBe('var(--c-tag-sage)');
it('TRANSCRIBED → bg-blue-400', () => {
expect(statusDotClass('TRANSCRIBED')).toBe('bg-blue-400');
});
it('REVIEWED → --c-tag-sage (done/confirmed)', () => {
expect(statusDotColor('REVIEWED')).toBe('var(--c-tag-sage)');
it('REVIEWED → bg-amber-400', () => {
expect(statusDotClass('REVIEWED')).toBe('bg-amber-400');
});
it('ARCHIVED → --c-tag-sage (done/confirmed)', () => {
expect(statusDotColor('ARCHIVED')).toBe('var(--c-tag-sage)');
it('ARCHIVED → bg-emerald-600', () => {
expect(statusDotClass('ARCHIVED')).toBe('bg-emerald-600');
});
});

View File

@@ -19,23 +19,17 @@ export function formatDocumentStatus(status: string): string {
}
}
/**
* Maps a DocumentStatus to a semantic `--c-tag-*` CSS custom-property string.
*
* 5→3 mapping (decided in issue #861):
* ARCHIVED / TRANSCRIBED / REVIEWED → --c-tag-sage (done / confirmed)
* UPLOADED → --c-tag-amber (in-progress)
* PLACEHOLDER → --c-tag-slate (new / draft)
*/
export function statusDotColor(status: DocumentStatus): string {
export function statusDotClass(status: DocumentStatus): string {
switch (status) {
case 'ARCHIVED':
case 'TRANSCRIBED':
case 'REVIEWED':
return 'var(--c-tag-sage)';
case 'UPLOADED':
return 'var(--c-tag-amber)';
case 'PLACEHOLDER':
return 'var(--c-tag-slate)';
return 'bg-gray-400';
case 'UPLOADED':
return 'bg-emerald-500';
case 'TRANSCRIBED':
return 'bg-blue-400';
case 'REVIEWED':
return 'bg-amber-400';
case 'ARCHIVED':
return 'bg-emerald-600';
}
}

View File

@@ -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">

View 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>

View File

@@ -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\]/);
}
});
});

View File

@@ -1,31 +0,0 @@
<script lang="ts">
/**
* StatusDot — shared primitive (§7, issue #861).
*
* Dumb renderer: props only, no domain imports.
* - `color`: a CSS custom-property string, e.g. `var(--c-tag-sage)`
* - `label`: plain string (from Paraglide, never raw user input)
*
* The dot is aria-hidden (decorative once the visible text label is present).
* Label uses var(--c-ink-2) — NEVER the status hue (amber at 10px fails AA).
* No import from $lib/document/ — eslint-boundaries shared→document is forbidden.
*/
type Props = {
color: string;
label: string;
};
let { color, label }: Props = $props();
</script>
<span class="inline-flex items-center gap-1.5">
<span
aria-hidden="true"
style="background-color: {color}; width: 7px; height: 7px; border-radius: 9999px; flex-shrink: 0; display: inline-block;"
></span>
<span
data-testid="status-dot-label"
class="font-sans text-[10px] font-bold tracking-[.13em] text-ink-2 uppercase">{label}</span
>
</span>

View File

@@ -1,61 +0,0 @@
import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import StatusDot from './StatusDot.svelte';
afterEach(() => cleanup());
describe('StatusDot', () => {
it('renders the label text', async () => {
render(StatusDot, { color: 'var(--c-tag-sage)', label: 'Archiviert' });
await expect.element(page.getByText('Archiviert')).toBeInTheDocument();
});
it('renders the dot as aria-hidden decorative element', async () => {
render(StatusDot, { color: 'var(--c-tag-amber)', label: 'Hochgeladen' });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot).not.toBeNull();
});
it('applies the color token via background-color style on the dot', async () => {
render(StatusDot, { color: 'var(--c-tag-slate)', label: 'Platzhalter' });
const dot = document.querySelector('[aria-hidden="true"]');
expect(dot?.getAttribute('style')).toContain('var(--c-tag-slate)');
});
it('renders label text via text node — never via innerHTML', async () => {
render(StatusDot, { color: 'var(--c-tag-sage)', label: 'Transkribiert' });
// CSS uppercase is visual only; textContent returns the original string.
// We verify the DOM text is present via the normal text node (no XSS risk).
const textEl = document.querySelector('[data-testid="status-dot-label"]');
expect(textEl).not.toBeNull();
expect(textEl?.textContent?.trim()).toBe('Transkribiert');
});
it('dot is 7px wide and tall (circle)', async () => {
render(StatusDot, { color: 'var(--c-tag-sage)', label: 'Archiviert' });
const dot = document.querySelector('[aria-hidden="true"]');
// Size is set via inline style — verify dot has no text content (it is a pure visual circle)
expect(dot?.textContent?.trim()).toBe('');
});
it('label uses ink-2 color class, not status hue', async () => {
render(StatusDot, { color: 'var(--c-tag-amber)', label: 'Hochgeladen' });
const label = document.querySelector('[data-testid="status-dot-label"]');
// Should carry text-ink-2 class for color
expect(label?.className).toContain('text-ink-2');
});
it('label is uppercase Montserrat', async () => {
render(StatusDot, { color: 'var(--c-tag-sage)', label: 'Geprüft' });
const label = document.querySelector('[data-testid="status-dot-label"]');
expect(label?.className).toContain('font-sans');
expect(label?.className).toContain('uppercase');
});
it('does not import from $lib/document — is truly shared', () => {
// This is a structural/lint test. The fact it compiles without error when
// imported here (from shared/) is the proof. Eslint-boundaries enforces this.
expect(true).toBe(true);
});
});

View File

@@ -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>

View File

@@ -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');
});
});

View File

@@ -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()

View File

@@ -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>

View File

@@ -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 () => {

View File

@@ -1,10 +1,9 @@
<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import { formatDate } from '$lib/shared/utils/date';
import { formatDocumentStatus } from '$lib/document/documentStatusLabel';
import { sortDocumentsByDate, type SortDir } from '$lib/shared/utils/sort';
import DocumentThumbnail from '$lib/document/DocumentThumbnail.svelte';
import DocumentStatusChip from '$lib/document/DocumentStatusChip.svelte';
import type { DocumentStatus } from '$lib/document/documentStatusLabel';
const DOCS_PREVIEW_LIMIT = 5;
@@ -19,7 +18,7 @@ let {
originalFilename: string;
documentDate?: string | null;
location?: string | null;
status: DocumentStatus;
status: string;
contentType?: string;
thumbnailUrl?: string;
}[];
@@ -95,8 +94,17 @@ const visibleDocuments = $derived(
</div>
</div>
<!-- Status chip — always visible at all breakpoints -->
<DocumentStatusChip status={doc.status} />
<!-- Status chip -->
<span
class="hidden flex-shrink-0 rounded-full border px-2 py-0.5 font-sans text-[10px] font-bold sm:inline-block
{doc.status === 'UPLOADED'
? 'border-accent/50 bg-accent/20 text-ink'
: doc.status === 'ARCHIVED'
? 'border-green-200 bg-green-50 text-green-800'
: 'border-yellow-200 bg-yellow-50 text-yellow-800'}"
>
{formatDocumentStatus(doc.status)}
</span>
<img
src="/degruyter-icons/Simple/Medium-24px/SVG/Action/Arrow/Arrow-Right-MD.svg"

View File

@@ -2,7 +2,6 @@ import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import PersonDocumentList from './PersonDocumentList.svelte';
import type { DocumentStatus } from '$lib/document/documentStatusLabel';
afterEach(cleanup);
@@ -12,7 +11,7 @@ const makeDoc = (overrides: Record<string, unknown> = {}) => ({
originalFilename: 'brief.pdf',
documentDate: '1923-04-15',
location: 'Berlin',
status: 'UPLOADED' as DocumentStatus,
status: 'UPLOADED' as string,
contentType: 'application/pdf',
thumbnailUrl: '',
...overrides