summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/CounterButton.svelte
blob: 8024b0ee5398737b8dde282c1fe35c2f771d71a8 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!--
	One [−] icon [total] [+] counter (the reference `CounterButton`): the
	deck-header removable counters (bless/curse/empower/enfeeble) send
	changeBless/Curse/Empower/Enfeeble with `change` ±1 through it.
-->
<script lang="ts">
	let {
		image,
		total,
		maxValue,
		showTotal = true,
		extraImage = null,
		onIncrement,
		onDecrement
	}: {
		/** The counter icon, e.g. `/images/abilities/bless.png`. */
		image: string;
		/** The current total (the deck's removable counter). */
		total: number;
		/** The reference `maxValue` — the plus is disabled at/above it. */
		maxValue: number;
		/** Show the total next to the icon (deck headers do). */
		showTotal?: boolean;
		/** An optional second icon overprinted (two enfeeble owners, …). */
		extraImage?: string | null;
		onIncrement: () => void;
		onDecrement: () => void;
	} = $props();
</script>

<div class="counter" role="group" aria-label={image}>
	<button
		class="counter__btn"
		aria-label="decrease"
		disabled={total <= 0}
		onclick={onDecrement}
	>
		<img src="/images/psd/sub.png" alt="−" />
	</button>

	<div class="counter__icon">
		<img src={image} alt="" />
		{#if extraImage}
			<img class="counter__extra" src={extraImage} alt="" />
		{/if}
		{#if showTotal}
			<span class="counter__total">{total}</span>
		{/if}
	</div>

	<button
		class="counter__btn"
		aria-label="increase"
		disabled={total >= maxValue}
		onclick={onIncrement}
	>
		<img src="/images/psd/add.png" alt="+" />
	</button>
</div>

<style>
	.counter {
		display: flex;
		align-items: center;
		gap: 2px;
	}
	.counter__btn {
		width: 32px;
		height: 32px;
		padding: 2px;
		background: transparent;
		border: none;
		border-radius: 4px;
		cursor: pointer;
	}
	.counter__btn:hover:not(:disabled) {
		background: rgba(255, 255, 255, 0.15);
	}
	.counter__btn:disabled {
		opacity: 0.35;
		cursor: default;
	}
	.counter__btn img {
		width: 100%;
		height: 100%;
		filter: brightness(0) invert(1);
	}
	.counter__icon {
		position: relative;
		width: 32px;
		height: 32px;
	}
	.counter__icon > img {
		width: 100%;
		height: 100%;
		object-fit: contain;
	}
	.counter__extra {
		position: absolute;
		inset: 0;
		opacity: 0.55;
	}
	.counter__total {
		position: absolute;
		inset: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
		font-weight: 700;
		color: #fff;
		text-shadow: 1px 1px 1px #000;
		pointer-events: none;
	}
</style>