aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Qr.svelte
blob: 1fe4a84d4b4753e8e993d9e57cda887fccebff91 (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
<script>
  import { onMount } from "svelte";
  import { browser } from "$app/environment";
  let { icon, text } = $props();
  let qr = $state();
  let screenfull;

  onMount(async () => {
    if (!browser) return;
    screenfull = (await import("screenfull")).default;
  });

  let src = $derived(() => {
    let url = `/qr/${encodeURIComponent(text)}`;
    if (icon) url += `/${icon}`;
    else url += "/raw";
    return url;
  });
</script>

<div
  class="w-72 sm:w-80 mx-auto cursor-pointer"
  bind:this={qr}
  onclick={() => screenfull?.toggle?.(qr)}
  onkeydown={(e) =>
    (e.key === "Enter" || e.key === " ") && screenfull?.toggle?.(qr)}
  role="button"
  tabindex="0"
  aria-label="Toggle fullscreen QR"
>
  <img {src} class="mx-auto" alt="QR Code" />
</div>