You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
7 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
|
||
8 years ago
|
export default class Avatar extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
7 years ago
|
account: ImmutablePropTypes.map.isRequired,
|
||
8 years ago
|
size: PropTypes.number.isRequired,
|
||
|
style: PropTypes.object,
|
||
|
animate: PropTypes.bool,
|
||
8 years ago
|
inline: PropTypes.bool,
|
||
8 years ago
|
};
|
||
|
|
||
|
static defaultProps = {
|
||
|
animate: false,
|
||
|
size: 20,
|
||
8 years ago
|
inline: false,
|
||
8 years ago
|
};
|
||
|
|
||
|
state = {
|
||
8 years ago
|
hovering: false,
|
||
8 years ago
|
};
|
||
|
|
||
|
handleMouseEnter = () => {
|
||
8 years ago
|
if (this.props.animate) return;
|
||
8 years ago
|
this.setState({ hovering: true });
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleMouseLeave = () => {
|
||
8 years ago
|
if (this.props.animate) return;
|
||
8 years ago
|
this.setState({ hovering: false });
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
render () {
|
||
7 years ago
|
const { account, size, animate, inline } = this.props;
|
||
8 years ago
|
const { hovering } = this.state;
|
||
|
|
||
7 years ago
|
const src = account.get('avatar');
|
||
|
const staticSrc = account.get('avatar_static');
|
||
|
|
||
8 years ago
|
let className = 'account__avatar';
|
||
|
|
||
|
if (inline) {
|
||
|
className = className + ' account__avatar-inline';
|
||
|
}
|
||
|
|
||
8 years ago
|
const style = {
|
||
|
...this.props.style,
|
||
|
width: `${size}px`,
|
||
|
height: `${size}px`,
|
||
8 years ago
|
backgroundSize: `${size}px ${size}px`,
|
||
8 years ago
|
};
|
||
|
|
||
|
if (hovering || animate) {
|
||
|
style.backgroundImage = `url(${src})`;
|
||
|
} else {
|
||
|
style.backgroundImage = `url(${staticSrc})`;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<div
|
||
8 years ago
|
className={className}
|
||
8 years ago
|
onMouseEnter={this.handleMouseEnter}
|
||
|
onMouseLeave={this.handleMouseLeave}
|
||
|
style={style}
|
||
7 years ago
|
data-avatar-of={`@${account.get('acct')}`}
|
||
8 years ago
|
/>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|