MapComplete/src/UI/Base/ShareButton.svelte

34 lines
883 B
Svelte
Raw Normal View History

2023-05-11 17:29:25 +02:00
<script lang="ts">
import ToSvelte from "./ToSvelte.svelte"
import Svg from "../../Svg"
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
}
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>
<button on:click={share} class="soft no-image-background m-0 h-8 w-8 p-0" use:ariaLabel={Translations.t.general.share}>
<slot name="content">
2023-12-01 15:23:28 +01:00
<Share class="h-7 w-7 p-1" />
</slot>
2023-05-11 17:29:25 +02:00
</button>