Loëck Vézien
7 years ago
committed by
GitHub
4 changed files with 84 additions and 0 deletions
@ -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 |
@ -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)} />) |
Loading…
Reference in new issue