VayuUI

QRCode

A pure TypeScript QR code generator rendered as SVG with support for logos, custom colors, and error correction levels.

Installation

npx vayu-ui-cli@latest add qrcode

Usage

QRCode Example

Default (md)

Size Variants

Custom Colors

With Excavated Logo

No Margin

Empty State

<QRCode value="https://example.com" />

<QRCode value="https://example.com" size="sm" />
<QRCode value="https://example.com" size="md" />
<QRCode value="https://example.com" size="lg" />

<QRCode
  value="https://example.com"
  bgColor="#18181b"
  fgColor="#a3e635"
/>

<QRCode
  value="https://example.com"
  size="lg"
  level="H"
  imageSettings={{
    src: "/logo.png",
    width: 50,
    height: 50,
    excavate: true,
  }}
/>

<QRCode value="https://example.com" includeMargin={false} />

<QRCode value="" />

Anatomy

import { QRCode } from 'vayu-ui';

<QRCode value="https://example.com" />;
  • QRCode — Single component that renders an SVG-based QR code. Handles encoding, module placement, masking, and optional center logo overlay internally.

Accessibility

  • Keyboard Support: Not applicable. QRCode is a static image element with no interactive controls.
  • ARIA Attributes:
    • role="img" applied to the root container for proper semantic meaning.
    • aria-label auto-generated as QR code for: the encoded value when populated.
    • Empty state receives aria-label="Empty QR code".
  • Focus Behavior: The component is non-interactive. It uses role="img" so screen readers treat it as a decorative/informational image.

Screen reader behavior

When encountering a populated QRCode, the screen reader announces it as an image with the label "QR code for: {encoded value}". For example, with value="https://example.com", the screen reader announces: "QR code for: https://example.com, image". If a custom aria-label is provided, it overrides the default. When the value is empty, the screen reader announces: "Empty QR code, image". The SVG content inside is not individually traversed by screen readers since the parent div has role="img".

Component Folder Structure

QRcode/
├── QRCode.tsx    # React component with SVG rendering, logo overlay, and color resolution
├── QREncoder.ts  # Pure TypeScript QR encoding engine (byte mode, versions 1-40)
├── types.ts      # Shared type definitions (ErrorCorrectionLevel, QRCodeImageSettings)
├── index.ts      # Public API re-exports
└── README.md     # Component usage reference

Props

QRCode

PropTypeDefaultDescription
valuestringData to encode in the QR code. Required.
size"sm" | "md" | "lg""md"Size variant: sm (128px), md (200px), lg (300px).
qrSizenumberCustom width/height in pixels. Overrides size.
level"L" | "M" | "Q" | "H""M"Error correction level. Auto-upgrades to H when imageSettings is set.
bgColorstringvar(--color-ground-50)Background color of the QR code.
fgColorstringvar(--color-ground-950)Foreground (module) color of the QR code.
includeMarginbooleantrueAdd a 4-module quiet zone margin around the code.
imageSettingsQRCodeImageSettingsConfiguration for a center logo overlay.
classNamestringAdditional CSS classes applied to the root div.
aria-labelstring"QR code for: value"Accessible label. Overrides the auto-generated default.

QRCodeImageSettings

PropTypeDefaultDescription
srcstringURL of the center logo image. Required.
widthnumberWidth of the logo in pixels. Required.
heightnumberHeight of the logo in pixels. Required.
excavatebooleantrueClear QR modules behind the logo for scannability. Defaults to true.
excavateMarginnumber1Extra cell buffer cleared around the excavated area.

On this page