feat(shared): add StatusDot primitive — 7px dot + UPPERCASE label, 3 semantic tokens (§7)
Refs #861 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
31
frontend/src/lib/shared/primitives/StatusDot.svelte
Normal file
31
frontend/src/lib/shared/primitives/StatusDot.svelte
Normal file
@@ -0,0 +1,31 @@
|
||||
<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>
|
||||
61
frontend/src/lib/shared/primitives/StatusDot.svelte.spec.ts
Normal file
61
frontend/src/lib/shared/primitives/StatusDot.svelte.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user