flotilla/src/lib/components/ImageIcon.svelte

26 lines
650 B
Svelte
Raw Normal View History

2025-10-31 23:18:58 +00:00
<script lang="ts">
import Icon from "@lib/components/Icon.svelte"
type Props = {
src: string
alt: string
size?: number
class?: string
style?: string
2025-10-31 23:18:58 +00:00
}
const {src, alt, size = 5, style, class: className}: Props = $props()
const rem = size * 0.25
const imgStyle = $derived(
`width: ${rem}rem; height: ${rem}rem; min-width: ${rem}rem; min-height: ${rem}rem${style ? `; ${style}` : ""}`,
)
2025-10-31 23:18:58 +00:00
</script>
{#if src.includes("image/svg") || src.endsWith(".svg")}
<Icon icon={src} {size} {style} class={className} />
2025-10-31 23:18:58 +00:00
{:else}
<img {src} {alt} style={imgStyle} class="aspect-square object-cover {className}" />
2025-10-31 23:18:58 +00:00
{/if}