UNPKG

813 BJSXView Raw
1const React = require('react');
2const MD5 = require('spark-md5');
3
4const URL = 'https://www.gravatar.com/avatar';
5
6/**
7 * Gravatar
8 * @property {string} email the users email to use with gravatar
9 */
10class Gravatar extends React.Component {
11 static propTypes = {
12 email: React.PropTypes.string.isRequired,
13 default: React.PropTypes.string,
14 size: React.PropTypes.number,
15 style: React.PropTypes.object
16 }
17
18 static defaultProps = {
19 default: 'retro',
20 size: 200,
21 style: {}
22 }
23
24 render() {
25 return <img
26 className={`gravatar ${this.props.className || ''}`}
27 src={`${URL}/${MD5.hash(this.props.email)}?d=${this.props.default}&s=${this.props.size}`}
28 style={this.props.style || {}}/>
29 }
30}
31
32export {Gravatar};
33
\No newline at end of file