Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export QRCodeSVG and QRCodeCanvas directly. #56

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ npm install qrcode.react

```js
var React = require('react');
var QRCode = require('qrcode.react');
var QRCode = require('qrcode.react').QRCodeCanvas; // or QRCodeSVG

React.render(
<QRCode value="http://facebook.github.io/react/" />,
Expand Down
11 changes: 6 additions & 5 deletions examples/demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var QRCode = require('..');
var {QRCodeCanvas, QRCodeSVG} = require('..');
var React = require('react');
var ReactDOM = require('react-dom');

Expand Down Expand Up @@ -36,15 +36,16 @@ class Demo extends React.Component {
excavate: ${this.state.imageExcavate},
}}`
: '';
var code = `<QRCode
var code = `<${this.state.renderAs === 'svg' ? 'QRCodeSVG' : 'QRCodeCanvas'}
value={"${this.state.value}"}
size={${this.state.size}}
bgColor={"${this.state.bgColor}"}
fgColor={"${this.state.fgColor}"}
level={"${this.state.level}"}
includeMargin={${this.state.includeMargin}}
renderAs={"${this.state.renderAs}"}${imageSettingsCode}
includeMargin={${this.state.includeMargin}}${imageSettingsCode}
/>`;

const Component = this.state.renderAs === 'svg' ? QRCodeSVG : QRCodeCanvas;
return (
<div>
<div>
Expand Down Expand Up @@ -257,7 +258,7 @@ class Demo extends React.Component {
</label>
</div>

<QRCode
<Component
value={this.state.value}
size={this.state.size}
fgColor={this.state.fgColor}
Expand Down
11 changes: 1 addition & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,4 @@ if (process.env.NODE_ENV !== 'production') {
QRCodeSVG.propTypes = PROP_TYPES;
}

type RootProps = QRProps & {renderAs: 'svg' | 'canvas'};
const QRCode = (props: RootProps): React.Node => {
const {renderAs, ...otherProps} = props;
const Component = renderAs === 'svg' ? QRCodeSVG : QRCodeCanvas;
return <Component {...otherProps} />;
};

QRCode.defaultProps = {renderAs: 'canvas', ...DEFAULT_PROPS};

module.exports = QRCode;
module.exports = {QRCodeSVG, QRCodeCanvas};