insomnia/app/ui/components/gravatar-img.js
Gregory Schier 8452e8b777 Some eslint refactoring (#109)
* Fixed duplication kve bug

* Some changes

* Add proptypes linting

* Fixed proptypes even more

* Filename linting
2017-03-07 21:52:17 -08:00

34 lines
836 B
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import crypto from 'crypto';
class GravatarImg extends PureComponent {
render () {
const {email, size, className} = this.props;
const sanitizedEmail = email.trim().toLowerCase();
const hash = crypto
.createHash('md5')
.update(sanitizedEmail)
.digest('hex');
const url = `https://www.gravatar.com/avatar/${hash}?s=${size * 2}`;
const cssSize = `${size}px`;
return (
<img src={url}
alt="Profile picture"
className={className}
title={sanitizedEmail}
style={{width: cssSize, height: cssSize}}/>
);
}
}
GravatarImg.propTypes = {
// Required
email: PropTypes.string.isRequired,
// Optional
size: PropTypes.number,
className: PropTypes.string
};
export default GravatarImg;