@gfazioli/mantine-qr-code
A highly customizable QR Code component for React applications built with Mantine.
Installation
After installation import package styles at the root of your application:
You can import styles within a layer @layer mantine-qr-code by importing @gfazioli/mantine-qr-code/styles.layer.css file.
Usage
Configurator
Explore all available props and see the component in action:
Colors
The QRCode component supports all Mantine theme colors. Use the color and background props to customize:
red
blue
violet
teal
orange
cyan
Dot styles
Control the appearance of data modules with the dotStyle prop:
Square
Rounded
Dots
Corner styles
Customize the three finder patterns (corners) with the cornerStyle prop:
Square
Rounded
Dots
Error correction
QR codes support four error correction levels. Higher levels allow more damage tolerance but produce denser codes:
L (7%)
M (15%)
Q (25%)
H (30%)
Image overlay
Add a logo or image at the center of the QR code. Use errorCorrectionLevel="H" for best results when overlaying images:
imageSize(default0.2): the image side as a fraction of the QR code, quiet zone excluded. Keep it small enough for the error correction level to recover the modules it hides.imagePadding(default1): the clearance around the image, in modules. The cleared area spans an odd number of whole modules so it stays centered, so the clearance can differ fromimagePaddingby up to half a module.imageExcavate(defaulttrue): removes the modules behind the image and its padding. Set it tofalseto draw the image over the modules instead.
Download
Use the useQRCodeDownload hook to download the QR code as SVG, PNG, JPEG or WebP:
- its options set the defaults for every call:
format(png),fileName(qrcode) andscalefor raster formats (4); download()takes the same options to override them for one download;getDataUrl()returns the image as a data URL instead of downloading it.
An image overlay is fetched and embedded in the export, so it must come from the same origin or a server that allows cross-origin requests (CORS), or be passed as a data URL. When it cannot be fetched, PNG, JPEG and WebP leave the image out and SVG keeps its URL. With background="transparent", PNG, WebP and SVG stay transparent, while JPEG, which has no transparency, gets a white background:
Styles API
QRCode supports Styles API, you can add styles to any inner element of the component with classNames prop. Follow Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Use cases
QR codes can encode various data types including URLs, WiFi credentials, and contact information:
URL
WiFi
vCard