Skip to content

Commit

Permalink
qr-generator: Improve download buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jul 10, 2024
1 parent 01554a8 commit 17c6291
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/lib/components/action-card-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
export let icon = undefined;
export let label;
export let href;
export let href = null;
export let tooltip = undefined;
export let enabled = true;
</script>

<li>
{#if !href}
{#if href === null}
<button
class="action-card-item"
class:disabled={!enabled}
on:click
title={ tooltip }
use:tooltipAction={{ position: "left" }}
Expand All @@ -23,6 +25,7 @@
{:else}
<a
class="action-card-item"
class:disabled={!enabled}
{href}
on:click
title={ tooltip }
Expand All @@ -49,6 +52,11 @@
font-size: 0.85rem;
}
.action-card-item.disabled {
opacity: 0.5;
cursor: default;
}
.action-card-item:hover {
background: var(--action-card-hover);
}
Expand Down
25 changes: 9 additions & 16 deletions src/routes/qr-generator/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import WarningBox from "$lib/components/warning-box.svelte";
import TextArea from "$lib/components/input/text-area.svelte";
import ActionCard from "$lib/components/action-card.svelte";
import ActionCardItem from "$lib/components/action-card-item.svelte";
import FileCodeOutline from "svelte-material-icons/FileCodeOutline.svelte";
import FilePngBox from "svelte-material-icons/FilePngBox.svelte";
import FileJpgBox from "svelte-material-icons/FileJpgBox.svelte";
import StackView from "$lib/components/stack-view.svelte";
import QrDownloadButton from "./qr-download-button.svelte";
let errorMessage = "";
let data = "https://eliandoran.github.io/toolkit/";
Expand Down Expand Up @@ -42,6 +42,10 @@
function rebuildQr(...args) {
key = {};
svgDownloadUrl = "";
pngDownloadUrl = "";
jpgDownloadUrl = "";
webpDownloadUrl = "";
}
function onQrCodeGenerated() {
Expand Down Expand Up @@ -239,21 +243,10 @@

<div class="actions">
<ActionCard columns="always">
{#if svgDownloadUrl}
<ActionCardItem label="Download as SVG" href={svgDownloadUrl} icon={FileCodeOutline} download _target="blank" />
{/if}

{#if pngDownloadUrl}
<ActionCardItem label="Download as PNG" href={pngDownloadUrl} icon={FilePngBox} download _target="blank" />
{/if}

{#if jpgDownloadUrl}
<ActionCardItem label="Download as JPEG" href={jpgDownloadUrl} icon={FileJpgBox} download _target="blank" />
{/if}

{#if webpDownloadUrl}
<ActionCardItem label="Download as WebP" href={webpDownloadUrl} download _target="blank" />
{/if}
<QrDownloadButton extension="SVG" url={svgDownloadUrl} icon={FileCodeOutline} />
<QrDownloadButton extension="PNG" url={pngDownloadUrl} icon={FilePngBox} />
<QrDownloadButton extension="JPEG" url={jpgDownloadUrl} icon={FileJpgBox} />
<QrDownloadButton extension="WebP" url={webpDownloadUrl} />
</ActionCard>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions src/routes/qr-generator/qr-download-button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import ActionCardItem from "$lib/components/action-card-item.svelte";
export let url = null;
export let icon = null;
export let extension;
</script>

<ActionCardItem
label="Download as {extension}"
href={url}
icon={icon}
download _target="blank" />

0 comments on commit 17c6291

Please sign in to comment.