2023-05-11 17:29:25 +02:00
|
|
|
<script lang="ts">
|
2023-06-14 20:39:36 +02:00
|
|
|
import ToSvelte from "./ToSvelte.svelte"
|
|
|
|
import Svg from "../../Svg"
|
2023-05-11 17:29:25 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
export let generateShareData: () => {
|
2023-05-11 17:29:25 +02:00
|
|
|
text: string
|
|
|
|
title: string
|
|
|
|
url: string
|
2023-06-14 20:39:36 +02:00
|
|
|
}
|
|
|
|
function share() {
|
2023-05-11 17:29:25 +02:00
|
|
|
if (!navigator.share) {
|
2023-06-14 20:39:36 +02:00
|
|
|
console.log("web share not supported")
|
|
|
|
return
|
2023-05-11 17:29:25 +02:00
|
|
|
}
|
|
|
|
navigator
|
2023-06-14 20:39:36 +02:00
|
|
|
.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-06-14 20:44:01 +02:00
|
|
|
<button on:click={share} class="secondary m-0 h-8 w-8 p-0">
|
2023-06-14 20:39:36 +02:00
|
|
|
<slot name="content">
|
|
|
|
<ToSvelte construct={Svg.share_svg().SetClass("w-7 h-7 p-1")} />
|
|
|
|
</slot>
|
2023-05-11 17:29:25 +02:00
|
|
|
</button>
|