Files
beavergram/frontend/src/lib/components/Location.svelte
T

68 lines
1.4 KiB
Svelte

<script lang="ts">
import type { LocationView } from "#lib/api/types.js";
interface Props {
location: LocationView;
}
let { location }: Props = $props();
const hasCoords = $derived(
location.latitude !== null && location.longitude !== null
);
const mapUrl = $derived(
hasCoords
? `https://www.openstreetmap.org/?mlat=${location.latitude}&mlon=${location.longitude}#map=16/${location.latitude}/${location.longitude}`
: null
);
const title = $derived(location.title ?? "Location");
</script>
<svelte:element
class="Location"
href={mapUrl}
rel={mapUrl ? "noopener" : undefined}
target={mapUrl ? "_blank" : undefined}
this={mapUrl ? "a" : "div"}
>
<span class="pin">📍</span>
<div class="info">
<div class="title">{title}</div>
{#if location.address}
<div class="address">{location.address}</div>
{/if}
{#if hasCoords}
<div class="coords">{location.latitude}, {location.longitude}</div>
{/if}
</div>
</svelte:element>
<style lang="scss">
.Location {
display: flex;
align-items: center;
gap: 0.5rem;
min-width: 12rem;
margin-bottom: 0.25rem;
color: inherit;
text-decoration: none;
}
.pin {
font-size: 1.5rem;
line-height: 1;
}
.title {
font-weight: var(--font-weight-medium);
}
.address,
.coords {
font-size: 0.875rem;
color: var(--color-text-secondary);
}
</style>