QR Code
Renders a QR code as inline SVG.
QrCode is new in v0.4. It encodes any text or URL into a QR code drawn as SVG, so it stays sharp at any size and needs no JavaScript.
Installation
bash
shellui add qr-code
The CLI also adds the QRCoder NuGet package to your project. The ShellUI.Components package already references it.
Usage
Basic
<QrCode Value="https://github.com/shellui-dev/shellui" />Sizes
Size is the width and height in pixels.
<div class="flex flex-wrap items-end gap-6">
<QrCode Value="https://shellui.dev" Size="96" />
<QrCode Value="https://shellui.dev" Size="140" />
<QrCode Value="https://shellui.dev" Size="200" />
</div>Colours
Foreground and Background take any CSS colour. Keep the contrast high, or scanners will struggle.
<div class="flex flex-wrap items-end gap-6">
<QrCode Value="https://shellui.dev" Size="140" Foreground="#1d4ed8" Background="#eff6ff" />
<QrCode Value="https://shellui.dev" Size="140" Foreground="#ffffff" Background="#0a0a0a" />
</div>Live value
The code redraws when Value changes. A higher ErrorCorrection level survives more damage but makes a denser code.
<div class="flex w-full max-w-sm flex-col items-start gap-4">
<Input @bind-Value="text" Placeholder="Text or URL" />
<QrCode Value="@text" Size="160" ErrorCorrection="H" Label="@($"QR code for {text}")" />
</div>
@code {
private string text = "https://shellui.dev";
}API Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
Value |
string |
"" |
The text or URL to encode |
Size |
int |
160 |
Width and height in pixels |
ErrorCorrection |
string |
"M" |
L (7%), M (15%), Q (25%) or H (30%) |
Foreground |
string |
"#000000" |
Colour of the modules |
Background |
string |
"#ffffff" |
Colour behind them |
Label |
string? |
null |
Accessible name; defaults to Value |
Class |
string? |
null |
Additional CSS classes |
Accessibility
- Renders with
role="img"and anaria-label(Label, or the encoded value) - A QR code can't be used without a camera, so show the link or text next to it as well