feat(tool): qr-code generator

This commit is contained in:
Corentin Thomasset 2022-04-14 18:18:15 +02:00
parent 203b6a9d73
commit 5582d75927
No known key found for this signature in database
GPG key ID: 3103EB5E79496F9C
8 changed files with 527 additions and 21 deletions

View file

@ -0,0 +1,35 @@
import QRCode, { type QRCodeErrorCorrectionLevel, type QRCodeToDataURLOptions } from 'qrcode';
import { ref, watch, type Ref } from 'vue';
export function useQRCode({
text,
color: { background, foreground },
errorCorrectionLevel,
options,
}: {
text: Ref<string>;
color: { foreground: Ref<string>; background: Ref<string> };
errorCorrectionLevel: Ref<QRCodeErrorCorrectionLevel>;
options?: QRCodeToDataURLOptions;
}) {
const qrcode = ref('');
watch(
[text, background, foreground, errorCorrectionLevel],
async () => {
if (text.value)
qrcode.value = await QRCode.toDataURL(text.value, {
color: {
dark: foreground.value,
light: background.value,
...options?.color,
},
errorCorrectionLevel: errorCorrectionLevel.value,
...options,
});
},
{ immediate: true }
);
return { qrcode };
}