refactor: remove icon toggle functionality and simplify QR code component

This commit is contained in:
MinerAle 2025-02-27 08:29:35 +01:00
parent 1d04e199ce
commit 9a9975c6a9

View file

@ -1,6 +1,6 @@
<script setup> <script setup>
import { Button, Switch } from '#components' import { Button } from '#components'
import { Download, Palette } from 'lucide-vue-next' import { Download } from 'lucide-vue-next'
import QRCodeStyling from 'qr-code-styling' import QRCodeStyling from 'qr-code-styling'
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
@ -14,8 +14,6 @@ const props = defineProps({
default: '', default: '',
}, },
}) })
const showIcon = ref(true)
const color = ref('#000000') const color = ref('#000000')
const options = { const options = {
width: 256, width: 256,
@ -23,12 +21,7 @@ const options = {
data: props.data, data: props.data,
margin: 10, margin: 10,
qrOptions: { typeNumber: '0', mode: 'Byte', errorCorrectionLevel: 'Q' }, qrOptions: { typeNumber: '0', mode: 'Byte', errorCorrectionLevel: 'Q' },
imageOptions: { imageOptions: { hideBackgroundDots: true, imageSize: 0.4, margin: 2 },
hideBackgroundDots: true,
imageSize: 0.3,
margin: 0,
crossOrigin: 'anonymous',
},
dotsOptions: { type: 'dots', color: '#000000', gradient: null }, dotsOptions: { type: 'dots', color: '#000000', gradient: null },
backgroundOptions: { color: '#ffffff', gradient: null }, backgroundOptions: { color: '#ffffff', gradient: null },
image: props.image, image: props.image,
@ -79,16 +72,6 @@ const options = {
const qrCode = new QRCodeStyling(options) const qrCode = new QRCodeStyling(options)
const qrCodeEl = ref(null) const qrCodeEl = ref(null)
function updateIcon(show) {
qrCode.update({
image: show ? props.image : '',
})
}
watch(showIcon, (show) => {
updateIcon(show)
})
function updateColor(newColor) { function updateColor(newColor) {
qrCode.update({ qrCode.update({
dotsOptions: { type: 'dots', color: newColor, gradient: null }, dotsOptions: { type: 'dots', color: newColor, gradient: null },
@ -111,7 +94,6 @@ function downloadQRCode() {
onMounted(() => { onMounted(() => {
qrCode.append(qrCodeEl.value) qrCode.append(qrCodeEl.value)
updateIcon(showIcon.value)
}) })
</script> </script>
@ -121,26 +103,24 @@ onMounted(() => {
ref="qrCodeEl" ref="qrCodeEl"
:data-text="data" :data-text="data"
/> />
<div class="flex items-center gap-4"> <div class="flex items-center gap-2">
<div class="flex items-center gap-2"> <div class="relative flex items-center">
<div class="flex items-center gap-2 px-3 py-2 border rounded-md"> <div
<Palette class="w-4 h-4" /> class="w-8 h-8 rounded-full border cursor-pointer overflow-hidden"
:style="{ backgroundColor: color }"
>
<input <input
v-model="color" v-model="color"
type="color" type="color"
class="w-20 h-8 rounded cursor-pointer" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
title="Change QR code color" title="Change QR code color"
> >
</div> </div>
<Button variant="outline" @click="downloadQRCode">
<Download class="w-4 h-4 mr-2" />
Download QR Code
</Button>
</div>
<div class="flex items-center gap-2">
<span class="text-sm text-gray-500">Icon</span>
<Switch v-model="showIcon" />
</div> </div>
<Button variant="outline" @click="downloadQRCode">
<Download class="w-4 h-4 mr-2" />
Download QR Code
</Button>
</div> </div>
</div> </div>
</template> </template>