1 | const cx = require('classnames');
|
2 | const React = require('react');
|
3 | const MD5 = require('spark-md5');
|
4 |
|
5 | const URL = 'https://www.gravatar.com/avatar';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | class 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 |
|
37 | export {Gravatar};
|
38 |
|
\ | No newline at end of file |