nifty-wallet/ui/app/components/identicon.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const findDOMNode = require('react-dom').findDOMNode
const jazzicon = require('jazzicon')
const iconFactoryGen = require('../../lib/icon-factory')
const iconFactory = iconFactoryGen(jazzicon)
module.exports = IdenticonComponent
inherits(IdenticonComponent, Component)
2016-06-21 13:18:32 -07:00
function IdenticonComponent () {
Component.call(this)
2016-05-11 02:11:31 -07:00
this.defaultDiameter = 46
}
2016-06-21 13:18:32 -07:00
IdenticonComponent.prototype.render = function () {
2016-10-27 16:16:28 -07:00
var props = this.props
var diameter = props.diameter || this.defaultDiameter
return (
h('div', {
key: 'identicon-' + this.props.address,
style: {
display: 'inline-block',
2016-05-11 02:11:31 -07:00
height: diameter,
width: diameter,
borderRadius: diameter / 2,
overflow: 'hidden',
},
})
)
}
2016-06-21 13:18:32 -07:00
IdenticonComponent.prototype.componentDidMount = function () {
2016-10-27 16:16:28 -07:00
var props = this.props
var address = props.address
if (!address) return
var container = findDOMNode(this)
2016-10-27 16:16:28 -07:00
var diameter = props.diameter || this.defaultDiameter
var img = iconFactory.iconForAddress(address, diameter, false)
2016-05-10 23:53:07 -07:00
container.appendChild(img)
}