Data Display & Media
QR Code
Renders a QR code as crisp, scalable SVG. Encodes any text (byte mode, UTF-8) with a self-contained generator — no runtime dependencies. Choose a module style with variant, theme it with CSS custom properties, and drop a logo into the center via the default slot.
Preview
Section titled “Preview”<nana-qr-code
value="https://design.nanatec.co.ke"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code> <script lang="ts">
import { NanaQrCode } from '$lib/components/ui/qr-code';
</script>
<div class="flex flex-wrap items-center gap-6">
<NanaQrCode value="https://design.nanatec.co.ke" label="Nana UI" />
<NanaQrCode value="https://design.nanatec.co.ke" variant="rounded" errorCorrection="H" logo="N" />
<NanaQrCode value="https://design.nanatec.co.ke" variant="dots" class="text-primary" />
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add qr-code --framework web-componentsnpx @nana-tec/ui add qr-code --framework svelteLands in src/lib/components/ui/qr-code/ as NanaQrCode.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/qr-code";
Copied in with npx @nana-tec/ui add qr-code? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<script lang="ts"> import { NanaQrCode } from '$lib/components/ui/qr-code';</script>
<NanaQrCode value="https://pay.example.com/unit-4b" size={180} variant="rounded" label="Pay rent for Unit 4B" />The code is drawn as SVG by a generator with no dependencies, so it stays crisp at any
size. The modules take the text colour. Put a logo in the middle with logo (a monogram) or
children (an image), and raise errorCorrection to Q or H so the code still scans.
Basic usage
Section titled “Basic usage”<nana-qr-code value="https://design.nanatec.co.ke"></nana-qr-code>Module styles
Section titled “Module styles”The variant attribute changes how modules are drawn — square (default),
rounded, or dots. (The demos below set explicit colors so they stay crisp
in both light and dark; by default the module color follows your theme.)
<nana-qr-code
value="https://nanatec.co.ke"
variant="square"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code>
<nana-qr-code
value="https://nanatec.co.ke"
variant="rounded"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code>
<nana-qr-code
value="https://nanatec.co.ke"
variant="dots"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code> Theming
Section titled “Theming”Override the colour tokens to brand the code. Keep strong contrast between foreground and background so it stays scannable.
<nana-qr-code
value="https://nanatec.co.ke"
style="
--nana-qr-foreground: #134e4a;
--nana-qr-background: #ffffff;
--nana-qr-radius: 12px;
"
></nana-qr-code>
<nana-qr-code
value="https://nanatec.co.ke"
style="
--nana-qr-foreground: #f59e0b;
--nana-qr-background: #0d1117;
--nana-qr-radius: 12px;
"
></nana-qr-code> Error correction
Section titled “Error correction”Higher levels (Q, H) tolerate more damage or occlusion — required if you
overlay a center logo.
<nana-qr-code
value="https://nanatec.co.ke"
error-correction="L"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code>
<nana-qr-code
value="https://nanatec.co.ke"
error-correction="H"
style="--nana-qr-foreground: #0d1117; --nana-qr-background: #ffffff"
></nana-qr-code> With a center logo
Section titled “With a center logo”For a simple text monogram, set the logo attribute — the badge is styled
for you (defaults to the module color, white text, rounded), tunable via CSS
variables. For a custom image, slot an <img> instead. Always pair either with
error-correction="H" so the code stays scannable behind the overlay.
<nana-qr-code
value="https://nanatec.co.ke"
logo="N"
variant="rounded"
error-correction="H"
style="--nana-qr-foreground: #134e4a; --nana-qr-background: #ffffff"
></nana-qr-code>
<nana-qr-code
value="https://nanatec.co.ke"
logo="N"
error-correction="H"
style="
--nana-qr-foreground: #0d1117;
--nana-qr-background: #ffffff;
--nana-qr-logo-bg: #f59e0b;
--nana-qr-logo-color: #111111;
"
></nana-qr-code> <nana-qr-code value="https://nanatec.co.ke" logo="N" error-correction="H"></nana-qr-code>
<nana-qr-code value="https://nanatec.co.ke" error-correction="H"> <img src="/logo.svg" alt="Nanatec" /></nana-qr-code>Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
errorCorrection | error-correction | QrCodeErrorCorrection | 'M' | Error-correction level (higher tolerates more damage / occlusion) |
label | label | string | '' | Accessible label (defaults to the encoded value) |
logo | logo | string | '' | Short monogram (e.g. "N") rendered as a styled center badge automatically. Prefer this over the slot for simple text logos. |
margin | margin | number | 4 | Quiet-zone width, in modules |
size | size | number | 160 | Rendered size in pixels (width and height) |
value | value | string | '' | The data to encode |
variant | variant | QrCodeVariant | 'square' | Module shape style |
Slots
| Slot | Description |
|---|---|
(default) | Optional center logo / overlay (e.g. an <img>). Use a high error-correction level so the code stays scannable. For a simple monogram, use the logo attribute instead — the badge is styled for you. |
CSS parts
| Part | Description |
|---|---|
::part(frame) | The bordered background frame |
::part(svg) | The SVG element |
::part(modules) | The <path> of dark modules |
::part(logo) | The center logo/monogram container; carries has-logo, logo--mono |
::part(placeholder) | The placeholder |
::part(logo-mono) | The logo mono |
CSS custom properties
| Property | Description |
|---|---|
--nana-qr-foreground | Module colour |
--nana-qr-background | Background / quiet-zone colour |
--nana-qr-radius | Frame corner radius |
--nana-qr-logo-size | Logo width / monogram tile size (default 22% / 2.25rem) |
--nana-qr-logo-bg | Monogram tile background (default: the module colour) |
--nana-qr-logo-color | Monogram text colour (default #fff) |
--nana-qr-logo-radius | Monogram tile corner radius (default 0.5rem) |
--nana-qr-logo-font-size | Text size of the centre monogram |
--nana-qr-logo-pad | Padding around the centre monogram |
NanaQrCode
| Prop | Type | Default |
|---|---|---|
valuerequired | string | |
size | number | 160 |
variant | QrVariant | 'square' |
errorCorrection | QrEcc | 'M' |
margin | number | 4 |
label | string | |
logo | string | |
children | Snippet |
Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>.