Browse Source

Merge pull request #48 from meriadec/master

Add QRCode component
master
Loëck Vézien 7 years ago
committed by GitHub
parent
commit
2bb5a569f5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      package.json
  2. 39
      src/components/base/QRCode/index.js
  3. 12
      src/components/base/QRCode/stories.js
  4. 32
      yarn.lock

1
package.json

@ -59,6 +59,7 @@
"i18next-node-fs-backend": "^1.0.0",
"lodash": "^4.17.4",
"object-path": "^0.11.4",
"qrcode": "^1.2.0",
"raven": "^2.3.0",
"raven-js": "^3.22.1",
"react": "^16.2.0",

39
src/components/base/QRCode/index.js

@ -0,0 +1,39 @@
// @flow
import React, { PureComponent } from 'react'
import qrcode from 'qrcode'
type Props = {
data: string,
size?: number,
}
class QRCode extends PureComponent<Props> {
static defaultProps = {
size: 200,
}
componentDidMount() {
this.drawQRCode()
}
componentDidUpdate() {
this.drawQRCode()
}
_canvas = null
drawQRCode() {
const { data, size } = this.props
qrcode.toCanvas(this._canvas, data, {
width: size,
margin: 0,
})
}
render() {
return <canvas ref={n => (this._canvas = n)} />
}
}
export default QRCode

12
src/components/base/QRCode/stories.js

@ -0,0 +1,12 @@
// @flow
import React from 'react'
import { storiesOf } from '@storybook/react'
import { text, number } from '@storybook/addon-knobs'
import QRCode from 'components/base/QRCode'
const stories = storiesOf('QRCode', module)
stories.add('basic', () => <QRCode data={text('data', 'sample')} size={number('size', 200)} />)

32
yarn.lock

@ -2128,6 +2128,12 @@ camelcase@^4.0.0, camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
can-promise@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/can-promise/-/can-promise-0.0.1.tgz#7a7597ad801fb14c8b22341dfec314b6bd6ad8d3"
dependencies:
window-or-global "^1.0.1"
caniuse-api@^1.5.2:
version "1.6.1"
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-1.6.1.tgz#b534e7c734c4f81ec5fbe8aca2ad24354b962c6c"
@ -3004,6 +3010,10 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0"
randombytes "^2.0.0"
dijkstrajs@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/dijkstrajs/-/dijkstrajs-1.0.1.tgz#d3cd81221e3ea40742cfcde556d4e99e98ddc71b"
dmg-builder@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/dmg-builder/-/dmg-builder-3.1.1.tgz#6e363919235d509df582c143ad5aa90b1ec0a994"
@ -5222,6 +5232,10 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
isarray@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.2.tgz#5aa99638daf2248b10b9598b763a045688ece3ee"
isbinaryfile@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-3.0.2.tgz#4a3e974ec0cba9004d3fc6cde7209ea69368a621"
@ -6640,6 +6654,10 @@ pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
pngjs@^3.3.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-3.3.1.tgz#8e14e6679ee7424b544334c3b2d21cea6d8c209a"
podda@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/podda/-/podda-1.2.2.tgz#15b0edbd334ade145813343f5ecf9c10a71cf500"
@ -7126,6 +7144,16 @@ q@^1.1.2, q@^1.4.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
qrcode@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/qrcode/-/qrcode-1.2.0.tgz#330d24313fbf8d429a806091af9525250239e44a"
dependencies:
can-promise "^0.0.1"
dijkstrajs "^1.0.1"
isarray "^2.0.1"
pngjs "^3.3.0"
yargs "^8.0.2"
qs@6.5.1, qs@^6.5.1, qs@~6.5.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
@ -9311,6 +9339,10 @@ wif@^2.0.1:
dependencies:
bs58check "<3.0.0"
window-or-global@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/window-or-global/-/window-or-global-1.0.1.tgz#dbe45ba2a291aabc56d62cf66c45b7fa322946de"
window-size@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"

Loading…
Cancel
Save