MapComplete/src/UI/BigComponents/ExtraLinkButton.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.7 KiB
Svelte
Raw Normal View History

<script lang="ts">
import ExtraLinkConfig from "../../Models/ThemeConfig/ExtraLinkConfig"
import Locale from "../i18n/Locale"
import { Utils } from "../../Utils"
import Translations from "../i18n/Translations"
import type { SpecialVisualizationState } from "../SpecialVisualization"
import Pop_out from "../../assets/svg/Pop_out.svelte"
import Tr from "../Base/Tr.svelte"
import Icon from "../Map/Icon.svelte"
export let state: SpecialVisualizationState
let theme = state.theme?.id ?? ""
let config: ExtraLinkConfig = state.theme.extraLink
let basepath = window.location.host
let showWelcomeMessageSwitch = state.featureSwitches.featureSwitchWelcomeMessage
const isIframe = Utils.isIframe
const t = Translations.t.general
const href = state.mapProperties.location.map(
(loc) => {
const subs = {
...loc,
theme: theme,
basepath,
2024-06-16 16:06:26 +02:00
language: Locale.language.data,
}
return Utils.SubstituteKeys(config.href, subs)
},
[state.mapProperties.zoom]
)
</script>
2024-06-16 16:06:26 +02:00
{#if config !== undefined && !(config.requirements.has("iframe") && !isIframe) && !(config.requirements.has("no-iframe") && isIframe) && !(config.requirements.has("welcome-message") && !$showWelcomeMessageSwitch) && !(config.requirements.has("no-welcome-message") && $showWelcomeMessageSwitch)}
<div class="links-as-button">
<a
href={$href}
target={config.newTab ? "_blank" : ""}
rel="noopener"
class="button pointer-events-auto flex rounded-full border-black"
2024-06-16 16:06:26 +02:00
>
<Icon icon={config.icon} clss="w-6 h-6 m-2" />
{#if config.text}
<Tr t={config.text} />
{:else}
<Tr t={t.screenToSmall.Subs({ theme: state.theme.title })} />
2024-06-16 16:06:26 +02:00
{/if}
</a>
</div>
{/if}