feat(web): add StatusPill semantic-color status indicator
Single-prop component mapping LidarrRequestStatus to voice-rule labels and semantic tones (warning/info/success/error). Used by /requests and /admin/requests in subsequent tasks.
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
<script lang="ts" module>
|
||||||
|
import type { LidarrRequestStatus } from '$lib/api/types';
|
||||||
|
|
||||||
|
type Tone = 'warning' | 'info' | 'success' | 'error';
|
||||||
|
|
||||||
|
type StatusEntry = { label: string; tone: Tone };
|
||||||
|
|
||||||
|
// Voice-rule labels per spec §6 (and project_design_system.md). Pending requests
|
||||||
|
// are an "awaiting" moment, completed requests are "kept" (Minstrel-voice for
|
||||||
|
// success), rejected is "set aside", failed is the error register.
|
||||||
|
const STATUS_TABLE: Record<LidarrRequestStatus, StatusEntry> = {
|
||||||
|
pending: { label: 'Awaiting review', tone: 'warning' },
|
||||||
|
approved: { label: 'Approved · downloading', tone: 'info' },
|
||||||
|
completed: { label: 'Kept', tone: 'success' },
|
||||||
|
rejected: { label: 'Set aside', tone: 'error' },
|
||||||
|
failed: { label: "Couldn't add", tone: 'error' },
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
let { status }: { status: LidarrRequestStatus } = $props();
|
||||||
|
|
||||||
|
const entry = $derived(STATUS_TABLE[status]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<span class="pill" data-tone={entry.tone} data-status={status}>{entry.label}</span>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.pill[data-tone='warning'] {
|
||||||
|
background: color-mix(in srgb, var(--fs-warning) 15%, transparent);
|
||||||
|
color: var(--fs-warning);
|
||||||
|
}
|
||||||
|
.pill[data-tone='info'] {
|
||||||
|
background: color-mix(in srgb, var(--fs-info) 15%, transparent);
|
||||||
|
color: var(--fs-info);
|
||||||
|
}
|
||||||
|
.pill[data-tone='success'] {
|
||||||
|
background: color-mix(in srgb, var(--fs-moss) 15%, transparent);
|
||||||
|
color: var(--fs-moss);
|
||||||
|
}
|
||||||
|
.pill[data-tone='error'] {
|
||||||
|
background: color-mix(in srgb, var(--fs-error) 15%, transparent);
|
||||||
|
color: var(--fs-error);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
import StatusPill from './StatusPill.svelte';
|
||||||
|
|
||||||
|
// Voice-rule labels and semantic tones per spec §6 / project_design_system.md.
|
||||||
|
// Each row is the contract: input status -> rendered label + data-tone attr.
|
||||||
|
const CASES = [
|
||||||
|
{ status: 'pending', label: 'Awaiting review', tone: 'warning' },
|
||||||
|
{ status: 'approved', label: 'Approved · downloading', tone: 'info' },
|
||||||
|
{ status: 'completed', label: 'Kept', tone: 'success' },
|
||||||
|
{ status: 'rejected', label: 'Set aside', tone: 'error' },
|
||||||
|
{ status: 'failed', label: "Couldn't add", tone: 'error' },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
describe('StatusPill', () => {
|
||||||
|
for (const { status, label, tone } of CASES) {
|
||||||
|
test(`${status} renders "${label}" with tone=${tone}`, () => {
|
||||||
|
render(StatusPill, { props: { status } });
|
||||||
|
const pill = screen.getByText(label);
|
||||||
|
expect(pill).toBeInTheDocument();
|
||||||
|
expect(pill.getAttribute('data-tone')).toBe(tone);
|
||||||
|
expect(pill.getAttribute('data-status')).toBe(status);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user