Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Collections

  • QuestionCard
  • Table
  • Book3D
  • ProTable
  • PricingTable
  • JsonViewer
  • EditableTable
  • List
  • Descriptions
  • RowActions
  • Tree
  • Card
  • Carousel
  • Video
  • Audio
  • BentoGrid
  • Image
  • MagicCard
  • AnimatedList
  • Marquee
  • Sortable
  • Kanban
  • DesignCanvas
  • LayerTree
  • StageDraw
  • SlideDeck
  • PresenterView
  • ComponentPicker
  • EventStream
  • QueueLane
  • DocumentSheet
  • Novel reader
  • Scheduler
  • Org classroom
  • Danmaku
  • LiveChat
  • LivePlayer
  • LogViewer
  • FileTree
  • CodeReviewThread
  • VirtualList
  • InfiniteScroll
  • LogoLoop
  • BounceCards
  • CardSwap
  • ChromaGrid
  • CircularGallery
  • DomeGallery
  • FlyingPosters
  • InfiniteMenu
  • MagicBento
  • ScrollStack
  • ProfileCard
  • TiltedCard
  • PixelCard
  • DecayCard
  • ReflectiveCard
  • Folder

Charts and Diagrams

  • Flow
  • Diagram
  • Paper
  • SequenceDiagram
  • Sankey
  • Sparkline
  • Funnel
  • Treemap
  • Gantt
  • Heatmap
  • ContributionGraph
  • Legend
  • Chart
  • WorldMap

Information

  • ImageViewer
  • LiveProductCard
  • DiffStat
  • ScoreRing
  • ScoreScale
  • Badge
  • Dot
  • StatusDot
  • Chip
  • FilterChip
  • Coupon
  • Tag
  • Annotation
  • Avatar
  • AvatarCircles
  • User
  • QRCode
  • Comment
  • RelativeTime
  • GitCommit
  • DeployStatus
  • ShieldBadge
  • AwardBadge
  • CreditCard
  • IconTile

Metrics

  • Stat
  • Statistic
  • Meter
  • Timeline
  • NumberTicker

Placeholders

  • Empty
  • Skeleton
  • Watermark

QRCode

qrcode

Generates theme-aware QR SVGs with version and correction boosting, excavated or watermark logos, plus SVG and high-DPI PNG export helpers.

Usage

Basic usage

Just pass in value, and the dark block inherits the currentColor eating theme by default.

tsx
<QRCode value="https://hulian.dev" size={160} />

Correction level

level L/M/Q/H Increasing redundancy (with logo recommendation H).

tsx
<>
  <QRCode value="https://hulian.dev" size={120} level="L" />
  <QRCode value="https://hulian.dev" size={120} level="H" />
</>

Chinese content

The kernel has been overwritten to UTF-8 encoding, which can directly encode Chinese.

tsx
<QRCode value="Hulian component library · Mobile QR code" size={140} level="H" />

Custom color matching

color/background Specify explicitly, or use the text-* utility class to change the dark block color.

tsx
<QRCode
  value="https://hulian.dev"
  size={140}
  color="#0f172a"
  background="#f1f5f9"
/>

Center Logo

Pass logo and embed it in the center of the QR code. Be sure to add level="H" to leave enough redundancy.

tsx
<QRCode
  value="https://hulian.dev"
  size={160}
  level="H"
  logo={{ src: "/logo.png", size: 36 }}
/>

Watermark type Logo

excavate={false} does not cut out the blank, and is equipped with opacity as watermark; the opaque logo does not cut out the blank, the module will be covered and cannot be scanned out.

tsx
<QRCode
  value="https://hulian.dev"
  level="H"
  logo={{ src: "/logo.png", size: 60, excavate: false, opacity: 0.25 }}
/>

Stable density · Automatic upgrade

minVersion pins the lower limit of the version to make a group of code density consistent (the content will not jump when the content becomes longer); boostLevel is enabled by default, and you can get higher error correction for free without upgrading the version.

