Skip to content

Commit

Permalink
Add white margin to QR code image (#938)
Browse files Browse the repository at this point in the history
* Switch collect qr to composition api

* add 15px white border to qr code image
  • Loading branch information
ktuite authored Feb 9, 2024
1 parent b92a672 commit 17c29f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
60 changes: 35 additions & 25 deletions src/components/collect-qr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,44 @@ except according to the terms contained in the LICENSE file.
</template>
<!-- eslint-enable vue/no-v-html -->

<script>
<script setup>
import { computed } from 'vue';
import qrcode from 'qrcode-generator';
import pako from 'pako/lib/deflate';

export default {
name: 'CollectQr',
props: {
settings: {
type: Object,
required: true
},
errorCorrectionLevel: {
type: String,
required: true
},
cellSize: {
type: Number,
required: true
}
defineOptions({
name: 'CollectQr'
});

const props = defineProps({
settings: {
type: Object,
required: true
},
errorCorrectionLevel: {
type: String,
required: true
},
computed: {
imgHtml() {
const code = qrcode(0, this.errorCorrectionLevel);
const json = JSON.stringify(this.settings);
code.addData(btoa(pako.deflate(json, { to: 'string' })));
code.make();
return code.createImgTag(this.cellSize, 0);
}
cellSize: {
type: Number,
required: true
}
};
});

const imgHtml = computed(() => {
const code = qrcode(0, props.errorCorrectionLevel);
const json = JSON.stringify(props.settings);
code.addData(btoa(pako.deflate(json, { to: 'string' })));
code.make();
return code.createImgTag(props.cellSize, 15);
});

</script>

<style lang="scss">

.collect-qr img {
margin: -15px;
}

</style>
2 changes: 1 addition & 1 deletion test/components/collect-qr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ describe('CollectQr', () => {
10
);

width2.should.equal(2 * width1);
width2.should.equal(2 * (width1 - 15)); // remove negative padding
});
});

0 comments on commit 17c29f7

Please sign in to comment.