James Prado 9cac0298a2 Improve accessibility (a11y) (#1267)
* Manage modal focus

* Add isOpen prop to CustomNodeModal

* Remove outline overrides

* Update outline style for inputs

* Fix modal focus management & Cleanup CustomNodeModal

* Add aria-label on modal close button

* Fix modal scroll to top

* Add aria-live property for notifications

* Add aria-busy to Spinner component

* Fix border styles for generatewallet password inputs

* Update token balances inputs

* Remove multiple h1's & Update styles

* Add alt text to all img elements

* Update swap link from bity to shapeshift

* Update aria-labels and alt text

* Only show keystore password input when required

* Revert "Only show keystore password input when required"

This reverts commit 7ec5de52da0982cd3131f365b142f6915638d831.

* address changes requested
2018-03-08 13:28:43 -06:00

72 lines
1.3 KiB
TypeScript

import QRCodeLib from 'qrcode';
import React from 'react';
// FIXME should store limited amount if history
// data -> qr cache
const cache: { [key: string]: string } = {};
interface Props {
data: string;
}
interface State {
qr?: string;
}
export default class QRCode extends React.PureComponent<Props, State> {
public state: State = {};
public componentWillMount() {
// Start generating QR codes immediately
this.generateQrCode(this.props.data);
}
public componentWillReceiveProps(nextProps: Props) {
// Regenerate QR codes if props change
if (nextProps.data !== this.props.data) {
this.generateQrCode(nextProps.data);
}
}
public render() {
const { qr } = this.state;
if (!qr) {
return null;
}
return (
<img
src={qr}
alt="QR Code"
style={{
width: '100%',
height: '100%'
}}
/>
);
}
private generateQrCode(value: string) {
if (cache[value]) {
this.setState({ qr: cache[value] });
return;
}
QRCodeLib.toDataURL(
value,
{
color: {
dark: '#000',
light: '#fff'
},
margin: 0,
errorCorrectionLevel: 'H'
},
(err, qr) => {
if (err) {
return;
}
cache[value] = qr;
this.setState({ qr });
}
);
}
}