GitHub

QRCode

A theme-aware QR code with loading feedback and optional reveal animation.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/qr-code

Install with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.

Usage

import { QRCode } from "@workspace/ui/components/qr-code";

<QRCode value="https://example.com/" label="Example website QR code" size={220} />;

Loading and empty states

Generation loads on demand in the client. The server renders a stable loading placeholder. Changing value generates a fresh code and discards the previous request result. loading keeps the placeholder visible even if generation has completed. An absent or empty value keeps the loading placeholder rather than generating an invalid code.

By default, the code uses the neutral --foreground color on a solid --card surface. It follows light and dark modes without inheriting the accent color. Theme changes recolor the existing code without generating it again. The basic code appears as soon as its image loads. Loading and empty states use independently pulsing dots with a roughly 800ms blur entrance and no visible text. Generation failures show an error icon. The loading dots, error icon, and logo surface follow the same neutral theme. The logo appears only when the code is ready.

Loading example…

Optional animation

Enable animated for a roughly 750ms reveal. Both modes use the dot-matrix skeleton while loading. Reduced motion freezes the dots and skips the reveal. The basic version displays the result directly.

Loading example…

Margin and finder patterns

margin controls the quiet space around the code in CSS pixels at the requested size, defaulting to 16. Set it to 0 to supply your own solid-color quiet zone. It scales with the code in smaller containers. Negative values become zero, excessive values are limited to size / 2 - 4, and non-finite values use the default.

Finder patterns use concentric rounded outer rings and rounded solid centers. Their outer edge, inner edge, and center have corner radii of 2.5, 1.5, and 0.5 modules, preserving the same corner centers as each edge moves inward. Insufficient quiet space, small sizes, and busy backgrounds reduce scan reliability. Verify scanning at the actual display size.

Loading example…

logo places a small React node over the center. The generator uses high error correction and retains the surrounding quiet zone. Keep the logo small, preserve the quiet zone, and verify scanning at the size and background where the code will be used. A logo can still reduce scan reliability even with error correction.

QRCode renders only the code. Compose your own layout or caption when needed. The code stays sharp while its neutral foreground and default solid background follow the theme. Test both light and dark modes with the scanners your application supports.

Loading example…

Without a background

background={false} drops the card, so the code sits straight on whatever is behind it and takes its color from currentColor. Scanners still need contrast: put it on a plain backdrop and keep the quiet zone clear. With a logo, the modules under the logo are cut out of the code itself, so the logo stays clear without a plate.

Loading example…

Glass

QR codes are content and keep their opaque reading area inside glass. Pass glass to place the code on glass instead; its reading area turns transparent and takes the code's own material. Prefer frosted over busy backgrounds so the code stays scannable.

API reference

PropTypeDefault / behavior
valuestringContent to encode; empty keeps placeholder.
loadingbooleanfalse.
animatedbooleanfalse; optional reveal animation.
sizenumber256; requested width, bounded to 64–1024 pixels and constrained by the container.
labelstring"QR code"; accessible description.
marginnumber16; quiet space in CSS pixels at the requested size.
logoReactNodeOptional center overlay.
backgroundbooleantrue; false drops the card behind the code.
glass, frostedboolean | GlassConfig, booleanShows the code on Clear or frosted glass.
render, ref, other propsDiv / useRender propsForwarded to the root.

The module exports QRCode, QRCodeProps, and qrCodeVariants. Generation uses qr-code-styling.