Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from no23reason/features/size-deprecation-warning
Browse files Browse the repository at this point in the history
Prepare to deprecate size prop
  • Loading branch information
no23reason authored Jun 20, 2017
2 parents 17aa546 + 804d25b commit 52f16eb
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 45 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import { QRCode } from 'react-qr-svg';
class Demo extends React.Component {
render() {
return (<QRCode
value="some text"
size={512}
level="Q"
bgColor="#FFFFFF"
fgColor="#000000"
level="Q"
style={{ width: 256 }}
value="some text"
/>);
}
}
Expand All @@ -50,7 +50,7 @@ The props available are (shown with default values):
```js
{
value: '', // The value to encode in the code
size: 256, // Size of the code in pixels
size: 256, // Size of the code in pixels. This is obsolete and will be removed in the next major version!
level: 'L', // QR Error correction level
bgColor: '#FFFFFF', // Color of the bright squares
fgColor: '#000000', // Color of the dark squares
Expand All @@ -59,6 +59,8 @@ The props available are (shown with default values):

The `level` prop corresponds to [Error correction level](https://en.wikipedia.org/wiki/QR_code#Error_correction) so the valid values are `L`, `M`, `Q` and `H`.

You can also specify all the props that are valid for the `<svg>` React element (e.g. `style`, `className` or `width` which you can use to specify the size of the QR code).

## Acknowledgements
This project is heavily inspired by the [`qrcode.react`](https://github.com/zpao/qrcode.react) project.

Expand Down
10 changes: 8 additions & 2 deletions demo/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Demo extends React.Component {
updateFgColor = e => this.setState({ ...this.state, fgColor: e.target.value });

render() {
const {state, updateSize, updateValue, updateLevel, updateBgColor, updateFgColor} = this;
const { state, updateSize, updateValue, updateLevel, updateBgColor, updateFgColor } = this;
return (<div>
<form className="pure-form pure-form-stacked">
<fieldset>
Expand Down Expand Up @@ -53,7 +53,13 @@ class Demo extends React.Component {
</fieldset>
</form>
<div className="qrcode">
<QRCode bgColor={state.bgColor} fgColor={state.fgColor} level={state.level} size={state.size} value={state.value} />
<QRCode
bgColor={state.bgColor}
fgColor={state.fgColor}
level={state.level}
style={{ width: state.size }}
value={state.value}
/>
</div>
</div>);
}
Expand Down
6 changes: 3 additions & 3 deletions docs-resources/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { QRCode } from 'react-qr-svg';
class Demo extends React.Component {
render() {
return (<QRCode
value="some text"
size={512}
level="Q"
bgColor="#FFFFFF"
fgColor="#000000"
level="Q"
style={{ width: 256 }}
value="some text"
/>);
}
}
Expand Down
20 changes: 0 additions & 20 deletions docs/app.4f68334a5808e054e71f.js

This file was deleted.

15 changes: 15 additions & 0 deletions docs/app.9f75ed5a44b04282b735.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



<link href="style.6139a0e7899fe1906c11.css" rel="stylesheet"></head>
<link href="style.0f46ed9cbf5e2764169e.css" rel="stylesheet"></head>
<body>
<div class="pure-g">
<header class="pure-u-1">
Expand All @@ -35,17 +35,17 @@ <h1>react-qr-svg</h1>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
render() {
<span class="hljs-keyword">return</span> (&lt;QRCode
value=&quot;some text&quot;
size={512}
level=&quot;Q&quot;
bgColor=&quot;#FFFFFF&quot;
fgColor=&quot;#000000&quot;
level=&quot;Q&quot;
style={{ width: 256 }}
value=&quot;some text&quot;
/&gt;);
}
}
</code></pre></pre><p><span>For the complete API documentation and more, please see the </span><a href="https://github.com/no23reason/react-qr-svg/blob/master/README.md"><span>README</span></a><span>.</span></p></div></div>
</section>
</article>
</div>
<script type="text/javascript" src="manifest.9817e370d02e630febf8.js"></script><script type="text/javascript" src="vendors.ec50d40b112c61dff298.js"></script><script type="text/javascript" src="app.4f68334a5808e054e71f.js"></script><script type="text/javascript" src="style.6139a0e7899fe1906c11.js"></script></body>
<script type="text/javascript" src="manifest.13035e058901d5ab0fde.js"></script><script type="text/javascript" src="vendors.f5af5a37821b3505a0eb.js"></script><script type="text/javascript" src="app.9f75ed5a44b04282b735.js"></script><script type="text/javascript" src="style.0f46ed9cbf5e2764169e.js"></script></body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Pure v0.6.2
Pure v1.0.0
Copyright 2013 Yahoo!
Licensed under the BSD License.
https://github.com/yahoo/pure/blob/master/LICENSE.md
Expand Down
1 change: 1 addition & 0 deletions docs/style.0f46ed9cbf5e2764169e.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/style.6139a0e7899fe1906c11.js

This file was deleted.

6 changes: 0 additions & 6 deletions docs/vendors.ec50d40b112c61dff298.js

This file was deleted.

6 changes: 6 additions & 0 deletions docs/vendors.f5af5a37821b3505a0eb.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ interface QRCodeProps {
/**
* The component
*/
export function QRCode(props: QRCodeProps): React.ReactElement<{}>;
export function QRCode(props: QRCodeProps & React.SVGProps): React.ReactElement<{}>;
11 changes: 10 additions & 1 deletion src/components/qr-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ import PropTypes from 'prop-types';
const QRCodeImpl = require('qr.js/lib/QRCode');
const ErrorCorrectLevel = require('qr.js/lib/ErrorCorrectLevel');

let warningFired = false;

export function QRCode({
value = '',
size,
level = 'L',
bgColor = '#FFFFFF',
fgColor = '#000000',
...otherProps
} = {}) {
if (size && !warningFired) {
/* eslint-disable no-console */
console.warn('The \'size\' prop is deprecated and will be removed in the next major version. Please use the \'style\', \'className\' or \'width\' props to size the code.');
/* eslint-enable no-console */
warningFired = true;
}
// adapted from https://github.com/zpao/qrcode.react/blob/master/src/index.js
const qrcode = new QRCodeImpl(-1, ErrorCorrectLevel[level]);
qrcode.addData(value);
qrcode.make();

const cells = qrcode.modules;

return (<svg shapeRendering="crispEdges" viewBox={[0, 0, cells.length, cells.length].join(' ')} width={size}>
return (<svg shapeRendering="crispEdges" viewBox={[0, 0, cells.length, cells.length].join(' ')} width={size} {...otherProps}>
{
cells.map((row, rowIndex) =>
row.map((cell, colIndex) => (
Expand Down
1 change: 1 addition & 0 deletions tests/typescript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Demo extends React.Component<IDemoProps, {}> {
return <div>
<QRCode bgColor="#FFFFFF" fgColor="#000000" level="M" size={512} value={this.props.text} />
<QRCode value="Only value here" />
<QRCode value="Style here" style={{ width: 250 }} />
</div>;
}
}

0 comments on commit 52f16eb

Please sign in to comment.