MapComplete/src/UI/Base/ShareButton.svelte

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

46 lines
1 KiB
Svelte
Raw Normal View History

2023-05-11 17:29:25 +02:00
<script lang="ts">
2023-12-01 15:23:28 +01:00
import Share from "../../assets/svg/Share.svelte"
import { ariaLabel } from "../../Utils/ariaLabel"
import Translations from "../i18n/Translations"
2023-05-11 17:29:25 +02:00
export let generateShareData: () => {
2023-05-11 17:29:25 +02:00
text: string
title: string
url: string
}
2023-12-25 23:55:52 +01:00
export let text: string
let isIcon = text === undefined || text === ""
function share() {
2023-05-11 17:29:25 +02:00
if (!navigator.share) {
console.log("web share not supported")
return
2023-05-11 17:29:25 +02:00
}
navigator
.share(generateShareData())
.then(() => {
console.log("Thanks for sharing!")
})
.catch((err) => {
console.log(`Couldn't share because of`, err.message)
})
}
2023-05-11 17:29:25 +02:00
</script>
2023-12-25 23:55:52 +01:00
{#if isIcon}
2023-12-30 15:24:30 +01:00
<button
on:click={share}
class="soft no-image-background m-0 h-8 w-8 p-0"
use:ariaLabel={Translations.t.general.share}
>
2023-12-25 23:55:52 +01:00
<slot name="content">
<Share class="h-7 w-7 p-1" />
</slot>
</button>
{:else}
<button on:click={share}>
<Share class="h-8 w-8 pr-2" />
{text}
</button>
{/if}