React library
Library API reference
Every entry point, component, function, constant and type the qrdx package exports, with types and defaults. For HTTP endpoints, see the REST API.
This page lists what qrdx exports, by entry point and by task, with each prop's type and default. The feature pages explain how to use them; this one is for looking a name up.
Entry points
Every framework package is an optional peer dependency: installing qrdx never adds one you do not use. jspdf is optional too, for PDF.
Components
QRCode
The component for most uses. QRProps plus a simple logo API, rendered as an <svg>. It uses no browser-only hooks, so it renders in React Server Components.
import { QRCode } from "qrdx";
<QRCode value="https://example.com" size={256} margin={4} level="H" logo="/logo.png" />;QRCode takes these props only; any other prop is dropped. QRCodeSVG puts any other prop (className, aria-label, role, data-*, …) on the <svg>, or on the frame's outer <svg> when there is a frame. Event handlers are left out of the markup.
QRCodeSVG
QRProps plus React's SVG attributes (QRPropsSVG): the same props as QRCode without logo, logoOptions, hideLogo and scale. The logo is imageSettings, in pixels:
A logo bigger than the code can repair is shrunk around its center (capImageSettings, the same budget as QRCode).
QRCodeCanvas
QRProps plus React's canvas attributes (QRPropsCanvas), drawn on a <canvas> at the device's pixel ratio. It draws plain square modules with solid colors: a gradient falls back to its first stop, and the pattern, eye color, eyeColors, moduleScale, art and template props are ignored. It ships with "use client".
getQRAsSVG
getQRAsSVG(props: QRPropsSVG): Promise<JSX.Element> returns the code as a React element with its logo embedded as a data URL. For a string, use toSVGString or getSVGString.
Download and export
Constants: DownloadFormat is "png" \| "jpg" \| "webp" \| "svg" \| "pdf" \| "eps"; DOWNLOAD_FORMATS maps each to its MIME type and extension; PRESET_SIZES has small (200), medium (400), large (800), xlarge (1200), 2xl (1600) and 3xl (2000); DEFAULT_SIZE is 128.
Print and EPS
PrintOptions: size (number), unit ("mm" or "in", default "mm"), bleed (mm, 0 to 20), cropMarks (boolean), colorMode ("rgb" or "cmyk").
Scan score and detection
Grades are "great", "ok", "risky" and "fails". Each check is { id, passed, message, fix?, skipped? }. Contrast lines: SCAN_CONTRAST_MIN 4.5, SCAN_CONTRAST_LOW 3, SCAN_CONTRAST_FAIL 1.5, and SCAN_IMAGE_CONTRAST_MIN 7 for a picture in the code and 12 behind it. The weak pairs ship as WEAK_BODY_EYES, WEAK_DOT_EYES, WEAK_SHARP_DOT_EYES, SHARP_DOT_EYE_SAFE_BODIES, WEAK_EYES and WEAK_DOTS.
Logos
Limits: LOGO_SIZE_MIN 0.1, LOGO_SIZE_MAX 0.3, LOGO_SIZE_DEFAULT 0.25, LOGO_PADDING_MAX 2, LOGO_SHAPES (square, rounded, circle).
Frames
Constants: FRAME_STYLES (the 19 built-in styles plus none), DEFAULT_FRAME_TEXT ("Scan me"), FRAME_TEXT_MAX_LENGTH (24), FRAME_FONT_SCALE_MIN (0.5), FRAME_FONT_SCALE_MAX (1.5), CUSTOM_FRAME_STYLE ("custom"), GRADIENT_FRAME_DEFAULTS.
Templates
TemplateDefinition<TCustomProps> is { id, name, description?, spec?, wrapper(children, props?, config?) }. The wrapper draws on a 300 by 300 canvas and gets { fgColor, bgColor, ...customProps } and { url, pixelSize }.
Shapes and art
Constants: QR_SHAPES (square, circle, heart), QR_CIRCLE_QUIET_MIN (3), QR_SILHOUETTE_MAX_CELLS (64), QR_ART_MODES (logo, halftone), QR_ART_VARIANTS, QR_ART_MAX_SAMPLE_SIZE (192), DEFAULT_ART_INTENSITY (0.6).
Rendering primitives
The React-free renderer, from qrdx/core:
Utilities
getSolidColor, getContrastRatio, getContrastLevel, getLuminance, hexToRgb, SUPPORTS_PATH2D, getColorString, normalizeColorConfig, isGradient, isImagePaint, decodePNGPixels, sanitizeFrameText and isLatin1Text are described on Utilities.
Types and option lists
The types below come from qrdx, qrdx/core and qrdx/types. The option lists are plain arrays; the zod schemas (qrPropsSchema, frameSchema, frameSpecSchema, colorConfigSchema, qrArtSchema, logoOptionsSchema, imageSettingsSchema and the rest) are built from them.
Option lists: BODY_PATTERN, CORNER_EYE_PATTERNS, CORNER_EYE_DOT_PATTERNS, FRAME_STYLES, QR_SHAPES, LOGO_SHAPES, EYE_POSITIONS. Retired values that still render for saved designs: RETIRED_CORNER_EYE_PATTERNS (curly) and RETIRED_CORNER_EYE_DOT_PATTERNS (diamond, star, banner).
Where things run
- Anywhere, no DOM:
toSVGString,createQRCodeTree,renderToString,getQRData, the frame and template helpers,createQRArtImage,createQRSilhouette,getPrintLayout,getQRAsEPS,getQRAsPrintPDFBuffer,scanQRPixels,toQRdxCodeHTML. - Browser:
downloadQRCodeand the other downloads,copyQRCodeToClipboard,getQRAsCanvas,getScanScore,getImageScanScore,handleImageLoad,loadQRArtImage,loadQRSilhouette,removeLogoBackground,createQRCode, the custom element. - Node only:
getQRAsPNGfromqrdx/node. - React Server Components:
QRCode,QRCodeSVGand everything that needs no DOM.QRCodeCanvasis a Client Component.
Related
Was this page helpful?
Last updated on