aboutsummaryrefslogtreecommitdiff
path: root/src/tools/qr-code-generator/useQRCode.ts
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-08-24 00:09:59 +0200
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-08-24 00:18:01 +0200
commit7de6c86f9ead8d7315614cc508dfee4fed90e9c2 (patch)
tree856b6d2184668146da2d631b90e7cbbc45652adf /src/tools/qr-code-generator/useQRCode.ts
parent83da6b7ee9db29e40faf288f9627257aa7124038 (diff)
downloadit-tools-7de6c86f9ead8d7315614cc508dfee4fed90e9c2.tar.gz
it-tools-7de6c86f9ead8d7315614cc508dfee4fed90e9c2.tar.zst
it-tools-7de6c86f9ead8d7315614cc508dfee4fed90e9c2.zip
refactor(useQRCode): switched args to MaybeRef
Diffstat (limited to 'src/tools/qr-code-generator/useQRCode.ts')
-rw-r--r--src/tools/qr-code-generator/useQRCode.ts21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/tools/qr-code-generator/useQRCode.ts b/src/tools/qr-code-generator/useQRCode.ts
index 38a9d31..44b72a7 100644
--- a/src/tools/qr-code-generator/useQRCode.ts
+++ b/src/tools/qr-code-generator/useQRCode.ts
@@ -1,5 +1,6 @@
+import { get, type MaybeRef } from '@vueuse/core';
import QRCode, { type QRCodeErrorCorrectionLevel, type QRCodeToDataURLOptions } from 'qrcode';
-import { ref, watch, type Ref } from 'vue';
+import { ref, watch, isRef } from 'vue';
export function useQRCode({
text,
@@ -7,24 +8,24 @@ export function useQRCode({
errorCorrectionLevel,
options,
}: {
- text: Ref<string>;
- color: { foreground: Ref<string>; background: Ref<string> };
- errorCorrectionLevel: Ref<QRCodeErrorCorrectionLevel>;
+ text: MaybeRef<string>;
+ color: { foreground: MaybeRef<string>; background: MaybeRef<string> };
+ errorCorrectionLevel?: MaybeRef<QRCodeErrorCorrectionLevel>;
options?: QRCodeToDataURLOptions;
}) {
const qrcode = ref('');
watch(
- [text, background, foreground, errorCorrectionLevel],
+ [text, background, foreground, errorCorrectionLevel].filter(isRef),
async () => {
- if (text.value)
- qrcode.value = await QRCode.toDataURL(text.value, {
+ if (get(text))
+ qrcode.value = await QRCode.toDataURL(get(text), {
color: {
- dark: foreground.value,
- light: background.value,
+ dark: get(foreground),
+ light: get(background),
...options?.color,
},
- errorCorrectionLevel: errorCorrectionLevel.value,
+ errorCorrectionLevel: get(errorCorrectionLevel) ?? 'M',
...options,
});
},