Skip to content

Commit 718ba29

Browse files
authored
feat(module:qrcode): padding & background color for qrcode (#8001)
* fix(module:qrcode): padding & background color for qrcode * fix(module:qrcode): code refactoring * fix(module:qrcode): code refactoring * fix(module:qrcode): renaming bg color property name * fix(module:qrcode): provide tests
1 parent 10003db commit 718ba29

12 files changed

Lines changed: 166 additions & 31 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 4
3+
title:
4+
zh-CN: 具有自定义背景颜色
5+
en-US: With custom background color
6+
---
7+
8+
## zh-CN
9+
10+
自定义二维码的背景颜色。
11+
12+
## en-US
13+
14+
Customize the background color of the QR Code.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-qr-code-background',
5+
template: `
6+
<nz-qrcode nzBgColor="#ff6600" nzValue="https://ng.ant.design/"></nz-qrcode>
7+
<nz-qrcode nzBgColor="#1677ff" nzValue="https://ng.ant.design/"></nz-qrcode>
8+
`,
9+
styles: [
10+
`
11+
nz-qrcode {
12+
margin-right: 12px;
13+
background-color: #f6f6f6;
14+
}
15+
`
16+
]
17+
})
18+
export class NzDemoQrCodeBackgroundComponent {}

components/qr-code/demo/color.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
order: 3
2+
order: 5
33
title:
44
zh-CN: 自定义颜色
55
en-US: Custom Color

components/qr-code/demo/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
order: 5
2+
order: 7
33
title:
44
zh-CN: 下载二维码
55
en-US: Download QRCode

components/qr-code/demo/error-level.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
order: 4
2+
order: 6
33
title:
44
zh-CN: 容错等级
55
en-US: Error Level

components/qr-code/demo/padding.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 3
3+
title:
4+
zh-CN: 带衬垫
5+
en-US: With padding
6+
---
7+
8+
## zh-CN
9+
10+
自定义 QR 码的填充。
11+
12+
## en-US
13+
14+
Customize the padding of the QR Code.

components/qr-code/demo/padding.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-qr-code-padding',
5+
template: `
6+
<nz-qrcode [nzPadding]="50" nzValue="https://ng.ant.design/"></nz-qrcode>
7+
<nz-qrcode [nzPadding]="[10, 20]" nzValue="https://ng.ant.design/"></nz-qrcode>
8+
`,
9+
styles: [
10+
`
11+
nz-qrcode {
12+
margin-right: 12px;
13+
background-color: #f6f6f6;
14+
}
15+
`
16+
]
17+
})
18+
export class NzDemoQrCodePaddingComponent {}

components/qr-code/doc/index.en-US.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ import { NzQRCodeModule } from 'ng-zorro-antd/qr-code';
1919

2020
### nz-qrcode
2121

22-
| Property | Description | Type | Default |
23-
| -------------- | ----------------------------------- | --------------------------------- | -------- |
24-
| `[nzValue]` | scanned link | `string` | - |
25-
| `[nzColor]` | QR code Color | `string` | `#000` |
26-
| `[nzSize]` | QR code Size | `number` | `160` |
27-
| `[nzIcon]` | Icon address in QR code | `string` | - |
28-
| `[nzIconSize]` | The size of the icon in the QR code | `number` | `40` |
29-
| `[nzBordered]` | Whether has border style | `boolean` | `true` |
30-
| `[nzStatus]` | QR code status | `'active'|'expired' |'loading'` | `active` |
31-
| `[nzLevel]` | Error Code Level | `'L'|'M'|'Q'|'H'` | `M` |
32-
| `(nzRefresh)` | callback | `EventEmitter<string>` | - |
22+
| Property | Description | Type | Default |
23+
|-----------------------|-------------------------------------|---------------------------------|----------|
24+
| `[nzValue]` | scanned link | `string` | - |
25+
| `[nzColor]` | QR code Color | `string` | `#000` |
26+
| `[nzBgColor]` | QR code background color | `string` | `#fff` |
27+
| `[nzSize]` | QR code Size | `number` | `160` |
28+
| `[nzPadding]` | QR code Padding | `number \| number[]` | `10` |
29+
| `[nzIcon]` | Icon address in QR code | `string` | - |
30+
| `[nzIconSize]` | The size of the icon in the QR code | `number` | `40` |
31+
| `[nzBordered]` | Whether has border style | `boolean` | `true` |
32+
| `[nzStatus]` | QR code status | `'active'|'expired' |'loading'` | `active` |
33+
| `[nzLevel]` | Error Code Level | `'L'|'M'|'Q'|'H'` | `M` |
34+
| `(nzRefresh)` | callback | `EventEmitter<string>` | - |
3335

