Back to Shark UI

QR Code

docs/components/qr-code

latest7.6 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

QR Code

Copy Markdown

Displays a QR code.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/qr-code

Anatomy#

QrCode
├── QrCodeFrame
├── QrCodeOverlay
└── QrCodeDownload

Usage#

import { 
  QrCode, 
  QrCodeFrame,
  QrCodeOverlay,
  QrCodeDownload,
} from "@/components/ui/qr-code";
<QrCode>
  <QrCodeFrame />
  <QrCodeOverlay />
  <QrCodeDownload />
</QrCode>

Size#

Override the size with the --qr-code-size CSS variable on QrCode

For example, --qr-code-size:6rem for small, --qr-code-size:10rem for large

PreviewCode

Examples#

With an overlay#

Use QrCodeOverlay to add an overlay in the center.

PreviewCode

Error correction#

In cases where the link is too long or the logo overlay covers a significant area, the error correction level can be increased.

Use the encoding.ecc property to set the error correction level:

  • L: Allows recovery of up to 7% data loss (default)
  • M: Allows recovery of up to 15% data loss
  • Q: Allows recovery of up to 25% data loss
  • H: Allows recovery of up to 30% data loss

PreviewCode

L

M

Q

H

Download#

Use QrCodeDownload with fileName and mimeType to let users download the QR code as an image.

PreviewCode

Live Preview

PNGSVG

API Reference#

QrCode#

Root wrapper for the QR code and optional overlay/actions.

PropTypeDefault
valuestring-
defaultValuestring-
onValueChange(details: ValueChangeDetails) => void-
encodingQrCodeGenerateOptions-
pixelSizenumber-
classNamestring-
asChildboolean-
AttributeDefault
--qr-code-size--spacing(32)
--qr-code-overlay-sizecalc(var(--qr-code-size)/4)

QrCodeFrame#

SVG containing the QR pattern. Scales with size.

PropTypeDefault
classNamestring-
asChildboolean-

QrCodeOverlay#

Optional center overlay on top of the QR pattern.

PropTypeDefault
classNamestring-
asChildboolean-

QrCodeDownload#

Downloads the QR code as an image file.

PropTypeDefault
fileNamestring-
mimeTypeDataUrlType-
qualitynumber-
classNamestring-
asChildboolean-

For a complete list of props, see the Ark UI documentation.

[

Previous page

Prose ](/docs/components/prose)[

Next page

Radio Group ](/docs/components/radio-group)

On This Page

InstallationAnatomyUsageSizeExamplesWith an overlayError correctionDownloadAPI ReferenceQrCodeQrCodeFrameQrCodeOverlayQrCodeDownload