cryptgeon/client/src/lib/ui/Icon.svelte

35 lines
574 B
Svelte
Raw Normal View History

2021-05-02 03:08:30 +02:00
<script lang="ts">
import { onMount } from 'svelte'
2021-05-03 11:10:53 +02:00
export let icon: string = ''
export let href: string = ''
2021-05-02 03:08:30 +02:00
2021-05-03 11:10:53 +02:00
$: src = href || `/icons/${icon}.svg`
2021-05-02 03:08:30 +02:00
let html = null
onMount(async () => {
html = await fetch(src).then((res) => res.text())
})
</script>
{#if html === null}
<img on:click {...$$restProps} {src} alt={icon} />
{:else}
<div on:click {...$$restProps}>
{@html html}
</div>
{/if}
<style>
img,
div {
display: inline-block;
contain: strict;
box-sizing: content-box;
}
div > :global(svg) {
display: block;
fill: currentColor;
}
</style>