forked from ethereum/blockies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-component.js
34 lines (31 loc) · 938 Bytes
/
react-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Usage:
// npm install blockies-identicon
// const Blockies = require("blockies/react-component");
// <Blockies opts={{seed: "foo", color: "#dfe", bgcolor: "#a71", size: 15, scale: 3, spotcolor: "#000"}}/>
var React = require('react');
var blockies = require("./blockies");
class BlockiesIdenticon extends React.Component {
constructor(props) {
super(props);
}
getOpts () {
return {
seed: this.props.opts.seed || "foo",
color: this.props.opts.color || "#dfe",
bgcolor: this.props.opts.bgcolor || "#a71",
size: this.props.opts.size || 15,
scale: this.props.opts.scale || 3,
spotcolor: this.props.opts.spotcolor || "#000"
};
}
componentDidMount() {
this.draw();
}
draw() {
blockies.render(this.getOpts(), this.canvas);
}
render() {
return React.createElement("canvas", {ref: canvas => this.canvas = canvas});
}
}
module.exports = BlockiesIdenticon;