Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

QR Code

ProNew

A scannable QR code drawn by the bundled encoder from a supplied value, with dot styles, a central logo, frames, caption and PNG download.

Installation

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

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
value*string

The link or text to encode.

—
sizenumber

Width of the code in pixels. It shrinks to fit a narrower container.

168
errorCorrectionQRErrorCorrection

How much damage the code survives: `L` 7%, `M` 15%, `Q` 25%, `H` 30%. Defaults to `H` with a logo and `M` without.

—
dotsDots

Shape of the data modules.

"square"
eyesEyes

Shape of the three corner markers.

"square"
foregroundstring

Color of the modules. Keep it much darker than `background`, or phones will not read the code.

"#0a0a0a"
backgroundstring

Color behind the modules.

"#ffffff"
colorstring

Color of the frame and the caption.

"var(--primary)"
textColorstring

Color of the caption text on top of `color`.

"var(--primary-foreground)"
logoReact.ReactNode

A logo for the centre: an image URL, or a node such as a `BrandIcon`.

—
logoSizenumber

Share of the code's width that the logo covers, up to 0.3.

0.22
quietZonenumber

Empty modules kept around the code.

2
frame"none" | "border" | "solid" | "banner" | "phone"

`border` outlines the code, `solid` mats it, `banner` puts a large caption beside it and `phone` draws a handset.

"none"
captionstring

The call to action: "Scan me", "Get the app".

—
captionIconReact.ReactNode

An icon shown before the caption.

—
captionStyle"bubble" | "bar" | "text"

`bubble` points at the code, `bar` is fused to the frame, `text` is plain.

"bubble"
captionSide"bottom" | "top" | "left"

Where the caption sits. Ignored by the `banner` and `phone` frames.

"bottom"
hrefstring

Turns the caption into a link, for visitors who are already on their phone.

—
downloadboolean

Adds a button that saves the code as a PNG.

false
fileNamestring

File name of the saved PNG, without the extension.

"qr-code"
onDownload() => void

Called once the PNG has been saved.

—
labelstring

Accessible name of the code. Defaults to the caption, or the encoded value.

—
classNamestring—

Accessibility

  • The code is one image named after its caption or the value it encodes.
  • Pass a web, phone, SMS, email or local `href` to make the caption a link; unsafe caption targets render as text.
  • The download button announces “Saved” or “Could not save” politely.
  • Empty and too-long values show a message instead of a broken code. The fade-in is skipped under reduced motion.