3436
## Note
3537

components/qr-code/doc/index.zh-CN.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ import { NzQRCodeModule } from 'ng-zorro-antd/qr-code';
2020

2121
### nz-qrcode
2222

23-
| 参数 | 说明 | 类型 | 默认值 |
24-
| -------------- | -------------------- | --------------------------------- | -------- |
25-
| `[nzValue]` | 扫描后的地址 | `string` | - |
26-
| `[nzColor]` | 二维码颜色 | `string` | `#000` |
27-
| `[nzSize]` | 二维码大小 | `number` | `160` |
28-
| `[nzIcon]` | 二维码中 icon 地址 | `string` | - |
29-
| `[nzIconSize]` | 二维码中 icon 大小 | `number` | `40` |
30-
| `[nzBordered]` | 是否有边框 | `boolean` | `true` |
31-
| `[nzStatus]` | 二维码状态 | `'active'|'expired' |'loading'` | `active` |
32-
| `[nzLevel]` | 二维码容错等级 | `'L'|'M'|'Q'|'H'` | `M` |
33-
| `(nzRefresh)` | 点击"点击刷新"的回调 | `EventEmitter<string>` | - |
23+
| 参数 | 说明 | 类型 | 默认值 |
24+
| -------------- |--------------|-----------------------------------| -------- |
25+
| `[nzValue]` | 扫描后的地址 | `string` | - |
26+
| `[nzColor]` | 二维码颜色 | `string` | `#000` |
27+
| `[nzBgColor]` | 二维码背景颜色 | `string` | `#fff` |
28+
| `[nzSize]` | 二维码大小 | `number` | `160` |
29+
| `[nzPadding]` | 二维码填充 | `number \| number[]` | `10` |
30+
| `[nzIcon]` | 二维码中 icon 地址 | `string` | - |
31+
| `[nzIconSize]` | 二维码中 icon 大小 | `number` | `40` |
32+
| `[nzBordered]` | 是否有边框 | `boolean` | `true` |
33+
| `[nzStatus]` | 二维码状态 | `'active'|'expired' |'loading'` | `active` |
34+
| `[nzLevel]` | 二维码容错等级 | `'L'|'M'|'Q'|'H'` | `M` |
35+
| `(nzRefresh)` | 点击"点击刷新"的回调 | `EventEmitter<string>` | - |
3436

3537
## 注意
3638

components/qr-code/qrcode.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ import { drawCanvas, ERROR_LEVEL_MAP, plotQRCodeData } from './qrcode';
5555
export class NzQRCodeComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {
5656
@ViewChild('canvas', { static: false }) canvas!: ElementRef<HTMLCanvasElement>;
5757
@Input() nzValue: string = '';
58+
@Input() nzPadding: number | number[] = 10;
5859
@Input() nzColor: string = '#000000';
60+
@Input() nzBgColor: string = '#FFFFFF';
5961
@Input() nzSize: number = 160;
6062
@Input() nzIcon: string = '';
6163
@Input() nzIconSize: number = 40;
@@ -110,7 +112,9 @@ export class NzQRCodeComponent implements OnInit, AfterViewInit, OnChanges, OnDe
110112
plotQRCodeData(this.nzValue, this.nzLevel),
111113
this.nzSize,
112114
10,
115+
this.nzPadding,
113116
this.nzColor,
117+
this.nzBgColor,
114118
this.nzIconSize,
115119
this.nzIcon
116120
);

0 commit comments

Comments
 (0)