Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-qrcode-logo

gcoro330.8kMIT3.0.0TypeScript support: included

React component to generate a QR Code customizable with logo and more properties

react, typescript, qrcode, custom, logo, opacity, padding

readme

react-qrcode-logo

Typescript React component to generate a customizable QR Code.

Installation

npm install --save react-qrcode-logo

Usage

// import
import { QRCode } from 'react-qrcode-logo';

// usage
<QRCode value="https://github.com/gcoro/react-qrcode-logo" />

Compatibility

If you are using a React version >= 18, use react-qrcode-logo version >= 3.0.0

Props

Prop Type Default value Description
value string https://reactjs.org/ The value encoded in the QR Code. When the QR Code is decoded, this value will be returned
ecLevel L | M | Q | H M The error correction level of the QR Code
enableCORS boolean false Enable crossorigin attribute
size number (in pixels) 150 The size of the QR Code
quietZone number (in pixels) 10 The size of the quiet zone around the QR Code. This will have the same color as QR Code bgColor
bgColor string (css color) #FFFFFF Background color
fgColor string (css color) #000000 Foreground color
logoImage string (src attribute) | The logo image. It can be a url/path or a base64 value
logoWidth number (in pixels) size * 0.2 Logo image width
logoHeight number (in pixels) logoWidth Logo image height
logoOpacity number (css opacity 0 <= x <= 1) 1 Logo opacity. This allows you to modify the transparency of your logo, so that it won't compromise the readability of the QR Code
removeQrCodeBehindLogo boolean false Removes points behind the logo. If no logoPadding is specified, the removed part will have the same size as the logo
logoPadding number | Adds a border with no points around the logo. When > 0, the padding will be visible even if the prop removeQrCodeBehindLogo is not set to true
logoPaddingStyle square | circle square Sets the shape of the padding area around the logo
qrStyle squares | dots | fluid squares Style of the QR Code modules
eyeRadius CornerRadii | CornerRadii[] | The corner radius for the positional patterns (the three "eyes" around the QR code). See more details here
eyeColor EyeColor | EyeColor[] | The color for the positional patterns (the three "eyes" around the QR code). See more details here
id string react-qrcode-logo Optional custom id for the QRCode canvas. You can use this prop if you have multiple QRCodes and need to differentiate them
style React.CSSProperties | CSS style properties that will be applied to the canvas component

Events

Event Name Returns Description
logoOnLoad event: Event Event that fires when the QR Code logo image has been loaded

Methods

Methods must be called on a valid QRCode ref - learn more.

Method Name Arguments Description
download fileType?: 'png' | 'jpg' | 'webp', fileName?: string This function will download the QR Code as image. Format and file name can be specified

Example

You can find a demo project here.

Contributing

PRs and suggestions are welcome. When making a pull request, please explain in a clear way the changes you made and why you are making them (+ if you can also update the README accordingly, ty <3). Also try keep the current repo codestyle (eg. do not reformat all the code with prettier).

Thanks to everyone who contributed and/or will contribute :)

More credits

This package was inspired by cssivision/qrcode-react and zpao/qrcode.react. Also looked up some parts from kazuhikoarase/qrcode-generator (which this package depends on).

changelog

Changelog

[v3.0.0]

Fixes

  • Removed use of ReactDOM.findDOMNode, which has been deprecated in React 18, and removed in React 19.

Features

  • Added download function to save the QRCode as image.
  • Added optional style prop to pass CSS to the canvas.
  • logoOnLoad callback now also returns the event details.

[v2.10.0]

Features

  • Added new qrStyle: fluid.

[v2.9.0]

Features

  • Added new optional prop logoPadding to specify optional padding around the logo.
  • Added new optional prop logoPaddingStyle to specify the shape of the logo padding (rectangular with 'square' or elliptic with 'circle').

Changes

  • Prop removeQrCodeBehindLogo does not have a default padding anymore, but has the same size as the logo.

[v2.8.0]

Features

  • Added new optional prop eyeColor to specify different colors for the positional patterns.

[v2.7.0]

Features

  • Added optional prop removeQrCodeBehindLogo, if set to true will draw an empty square around the logo.

[v2.6.0]

Features

  • Added optional prop id to specify the id of the canvas element.

[v2.5.0]

Features

  • Added new optional prop eyeRadius to specify the corner radius for the positional patterns.

[v2.2.1]

Fixes

  • Changed quietZone implementation so that it's included directly in the canvas, instead of just an HTML padding. This fixes the issue that caused the QR Code to appear without the quiet zone when it got saved.

[v2.2.0]

Features

  • Added new optional prop qrStyle ('squares' | 'dots'), to specify a different pattern for the QR Code main part.

Changes

  • Changed the prop name padding to quietZone, for a clearer naming. The purpose of this prop is to define the width of the quiet zone around the QR Code, which a part of the QR Code needed by the scanner to distinguish the QRCode from the surroundings.
  • Removed prop style.

Fixes

  • Fixed padding/quietZone value which was applied in percentage, and leaded to incorrect values sometimes.

[v2.1.0]

Features

  • Made CORS optional, by adding a new prop enableCORS.

[v2.0.1]

Fixes

  • Enabled CORS for logo image.

[v2.0.0]

Refactor

  • Replaced the package used to implement the QRCode, from qr.js to qrcode-generator.

[v1.0.0]

  • First version.