flotilla/src/app/components/RelayIcon.svelte

32 lines
881 B
Svelte
Raw Normal View History

<script lang="ts">
import ImageIcon from "@lib/components/ImageIcon.svelte"
2026-07-28 16:16:26 +00:00
import {relays} from "@app/core"
import {relayIconColor, relayIconInitials} from "@app/relays"
type Props = {
url: string
size?: number
class?: string
}
const {url, size = 7, ...props}: Props = $props()
2026-07-28 16:16:26 +00:00
const relay = $relays.one(url)
const rem = $derived(size * 0.25)
const fallbackStyle = $derived(
`width: ${rem}rem; height: ${rem}rem; min-width: ${rem}rem; min-height: ${rem}rem; font-size: ${rem * 0.4}rem; background-color: ${relayIconColor(url)}; color: white`,
)
</script>
2026-01-16 22:17:38 +00:00
{#if $relay?.icon}
2026-08-28 00:08:36 +00:00
<ImageIcon {size} alt="" src={$relay?.icon} class="rounded-full {props.class}" />
2026-01-16 22:17:38 +00:00
{:else}
<div
class="flex select-none items-center justify-center rounded-full font-bold {props.class}"
style={fallbackStyle}>
{relayIconInitials(url)}
</div>
2026-01-16 22:17:38 +00:00
{/if}