Skip to content

Commit 4eef086

Browse files
committed
add: height and width to QRCodeSVG
1 parent 459fe6b commit 4eef086

File tree

3 files changed

+44
-319
lines changed

3 files changed

+44
-319
lines changed

src/QRCodeSVG.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type RectsMapItemType = {
3030
export type OptionsType = ParentOptionsType & {
3131
fgColor: string;
3232
bgColor?: string;
33+
width?: number;
34+
height?: number;
3335
};
3436

3537
const DEFAULT_OPTIONS = {
@@ -41,6 +43,8 @@ export default class QRCodeSVG extends AbstractQRCodeWithImage {
4143
fgColor: string;
4244
bgColor: string;
4345
qrCodeSVG: string | null = null;
46+
height?: number;
47+
width?: number;
4448
qrCodeDataUrl: string | null = null;
4549

4650
constructor(value: string, options: Partial<OptionsType> = {}) {
@@ -49,6 +53,8 @@ export default class QRCodeSVG extends AbstractQRCodeWithImage {
4953

5054
this.fgColor = params.fgColor;
5155
this.bgColor = params.bgColor;
56+
this.width = params.width;
57+
this.height = params.height;
5258
}
5359

5460
_clearCache(): void {
@@ -201,7 +207,9 @@ export default class QRCodeSVG extends AbstractQRCodeWithImage {
201207
const size = this.getDataSize();
202208
const tags = [
203209
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" ' +
204-
`shape-rendering="crispEdges" viewBox="0 0 ${size} ${size}">`,
210+
`shape-rendering="crispEdges" viewBox="0 0 ${size} ${size}"${
211+
this.width ? ` width=${this.width}` : ''
212+
}${this.height ? ` height=${this.height}` : ''} >`,
205213
];
206214

207215
if (this.bgColor) {

0 commit comments

Comments
 (0)