UNPKG

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