QrCode
6 partsThe root of a QR code. Encodes value into a matrix (via @robonen/encoding)
and renders an <svg> whose viewBox is laid out in module units, so every
child part draws in the same resolution-independent coordinate space and the
whole code scales with the SVG's CSS width/height.
It is fully headless: compose QrCodeBackground, QrCodeCells,
QrCodeMarkers/QrCodeMarker and QrCodeLogo inside it and style them with
CSS (fill, gradients, <defs>) — patterns, marker shapes and logos are all
controlled by props or slots on those parts.
Demo
Anatomy
Import the parts and compose them. Each part forwards attributes to its underlying element.
import {
QrCodeRoot,
QrCodeBackground,
QrCodeCells,
QrCodeMarker,
QrCodeMarkers,
QrCodeLogo,
} from '@robonen/primitives/display/qr-code';
<QrCodeRoot>
<QrCodeBackground />
<QrCodeCells />
<QrCodeMarker />
<QrCodeMarkers />
<QrCodeLogo />
</QrCodeRoot>API Reference
QrCodeRoot
RootThe root of a QR code. Encodes `value` into a matrix (via `@robonen/encoding`) and renders an `<svg>` whose viewBox is laid out in module units, so every child part draws in the same resolution-independent coordinate space and the whole code scales with the SVG's CSS width/height. It is fully headless: compose `QrCodeBackground`, `QrCodeCells`, `QrCodeMarkers`/`QrCodeMarker` and `QrCodeLogo` inside it and style them with CSS (`fill`, gradients, `<defs>`) — patterns, marker shapes and logos are all controlled by props or slots on those parts.
| Prop | Type | Description |
|---|---|---|
value | string | The text to encode. Re-encodes reactively when it changes. |
errorCorrection? | QrCodeErrorCorrection | Error-correction level — higher levels survive more damage (and logos) at the cost of density. Default 'M'. |
margin? | number | Partial<QrCodeMargin> | Quiet-zone width in modules, uniform or per-side. Default 4 (the spec minimum). |
minVersion? | number | Smallest QR version (1–40) to consider. Default 1. |
maxVersion? | number | Largest QR version (1–40) to consider. Default 40. |
mask? | number | Mask pattern (0–7), or -1 to auto-select the lowest-penalty mask. Default -1. |
boostEcc? | boolean | Whether to automatically raise the error-correction level if the data still fits. Default true. |
QrCodeBackground
BackgroundA rectangle covering the entire code, quiet zone included. Use it for a solid backdrop or a gradient/pattern fill behind the modules. Defaults to `fill="none"` so the page background shows through unless you style it.
| Prop | Type | Description |
|---|---|---|
fill? | string | Fill applied to the rectangle. Default 'none' (transparent). Overridable via CSS. |
radius? | number | Corner radius in module units. Default 0. |
QrCodeCells
CellsRenders the data modules of the code. The `pattern` prop switches between pixel styles; `fluid` is neighbour-aware and merges adjacent modules into smooth blobs. By default the three finder patterns are skipped so that `QrCodeMarker`/`QrCodeMarkers` can style them independently — set `includeMarkers` to draw a complete code from cells alone. For total control, provide a `#cell` slot: it is rendered once per dark module with its grid position and center, and you emit whatever SVG you like.
| Prop | Type | Description |
|---|---|---|
pattern? | QrCellPattern | Module shape: square (default), dot, rounded, or fluid (connected). |
radius? | number | Corner roundness in [0, 1] for rounded/fluid. Default 0.5. |
gap? | number | Gap between modules in [0, 1), as a fraction of cell size. Ignored by fluid. Default 0. |
includeMarkers? | boolean | Also render the finder-pattern modules (use when not composing QrCodeMarkers). Default false. |
QrCodeMarker
MarkerA single finder ("eye") pattern, made of an outer `frame` ring and an inner `ball`. Position it by `corner` (resolved from the matrix size) or pin it with explicit `x`/`y` module coordinates. Override the `#frame` / `#ball` slots to draw arbitrary shapes; each receives the 7×7 region's origin and center.
| Prop | Type | Description |
|---|---|---|
corner? | MarkerCorner | Which finder to render. Ignored when both x and y are given. Default 'top-left'. |
x? | number | Explicit X of the finder's top-left module (overrides corner). |
y? | number | Explicit Y of the finder's top-left module (overrides corner). |
frame? | QrMarkerFrame | Outer ring shape: square (default), rounded, or circle. |
ball? | QrMarkerBall | Inner ball shape: square (default), rounded, circle, or diamond. |
radius? | number | Roundness in [0, 1] for rounded frames/balls. Default 0.5. |
QrCodeMarkers
MarkersConvenience wrapper that renders all three finder patterns with a shared style. Forwards `frame`/`ball`/`radius` to each `QrCodeMarker` and re-exposes their `#frame` / `#ball` slots (augmented with the `corner` being drawn). For fully bespoke per-corner rendering, use the `#default` slot — it is invoked once per marker with its placement.
| Prop | Type | Description |
|---|---|---|
frame? | QrMarkerFrame | Outer ring shape for every marker. Default square. |
ball? | QrMarkerBall | Inner ball shape for every marker. Default square. |
radius? | number | Roundness in [0, 1] for rounded frames/balls. Default 0.5. |
QrCodeLogo
LogoOverlays a logo at the center of the code (or anywhere via `x`/`y`). Pass an image `src`, or use the default slot for arbitrary SVG content — the slot receives the computed placement so you can size and position freely. With `knockout` (the default) the modules behind the logo are cleared so it sits in clean space; pair it with a high `errorCorrection` level on the root to keep the code scannable.
| Prop | Type | Description |
|---|---|---|
src? | string | Image URL to render via an SVG <image>. Optional when using the default slot. |
size? | number | Logo extent as a fraction of the code size, in [0, 1]. Default 0.25. |
x? | number | Center X in module units. Defaults to the code's horizontal center. |
y? | number | Center Y in module units. Defaults to the code's vertical center. |
padding? | number | Extra cleared padding around the logo, in modules. Default 1. |
knockout? | boolean | Clear the modules behind the logo so it has clean space. Default true. |