QrCode
HkQrCode renders a scannable QR code from an arbitrary payload — typically an otpauth:// URI for a two-factor enrolment. The code is always dark modules on a white card, independent of the app theme, so it stays scannable in dark mode; an empty or whitespace-only payload renders no code at all.
- The payload is encoded in byte mode with auto version selection (1–40) and the error-correction level you pass, so a longer string simply makes a denser code.
- A one-time code the user types is HkOtpInput's job; the QR code is for handing the secret to another device.
- A copyable setup link is HkCopyBadge; the QR code is the scan-me twin of that string.
Import
;
use *; // QrCode, QrErrorCorrectionLevel
use *; // rsx!, VNode
Both forms encode the same matrix from the same vendored encoder, so a code rendered by one is byte-identical in modules to the code rendered by the other. The Vue form re-encodes in a watch; the Rust form re-encodes on every render — the same observable contract for a host that passes the value in.
Payload and size
value is the payload; size is the rendered square in CSS pixels (168 by default) and margin is the quiet zone in modules (2 by default). Keep the quiet zone at least 2 modules if the card is not white — scanners need the light border to find the code.
The Vue fence below draws the matrix; the Rust fence renders the same payload as an SVG grid.
Error correction
level trades density for resilience: L (~7% recoverable), M (the default, ~15%), Q (~25%) and H (~30%). A code printed on a surface that will be scratched or photographed at an angle wants Q or H; a clean on-screen code is fine at M. The payload decides the version, so a higher level on the same string makes the same square denser.
Inks, inverse and the caption
colorDark and colorLight paint the modules; inverse swaps them for an advanced dark-card use — but a light-on-dark code is harder for many phone cameras to lock onto, so the default light card stays the high-contrast choice. label renders a caption under the code and becomes its accessible name; with no label the name falls back to the localized "QR code".
The Rust mirror emits an SVG instead of painting a canvas (it has no canvas op): same module grid, same hk-qr-canvas class, same card. An overflowing payload renders the light card without modules in both forms.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| value | String | "" | — |
| size | Number | 168 | — |
| margin | Number | 2 | — |
| level | String as PropType<QrErrorCorrectionLevel> | "M" | — |
| colorDark | String | "#000000" | — |
| colorLight | String | "#ffffff" | — |
| inverse | Boolean | false | — |
| label | String | "" | — |
| disabled | Boolean | false | — |
Rust
Props — QrCode
| Prop | Type | Default | Description |
|---|---|---|---|
| value | String | "" | Payload to encode (Vue default ""); whitespace-only renders nothing. |
| size | f64 | 168.0 | Rendered square size in CSS px (Vue default 168). |
| margin | f64 | 2.0 | Quiet-zone width in modules (Vue default 2). |
| level | QrErrorCorrectionLevel | QrErrorCorrectionLevel::M | Error-correction level (Vue default "M"). |
| color_dark | String | "#000000".to_string() | Dark module ink (Vue default "#000000"). |
| color_light | String | "#ffffff".to_string() | Light module ink (Vue default "#ffffff"). |
| inverse | bool | false | Swap dark/light (advanced use with a dark card; Vue default false). |
| label | String | "" | Optional caption under the QR (also the accessible name when set). |
| disabled | bool | false | Declared in Vue and never read there — kept inert for prop parity (see the header delta). |
Accessibility
- The code is an image with a name: role="img" plus aria-label, which is the label when given and the localized "QR code" otherwise. A bare "QR code" name tells a screen-reader user nothing about what is being scanned — pass label whenever the payload has a human-relevant purpose.
- The caption is visible text, not a replacement for the name: assistive technology reads the name, sighted users read the caption.
- Nothing in the card is focusable and no event is emitted; the QR code is a static surface.
- The light card is deliberate, not decorative: dark mode must not recolor the modules, because a low-contrast or inverted code fails to scan. Check contrast of custom colorDark / colorLight pairs before shipping them.
Related components
- HkCopyBadge — the copyable string version of the same enrolment token.
- HkOtpInput — the typed one-time-code field, the other half of a two-factor flow.
- Comment — the comment block, when a scan target is shared in a threaded note.