• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-webcomponents / 26950945697

04 Jun 2026 12:12PM UTC coverage: 98.389% (+0.05%) from 98.337%
26950945697

Pull #2242

github

web-flow
Merge b79ea6de0 into 989edd66d
Pull Request #2242: feat: Added QR code component with encoding and rendering capabilities

6144 of 6451 branches covered (95.24%)

Branch coverage included in aggregate %.

2480 of 2491 new or added lines in 8 files covered. (99.56%)

7 existing lines in 1 file now uncovered.

43941 of 44454 relevant lines covered (98.85%)

1704.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.88
/src/components/qr-code/qr-code.ts
1
import { css, html, LitElement, nothing, svg } from 'lit';
8✔
2
import { property } from 'lit/decorators.js';
8✔
3
import { registerComponent } from '../common/definitions/register.js';
8✔
4
import { isEmpty } from '../common/util.js';
8✔
5
import { generateQRCodeMatrix } from './model/matrix.js';
8✔
6
import { renderQrCorner } from './renderer/corner.js';
8✔
7
import { getFinderPatterns, renderDataModules } from './renderer/svg.js';
8✔
8
import type {
8✔
9
  QrCornerSquareStyle,
8✔
10
  QrDotStyle,
8✔
11
  QrErrorCorrectionLevel,
8✔
12
} from './types.js';
8✔
13

8✔
14
/**
8✔
15
 *
8✔
16
 * Generates a QR code based on the provided value and options.
8✔
17
 * The component renders an SVG representation of the QR code, which can be customized using various properties.
8✔
18
 *
8✔
19
 * @element igc-qr-code
8✔
20
 *
8✔
21
 * @cssproperty --igc-qr-dark - The color used for the dark modules of the QR code. Default is #000.
8✔
22
 * @cssproperty --igc-qr-background - The color used for the background of the QR code. Default is #fff.
8✔
23
 * @cssproperty --qr-corner-square-fill - The fill color for the corner squares of the QR code. Default is black.
8✔
24
 * @cssproperty --qr-corner-dot-fill - The fill color for the corner dots of the QR code. Default is black.
8✔
25
 */
