UIComponentsReact
A QR code for a text, such as a link, drawn as an image that can be saved as a PNG or an SVG file.
Built on the headless QR Code.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/qr-code.jsonIt also adds utils, button. The app needs its setup first: Installation.
Usage
Give QrCode the value to encode. Put a QrCodeFrame around a QrCodePattern inside it, then an optional QrCodeOverlay with a logo and a QrCodeDownloadTrigger for each file type. The Frame is an image named "QR code: " and the value; the Pattern draws the dark modules in the Frame's text colour. errorCorrection (L, M, Q or H, M by default) sets how much of the code can be lost and still read; give H when an Overlay covers the middle. A value too long for the largest code puts data-overflow on every part, empties the Frame and disables the DownloadTrigger. The encoding, quietZone, minVersion, labels and the DownloadTrigger's type, fileName and scale come from the headless QR Code.
import {
QrCode,
QrCodeDownloadTrigger,
QrCodeFrame,
QrCodeOverlay,
QrCodePattern,
} from '@/components/ui/qr-code'Examples
Default
A link at level H with a logo over the middle and a PNG download button.
The Frame is 160 by 160 CSS pixels with black modules on white in light and dark themes, since a code drawn light on dark is not read by every scanner; the quiet zone of four modules is drawn inside it. The Overlay sits in the Frame's grid cell, centred, in a 40 by 40 white box, so it covers about 6% of the code; at level H up to 30% can be lost. The Frame's name says the value, so the text reaches a screen reader as well; the Overlay is hidden from assistive technology. The DownloadTrigger is the Button's outline at its default size, named by its text, or "Download QR code" when it has none; variant and size change it. The file is drawn in the Frame's colours. Past capacity the Frame keeps its place with a dashed border, so the layout does not move, and the reason is for the app to say. This item takes Base UI's component ID as its slug and one name per Base UI part.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on QR Code's API reference.