summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/CounterButton.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/CounterButton.svelte')
-rw-r--r--web/src/lib/ui/CounterButton.svelte115
1 files changed, 115 insertions, 0 deletions
diff --git a/web/src/lib/ui/CounterButton.svelte b/web/src/lib/ui/CounterButton.svelte
new file mode 100644
index 0000000..8024b0e
--- /dev/null
+++ b/web/src/lib/ui/CounterButton.svelte
@@ -0,0 +1,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>