mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-05 02:09:03 +01:00
3d7f68c273
* Revert "Fix some icon names changed by the Font Awesome 5. (#8796)" This reverts commit3f9ec3de82
. * Revert "Migrate to font-awesome 5.0. (#8799)" This reverts commit8bae14591b
. * Revert "Fix some icons names, unavailable in fontawesome5 (free license). (#8792)" This reverts commitb9c727a945
. * Revert "Update the icon name changed by the Font Awesome 5. (#8776)" This reverts commit17af4d27da
. * Revert "Add bot icon to bot avatars and migrate to newer version of Font Awesome (#8484)" This reverts commit4b794e134d
.
72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
import { autoPlayGif } from '../initial_state';
|
|
|
|
export default class Avatar extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
size: PropTypes.number.isRequired,
|
|
style: PropTypes.object,
|
|
inline: PropTypes.bool,
|
|
animate: PropTypes.bool,
|
|
};
|
|
|
|
static defaultProps = {
|
|
animate: autoPlayGif,
|
|
size: 20,
|
|
inline: false,
|
|
};
|
|
|
|
state = {
|
|
hovering: false,
|
|
};
|
|
|
|
handleMouseEnter = () => {
|
|
if (this.props.animate) return;
|
|
this.setState({ hovering: true });
|
|
}
|
|
|
|
handleMouseLeave = () => {
|
|
if (this.props.animate) return;
|
|
this.setState({ hovering: false });
|
|
}
|
|
|
|
render () {
|
|
const { account, size, animate, inline } = this.props;
|
|
const { hovering } = this.state;
|
|
|
|
const src = account.get('avatar');
|
|
const staticSrc = account.get('avatar_static');
|
|
|
|
let className = 'account__avatar';
|
|
|
|
if (inline) {
|
|
className = className + ' account__avatar-inline';
|
|
}
|
|
|
|
const style = {
|
|
...this.props.style,
|
|
width: `${size}px`,
|
|
height: `${size}px`,
|
|
backgroundSize: `${size}px ${size}px`,
|
|
};
|
|
|
|
if (hovering || animate) {
|
|
style.backgroundImage = `url(${src})`;
|
|
} else {
|
|
style.backgroundImage = `url(${staticSrc})`;
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={className}
|
|
onMouseEnter={this.handleMouseEnter}
|
|
onMouseLeave={this.handleMouseLeave}
|
|
style={style}
|
|
/>
|
|
);
|
|
}
|
|
|
|
}
|