tsx
<>
  <QRCode value="A" minVersion={4} />
  <QRCode value="https://hulian.dev/components/qrcode" minVersion={4} />
</>

Export SVG / PNG

qrCodeSvgString produces an independent SVG string (can also be used on the server), qrCodeToPngDataUrl produces PNG data URL (automatically press DPR to enlarge, default white background).

SVG string 6263 Characters

tsx
import { qrCodeSvgString, qrCodeToPngDataUrl } from "@hulianui/ui"

// Download SVG
const svg = qrCodeSvgString({ value: url, size: 512 })
download(new Blob([svg], { type: "image/svg+xml" }), "qr.svg")

// Download PNG
const png = await qrCodeToPngDataUrl({ value: url, pixelSize: 512 })
Object.assign(document.createElement("a"), { href: png, download: "qr.png" }).click()

When to use

Use QRCode to encode scannable URLs or text in a locally rendered SVG. It supports themed colors, UTF-8 text, and a center logo without a remote image-generation service.

Import

ts
import { QRCode, buildQRCode, qrCodeSvgString, qrCodeToPngDataUrl } from "@hulianui/ui"

Props

NameTypeDefaultDescription
value*string-UTF-8 URL or text to encode.
sizenumber160Side length in pixels.
level"L" | "M" | "Q" | "H""M"Error-correction level; prefer H with a logo.
marginnumber2Quiet-zone width in modules.
colorstringcurrentColorDark-module color inherited from text color by default.
backgroundstringTransparentBackground color.
logoQRCodeLogo-Center { src: string; size?: number } logo; pair with level="H".
aria-labelstringThe valueAccessibility label.
classNamestring-Custom class name.

Additional capabilities

NameTypeDefaultDescription
minVersionnumber-Minimum QR version from 1 to 40. Longer content can still increase the version rather than being truncated; setting a floor keeps a group of codes visually consistent in density.
boostLevelbooleantrueRaises the error-correction level when spare capacity allows, without increasing the QR version.
logo.excavatebooleantruePlaces a background patch under the logo to clear covered modules. Set to false for a translucent watermark-style logo.
logo.opacitynumber1Logo opacity, commonly combined with excavate={false} for a watermark.

The export helpers use the same encoding core as the component, so their output stays consistent:

  • qrCodeSvgString({ value, size, color, background, ... }) returns a standalone SVG string for downloads, email, print artwork, or server-side use. Exported files need concrete colors such as #000 and #fff; currentColor has nothing to inherit outside a page.
  • qrCodeToPngDataUrl({ value, pixelSize, ... }) returns a browser-side Promise<string> containing a PNG data URL. It scales for devicePixelRatio so print and high-density displays remain crisp and uses a white background by default.
  • buildQRCode(options) returns the pure matrix data { count, total, path, level, version } for custom canvas, poster-composition, or nonstandard rendering.

Pitfalls

  • Do not export a PNG with a transparent background. An exported bitmap cannot inherit the page background, and a transparent code may become unreadable when printed or placed on a white document. qrCodeToPngDataUrl defaults to white for this reason.
  • A logo without excavation must be translucent. An opaque logo with excavate={false} covers modules directly and may make the code unscannable; pair watermark mode with opacity.
  • Unlike qrcode.react's fixed black foreground and white background defaults, QRCode uses currentColor and a transparent background so it follows the theme. qrCodeToPngDataUrl provides export support without adding a second Canvas component and dependency surface.
  • Dark modules default to currentColor; set a text class or explicit color, and provide sufficient background contrast.
  • Use level="H" with logo, or the covered modules may exceed available correction capacity.
  • UTF-8 or long content increases QR density. Increase visual size and scanning distance accordingly.

Related

Sparkline · ImageViewer · LiveProductCard · DiffStat · ScoreRing · Badge

PreviousUserData DisplayNextComment

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Pitfalls
    • Related