-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathAvatar.styled.tsx
More file actions
executable file
·84 lines (73 loc) · 2.83 KB
/
Avatar.styled.tsx
File metadata and controls
executable file
·84 lines (73 loc) · 2.83 KB
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
77
78
79
80
81
82
83
84
import { WithThemeProp } from '@medly-components/utils';
import styled, { css } from 'styled-components';
import Text from '../Text';
import { StyledProps } from './types';
const getAvatarSize = ({ theme: { avatar }, size }: StyledProps & WithThemeProp) => {
const { sizes, defaults } = avatar;
return sizes[size || defaults.size].avatarSize;
};
const getShadowColor = ({ theme: { avatar }, hoverTextShadowColor, hoverImgShadowColor, isImage }: StyledProps & WithThemeProp) => {
return isImage
? hoverImgShadowColor || avatar.defaults.hover.imgShadowColor
: hoverTextShadowColor || avatar.defaults.hover.textShadowColor;
};
const hoverStyle = ({ theme, hoverBgColor, hoverTextColor }: StyledProps & WithThemeProp) => {
const { defaults } = theme.avatar;
return css`
&:hover {
background: ${hoverBgColor || defaults.hover.bgColor};
box-shadow: 0 0.4rem 0.8rem ${getShadowColor};
${Text.Style} {
color: ${hoverTextColor || defaults.hover.textColor};
}
}
`;
};
const pressedStyle = ({ theme, pressedBgColor, pressedTextColor }: StyledProps & WithThemeProp) => {
const { defaults } = theme.avatar;
return css`
&:active {
background: ${pressedBgColor || defaults.pressed.bgColor};
${Text.Style} {
color: ${pressedTextColor || defaults.pressed.textColor};
}
}
`;
};
const getTextStyle = ({ theme, ...props }: StyledProps & WithThemeProp) => {
const { size, textColor, bgColor } = props,
{ defaults, sizes } = theme.avatar,
{ avatarSize, fontSize } = sizes[size || defaults.size];
return css`
color: ${textColor || defaults.textColor};
background: ${bgColor || defaults.bgColor};
user-select: none;
${Text.Style} {
line-height: ${avatarSize};
font-size: ${fontSize};
font-weight: ${theme.font.weights[defaults.fontWeight]};
font-family: ${defaults.fontFamily};
}
`;
};
export const AvatarStyled = styled('div')<StyledProps>`
display: inline-block;
text-align: center;
min-width: max-content;
width: ${getAvatarSize};
height: ${getAvatarSize};
border-radius: ${({ theme }) => theme.avatar.defaults.borderRadius};
overflow: hidden;
cursor: ${({ onClick, disabled }) => (disabled ? 'not-allowed' : onClick ? 'pointer' : 'inherit')};
${getTextStyle}
img {
width: ${getAvatarSize};
height: ${getAvatarSize};
object-fit: cover;
border: 0.1rem solid ${({ theme }) => theme.avatar.defaults.borderColor};
box-sizing: border-box;
border-radius: ${({ theme }) => theme.avatar.defaults.borderRadius};
}
${props => props.onClick && hoverStyle};
${props => props.onClick && pressedStyle};
`;