0.0.1 • Published 5 years ago

@layerise/qr v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

qrcode.react

A React component to generate QR codes.

Installation

npm install qrcode.react

Usage

var React = require('react');
var QRCode = require('qrcode.react');

React.render(
  <QRCode value="http://facebook.github.io/react/" />,
  mountNode
);

Available Props

proptypedefault value
valuestring
renderAsstring ('canvas' 'svg')'canvas'
sizenumber128
bgColorstring (CSS color)"#FFFFFF"
fgColorstring (CSS color)"#000000"
levelstring ('L' 'M' 'Q' 'H')'L'
includeMarginbooleanfalse
reffunction react's ref
imgsee belowsee below

img Props

proptypedefault value
srcstring
topnumber (percentage)50
leftnumber (percentage)50
widthnumber (percentage)10
heightnumber (percentage)10

Custom Styles

qrcode.react will pass through any additional props to the underlying DOM node (<svg> or <canvas>). This allows the use of inline style or custom className to customize the rendering. One common use would be to support a responsive layout.

Note: In order to render QR Codes in <canvas> on high density displays, we scale the canvas element to contain an appropriate number of pixels and then use inline styles to scale back down. We will merge any additional styles, with custom height and width overriding our own values. This allows scaling to percentages but if scaling beyond the size, you will encounter blurry images. I recommend detecting resizes with something like react-measure to detect and pass the appropriate size when rendering to <canvas>.

Download (or Export) as File

You need to set ref={ref => this.qrcode = ref} to get the component reference first, then call:

this.qrcode.download('QR Code.png');

related methods:

  • genCanvas(overwritingProps): Promise<HTMLCanvasElement>
  • genCanvasDataURL(type, overwritingProps): Promise<string>
  • download(filename, type, overwritingProps)

LICENSE ISC

0.0.1

5 years ago