-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: cleanup QR * fix: remove unnecessary styles * fix * styles: center qr in its container * chore: cleanup code --------- Co-authored-by: Begoña Álvarez de la Cruz <[email protected]> Co-authored-by: JCNoguera <[email protected]> Co-authored-by: Jean Carlo Noguera <[email protected]>
- Loading branch information
1 parent
be2c429
commit f8df16f
Showing
3 changed files
with
10 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,26 @@ | ||
<script lang="ts"> | ||
import { default as QrCode } from 'qrious' | ||
import { appSettings } from '@core/app' | ||
import { onMount } from 'svelte' | ||
import { default as QrCode } from 'qrious' | ||
export let data: string | ||
export let classes: string = '' | ||
$: color = $appSettings.darkMode ? '#ffffff' : '#000000' | ||
$: data && generateQrCode() | ||
const QRcode = new QrCode() | ||
let image = '' | ||
const qrCode = new QrCode() | ||
let qrImage = '' | ||
function generateQrCode(): void { | ||
QRcode.set({ | ||
qrCode.set({ | ||
background: '#ffffff00', | ||
foreground: color, | ||
level: 'L', | ||
padding: 0, | ||
size: 200, // if this value is changed, the image gets some weird padding. Therefore we need to do the sizing with css | ||
size: 135, | ||
value: data, | ||
}) | ||
image = QRcode.toDataURL('image/png') | ||
} | ||
$: if (data) { | ||
generateQrCode() | ||
qrImage = qrCode.toDataURL('image/png') | ||
} | ||
onMount((): void => { | ||
generateQrCode() | ||
}) | ||
</script> | ||
|
||
<div class="flex justify-center {classes}"> | ||
<img src={image} alt={data} class="qrcode" /> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.qrcode { | ||
width: 135px; | ||
height: 135px; | ||
} | ||
</style> | ||
<img src={qrImage} alt={data} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters