nicco.io/src/lib/components/Icon.svelte

36 lines
603 B
Svelte
Raw Normal View History

2021-08-02 09:53:08 +02:00
<script lang="ts">
2021-04-21 13:31:33 +02:00
import { onMount } from 'svelte'
2021-08-02 09:53:08 +02:00
export let icon: string
2021-04-21 13:31:33 +02:00
$: src = `/icons/${icon}.svg`
2021-08-02 09:53:08 +02:00
let html: string | null = null
2021-04-21 13:31:33 +02:00
onMount(async () => {
html = await fetch(src).then((res) => res.text())
})
2021-03-06 23:10:17 +01:00
</script>
2021-04-21 13:31:33 +02:00
{#if html === null}
<img {...$$restProps} {src} alt={icon} />
{:else}
<span {...$$restProps}>
{@html html}
</span>
{/if}
2021-03-06 23:10:17 +01:00
<style>
2021-04-21 13:31:33 +02:00
span,
2021-03-06 23:10:17 +01:00
img {
display: inline-block;
width: 1em;
height: 1em;
contain: strict;
box-sizing: content-box;
transform: translateY(0.2em);
}
2021-04-21 13:31:33 +02:00
span > :global(svg) {
display: block;
}
2021-03-06 23:10:17 +01:00
</style>