--- title: "Mantine QR Code - A Real QR Code Generator for Mantine" author: "Giovambattista Fazioli" published: "2026-09-04T08:41:04.915Z" updated: "2026-09-04T08:41:04.915Z" url: "https://zyvop.com/mantine-qr-code-a-real-qr-code-generator-for-mantine-x5xs3" canonical: "https://dev.to/undolog/mantine-qr-code-a-real-qr-code-generator-for-mantine-1a7j" tags: ["react","TypeScript","webcomponents","uidesign"] --- # Mantine QR Code - A Real QR Code Generator for Mantine ![Cover image]() > Generate fully scannable, beautifully styled QR codes with custom dot shapes, finder patterns, image overlays, and one-click SVG/PNG download — all integrated with the Mantine design system. ## Introduction The Mantine QR Code component has been completely rebuilt from the ground up. What was previously an LED-style indicator has been transformed into a fully functional QR code generator that produces real, scannable codes from any string input. It renders pure SVG for crisp output at any resolution, follows Mantine's Styles API conventions, and ships with a dedicated download hook for exporting to SVG, PNG, JPEG, or WebP. ![Mantine QR Code]() ## ✨ New Features ### Real QR Code Generation The component now encodes actual QR code data using the `qrcode` library. Pass any string — a URL, WiFi credentials, vCard, plain text — and get a scannable QR code rendered as optimized SVG. ```javascript import { QRCode } from '@gfazioli/mantine-qr-code'; function Demo() {return ;} ``` Enter fullscreen mode Exit fullscreen mode The `value` prop is the only required prop. Everything else has sensible defaults. ### Dot Styles Control the appearance of data modules with the `dotStyle` prop. Three built-in styles are available: ```javascript {/* Default */} ``` Enter fullscreen mode Exit fullscreen mode Each style generates a single combined `` element for all data modules, keeping the DOM lightweight even for dense QR codes. ### Corner Styles The three finder patterns (the large squares in the corners) can be styled independently with `cornerStyle`: ```javascript {/* Default */} ``` Enter fullscreen mode Exit fullscreen mode Mix and match dot and corner styles for unique designs: ```javascript ``` Enter fullscreen mode Exit fullscreen mode ### Image Overlay with Excavation Add a logo or image at the center of the QR code. The component automatically removes ("excavates") the data modules behind the image to keep the code scannable: ```javascript ``` Enter fullscreen mode Exit fullscreen mode > **Tip:** Use `errorCorrectionLevel="H"` when overlaying images — it provides 30% error correction, ensuring the code remains scannable even with a portion covered. ### Error Correction Levels Four standard error correction levels are supported via the `errorCorrectionLevel` prop: | Level | Recovery | Best for | | --- | --- | --- | | `L` | ~7% | Dense data, minimal damage expected | | `M` | ~15% | General use (default) | | `Q` | ~25% | Moderate resilience | | `H` | ~30% | Image overlays, printed codes | ### `useQRCodeDownload` Hook A dedicated hook makes it easy to export the QR code in multiple formats: ```javascript import { QRCode, useQRCodeDownload } from '@gfazioli/mantine-qr-code'; function Demo() {const { ref, download, getDataUrl } = useQRCodeDownload({ fileName: 'my-qr-code', scale: 4, // 4x resolution for raster formats}); return ( <> );} ``` Enter fullscreen mode Exit fullscreen mode Supported formats: `svg`, `png`, `jpeg`, `webp`. The `getDataUrl` function returns a data URL — useful for preview thumbnails or embedding. ### Theme-Aware Colors Both foreground and background colors integrate with the Mantine theme: ```javascript ``` Enter fullscreen mode Exit fullscreen mode ### Full Styles API The component exposes 8 style selectors for granular customization: | Selector | Element | Description | | --- | --- | --- | | `root` | `
` | Outer container | | `svg` | `` | SVG element | | `background` | `` | Background rectangle | | `modules` | `` | Combined data modules path | | `finderPattern` | `` | Finder pattern group (×3) | | `finderOuter` | `` | Outer ring of finder pattern | | `finderInner` | `` | Inner square of finder pattern | | `image` | `` | Center image overlay | ### CSS Variables | Variable | Description | | --- | --- | | `--qr-code-size` | Width and height | | `--qr-code-radius` | Container border radius | | `--qr-code-color` | Foreground (module) color | | `--qr-code-background` | Background color | Size presets: `xs` (80px), `sm` (120px), `md` (160px), `lg` (200px), `xl` (256px). ## 🔧 Improvements - **SVG Accessibility**: The SVG element includes `role="img"` and an `aria-label` derived from the encoded value. - **Optimized Rendering**: All data modules are combined into a single `` element, keeping the DOM minimal regardless of QR code density. - **Memoized Computation**: QR matrix generation and SVG path building are wrapped in `useMemo` — re-computation only happens when relevant props change. - **SSR Compatible**: No browser-only APIs (`window`, `document`) are used during rendering. The download hook uses browser APIs only when explicitly called. ## 📖 Complete Props Reference ```typescript interface QRCodeBaseProps {value: string; // Required — data to encodesize?: MantineSize | string | number; // Default: 'md'radius?: MantineRadius | string | number; // Container border radiuscolor?: MantineColor; // Default: 'dark'background?: MantineColor | 'transparent'; // Default: 'white'errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'; // Default: 'M'quietZone?: number; // Default: 1dotStyle?: 'square' | 'rounded' | 'dots'; // Default: 'square'cornerStyle?: 'square' | 'rounded' | 'dots'; // Default: 'square'image?: string; // Center image URLimageSize?: number; // 0–1, default: 0.2imageRadius?: MantineRadius | string | number;imagePadding?: number; // Default: 1imageExcavate?: boolean; // Default: true} ``` Enter fullscreen mode Exit fullscreen mode ## Getting Started Install the package: ```bash npm install @gfazioli/mantine-qr-code ``` Enter fullscreen mode Exit fullscreen mode Import styles at the root of your application: ```javascript import '@gfazioli/mantine-qr-code/styles.css'; ``` Enter fullscreen mode Exit fullscreen mode Use the component: ```javascript import { QRCode } from '@gfazioli/mantine-qr-code'; function App() {return ( );} ``` Enter fullscreen mode Exit fullscreen mode ## Use Cases ![Use Cases]() ```javascript {/* URL */} {/* WiFi credentials */} {/* vCard contact */} ``` Enter fullscreen mode Exit fullscreen mode ## Links - 📦 [npm package]() - 📖 [Documentation & Demos]() - 🔗 [GitHub Repository]() - 🧩 [More Mantine Extensions]()