File size: 1,827 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import styled from 'styled-components';

import constants from '../utils/constants';
import colors from '../utils/colors';

const StyledUserAvatar = styled.div`
  width: ${props => props.size};
  height: ${props => props.size};
  margin-right: 10px;
  position: relative;
  box-sizing: content-box;
  transition: 0.1s opacity ease-in;

  :hover {
    opacity: ${props => (props.fadeHover ? 0.85 : 1)};
  }

  .avatar {
    width: ${props => props.size};
    height: ${props => props.size};
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    overflow: hidden;
  }

  .fadeHover:hover {
    opacity: 0.9;
  }

  .status {
    position: absolute;
    width: ${props => props.statusSize};
    height: ${props => props.statusSize};

    background-clip: padding-box;
    border-color: ${colors.grayNormal};
    border-style: solid;
    border-width: ${props => (props.isBig ? 3 : 2)}px;
    border-radius: 999px;
    bottom: ${props => (props.isBig ? 0 : -4)}px;
    right: ${props => (props.isBig ? 0 : -2)}px;
  }

  .status.online {
    background-color: #43b581;
    box-shadow: ${props => props.isBig && 'inset 0 0 0 2px rgba(180, 225, 205, 0.6)'};
  }
`;

const UserAvatar = ({ className, avatarUrl, isBig, fadeHover, children }) => {
  const avatarSize = (isBig ? 90 : 30) + 'px';
  const statusSize = (isBig ? 18 : 10) + 'px';

  return (
    <StyledUserAvatar
      className={className}
      size={avatarSize}
      statusSize={statusSize}
      fadeHover={fadeHover}
      isBig={isBig}
    >
      <div
        className="avatar"
        style={{ backgroundImage: `url(${avatarUrl || constants.defaultAvatar})` }}
      >
        {children}
      </div>
      <div className="status online" />
    </StyledUserAvatar>
  );
};

export default UserAvatar;