QR code
A QR code drawn as SVG from a string: a link to open on a phone, a code to join a workspace, Wi-Fi details. The encoder is in the file, with no package. The code is black on white in both themes, because many scanners do not read a light code on a dark ground. For a value people type, show it as text next to the code as well.
Install
npx shadcn@latest add @thrum-pro/qr-codeThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | Required | The text to encode, as UTF-8 bytes. Up to 271 bytes at level L and 119 at H; past that the error state shows. |
title | string | Required | The accessible name: what scanning the code does, such as "Open Acme invoice 2041". |
size | number | Default 160 | Width and height in pixels, quiet zone included. |
level | "L" | "M" | "Q" | "H" | Default "M" | How much damage the code survives: about 7%, 15%, 25% or 30% of it. Higher levels need more modules for the same value. |
margin | number | Default 4 | The quiet zone around the code, in modules. Scanners expect 4; less works on a plain background. |
children | ReactNode | – | A mark in the centre, such as a logo. The level becomes H and the modules under it are cleared: about 20% of the width. |
tooLongLabel | string | Default "Too long to show as a QR code" | What the error state says when the value does not fit in version 10. |
className | string | – | Extra classes, merged last. A text colour class changes the module colour and a background class the ground; keep it dark on light. |
...props | ComponentProps<"div"> | – | Every other div attribute is passed through. |
qrMatrix() | (text: string, level?: QrLevel, mask?: number) => QrMatrix | null | – | A second export: the encoder. It returns the version, the mask and modules[y][x], or null when the text is too long. |
Motion and sound
Motion
- The code does not move.
Sound
Silent. This component makes no sound.
Accessibility
- The code is an image named by title, so a screen reader says what scanning it does, not the modules.
- Modules are black on white in the light and the dark theme. A light code on a dark ground is one many scanners do not read.
- Modules are plain squares joined into one shape, which scans best. Only the frame around the quiet zone follows the theme's radius.
- A value that is too long shows a dashed box of the same size with the reason in words, also in the image's name.
- Show a short value as text as well, for people who cannot scan.
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/qr-code.tsx- Packages
- None
- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-03First release.