8✔
26
export default class IgcQrCodeComponent extends LitElement {
27✔
27
  public static readonly tagName = 'igc-qr-code';
27✔
28

27✔
29
  public static override styles = css`
27✔
30
    :host {
27✔
31
      display: inline-block;
27✔
32
      contain: content;
27✔
33
    }
27✔
34
  `;
27✔
35

27✔
36
  /* blazorSuppress */
27✔
37
  public static register(): void {
27✔
38
    registerComponent(IgcQrCodeComponent);
1✔
39
  }
1✔
40

27✔
41
  /**
27✔
42
   * The value to be encoded in the QR code. This can be any string, such as a URL, text, or other data.
27✔
43
   * When this property is set, the component will generate a QR code representing the provided value.
27✔
44
   *
27✔
45
   * @attr value
27✔
46
   */
27✔
47
  @property()
27✔
48
  public value?: string;
27✔
49

27✔
50
  /**
27✔
51
   * The version of the QR code to generate, which determines the size and data capacity of the QR code.
27✔
52
   * Valid values are integers from 1 to 40, where each version corresponds to a specific module size and data capacity.
27✔
53
   *
27✔
54
   * If not specified, the component will automatically select the smallest version that can accommodate the provided value.
27✔
55
   *
27✔
56
   * @attr version
27✔
57
   */
27✔
58
  @property({ type: Number })
27✔
59
  public version?: number;
27✔
60

27✔
61
  /**
27✔
62
   * The error correction level for the QR code, which determines the QR code's ability to be read if it is partially obscured or damaged.
27✔
63
   * Valid values are 'L', 'M', 'Q', and 'H', where 'L' provides the lowest level of error correction and 'H' provides the highest level.
27✔
64
   *
27✔
65
   * @attr error-level
27✔
66
   * @default 'M'
27✔
67
   */
27✔
68
  @property({ attribute: 'error-level' })
27✔
69
  public errorLevel?: QrErrorCorrectionLevel = 'M';
27✔
70

27✔
71
  /**
27✔
72
   * The size of the QR code in pixels. This determines the width and height of the generated QR code. The default value is 128 pixels.
27✔
73
   *
27✔
74
   * @attr size
27✔
75
   * @default 128
27✔
76
   */
27✔
77
  @property({ type: Number })
27✔
78
  public size = 128;
27✔
79

27✔
80
  /**
27✔
81
   * The margin around the QR code in pixels. This is the whitespace area surrounding the QR code,
27✔
82
   * which helps ensure that it can be properly scanned.
27✔
83
   *
27✔
84
   * @attr margin
27✔
85
   * @default 4
27✔
86
   */
27✔
87
  @property({ type: Number })
27✔
88
  public margin = 4;
27✔
89

27✔
90
  /**
27✔
91
   * The style of the data modules (dots) in the QR code. This can be 'square', 'circle', or 'rounded'.
27✔
92
   *
27✔
93
   * @attr dot-style
27✔
94
   * @default 'square'
27✔
95
   */
27✔
96
  @property({ attribute: 'dot-style' })
27✔
97
  public dotStyle: QrDotStyle = 'square';
27✔
98

27✔
99
  /**
27✔
100
   * The style of the corner squares in the QR code. This can be 'square', 'circle', or 'rounded'.
27✔
101
   *
27✔
102
   * @attr square-style
27✔
103
   * @default 'square'
27✔
104
   */
27✔
105
  @property({ attribute: 'square-style' })
27✔
106
  public squareStyle: QrCornerSquareStyle = 'square';
27✔
107

8✔
108
  protected override render() {
8✔
109
    if (!this.value) return null;
30✔
110

18✔
111
    const { matrix, size } = generateQRCodeMatrix(
18✔
112
      this.value,
18✔
113
      this.errorLevel,
18✔
114
      this.version
18✔
115
    );
18✔
116

18✔
117
    const totalModules = size + this.margin * 2;
18✔
118
    const moduleSize = size / totalModules;
18✔
119
    const marginPx = this.margin * moduleSize;
18✔
120
    const svgSize = moduleSize * (size + this.margin * 2);
18✔
121

18✔
122
    const dataModules = renderDataModules(
18✔
123
      matrix,
18✔
124
      moduleSize,
18✔
125
      marginPx,
18✔
126
      this.dotStyle
18✔
127
    );
18✔
128

18✔
129
    const paths = isEmpty(dataModules)
18!
NEW
130
      ? nothing
✔
131
      : svg`<path d=${dataModules.join(' ')} fill="var(--igc-qr-dark, #000)"/>`;
18✔
132

30✔
133
    const patterns = getFinderPatterns(size, moduleSize, marginPx).map(
30✔
134
      ({ x, y }) =>
30✔
135
        renderQrCorner({
54✔
136
          x,
54✔
137
          y,
54✔
138
          size: moduleSize,
54✔
139
          dotStyle: this.dotStyle,
54✔
140
          squareStyle: this.squareStyle,
54✔
141
        })
54✔
142
    );
30✔
143

30✔
144
    return html`
30✔
145
      <svg
30✔
146
        xmlns="http://www.w3.org/2000/svg"
30✔
147
        role="img"
30✔
148
        width=${this.size}
30✔
149
        height=${this.size}
30✔
150
        viewBox="0 0 ${svgSize} ${svgSize}"
30✔
151
      >
30✔
152
        <title>${this.ariaLabel ?? `QR code: ${this.value}`}</title>
30✔
153

30✔
154
        <rect
30✔
155
          width=${svgSize}
30✔
156
          height=${svgSize}
30✔
157
          fill="var(--igc-qr-background, #fff)"
30✔
158
        />
30✔
159
        <g>${paths}${patterns}</g>
30✔
160
      </svg>
30✔
161
    `;
30✔
162
  }
30✔
163
}
8✔
164

8✔
165
declare global {
8✔
166
  interface HTMLElementTagNameMap {
8✔
167
    'igc-qr-code': IgcQrCodeComponent;
8✔
168
  }
8✔
169
}
8✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc