aboutsummaryrefslogtreecommitdiff
path: root/src/lib/components/StatusBadge.svelte
blob: 2bbdf5a5e2b317a840093ab4a2f5eee8801a9f51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

<script lang="ts">
	import {
		STATUS_LABELS,
		type RoutineStatus,
	} from '$lib/shared/routine-metrics';

	let {
		status,
		overdueDays = 0,
	}: { status: RoutineStatus; overdueDays?: number } = $props();

	const icon = $derived(
		status === 'ok'
			? '✓'
			: status === 'due'
				? '◷'
				: status === 'late'
					? '!'
					: '‼',
	);

	const label = $derived(
		overdueDays > 0
			? `${STATUS_LABELS[status]} (${overdueDays} j)`
			: STATUS_LABELS[status],
	);
</script>

<span class="status {status}" role="img" aria-label={label} title={label}
	>{icon}</span
>

<style>
	.status {
		flex-shrink: 0;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 1.5rem;
		height: 1.5rem;
		border-radius: 0.375rem;
		font-size: 0.875rem;
		font-weight: 700;
		line-height: 1;
	}

	.ok {
		background: var(--success);
		color: var(--white);
	}

	.due {
		background: var(--shadow-accent);
		color: var(--accent);
	}

	.late {
		background: var(--accent);
		color: var(--white);
	}

	.veryLate {
		background: var(--danger);
		color: var(--white);
	}
</style>