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.

51 lines
1.4 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { autoPlayGif } from '../initial_state';
  5. import Avatar from './avatar';
  6. export default class AvatarOverlay extends React.PureComponent {
  7. static propTypes = {
  8. account: ImmutablePropTypes.map.isRequired,
  9. friend: ImmutablePropTypes.map.isRequired,
  10. animate: PropTypes.bool,
  11. size: PropTypes.number,
  12. baseSize: PropTypes.number,
  13. overlaySize: PropTypes.number,
  14. };
  15. static defaultProps = {
  16. animate: autoPlayGif,
  17. size: 46,
  18. baseSize: 36,
  19. overlaySize: 24,
  20. };
  21. state = {
  22. hovering: false,
  23. };
  24. handleMouseEnter = () => {
  25. if (this.props.animate) return;
  26. this.setState({ hovering: true });
  27. };
  28. handleMouseLeave = () => {
  29. if (this.props.animate) return;
  30. this.setState({ hovering: false });
  31. };
  32. render() {
  33. const { account, friend, animate, size, baseSize, overlaySize } = this.props;
  34. const { hovering } = this.state;
  35. return (
  36. <div className='account__avatar-overlay' style={{ width: size, height: size }}>
  37. <div className='account__avatar-overlay-base'><Avatar animate={hovering || animate} account={account} size={baseSize} /></div>
  38. <div className='account__avatar-overlay-overlay'><Avatar animate={hovering || animate} account={friend} size={overlaySize} /></div>
  39. </div>
  40. );
  41. }
  42. }