qr code add copy to clipboard button

pull/3/head
TZGyn 2 years ago
parent b179404057
commit f4b64ff3b8
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,19 +1,39 @@
<script>
import { onMount } from 'svelte'
import { default as QrCode } from 'qrious'
import Button from './ui/button/button.svelte'
const QRcode = new QrCode()
export let errorCorrection = 'L'
export let background = '#fff'
export let color = '#000'
export let size = '500'
export let size = '300'
export let value = ''
export let padding = 10
export let className = 'qrcode'
let image = ''
const copyImageToClipboard = async () => {
if (!image) return
console.log(image)
const imageData = await fetch(image)
const imageBlob = await imageData.blob()
try {
navigator.clipboard.write([
new ClipboardItem({
'image/png': imageBlob,
}),
])
} catch (error) {
console.error(error)
}
}
function generateQrCode() {
QRcode.set({
background,
@ -24,7 +44,7 @@
value,
})
image = QRcode.toDataURL('image/jpeg')
image = QRcode.toDataURL()
}
export function getImage() {
@ -43,3 +63,4 @@
</script>
<img src={image} alt={value} class={className} />
<Button on:click={copyImageToClipboard}>Copy To Clipboard</Button>

@ -286,7 +286,7 @@
Use this QR code to share the shortener.
</Dialog.Description>
</Dialog.Header>
<div class="flex h-64 justify-center">
<div class="flex h-full flex-col items-center gap-4">
<Qr value={data.shortener_url + '/' + qrCode} />
</div>
</Dialog.Content>

Loading…
Cancel
Save