-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
SubscriptAvatar.tsx
89 lines (79 loc) · 3.69 KB
/
SubscriptAvatar.tsx
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
85
86
87
88
89
import React, {memo} from 'react';
import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import type {Icon} from '@src/types/onyx/OnyxCommon';
import Avatar from './Avatar';
import UserDetailsTooltip from './UserDetailsTooltip';
type SubscriptAvatarProps = {
/** Avatar URL or icon */
mainAvatar?: Icon;
/** Subscript avatar URL or icon */
secondaryAvatar?: Icon;
/** Set the size of avatars */
size?: ValueOf<typeof CONST.AVATAR_SIZE>;
/** Background color used for subscript avatar border */
backgroundColor?: string;
/** Removes margin from around the avatar, used for the chat view */
noMargin?: boolean;
/** Whether to show the tooltip */
showTooltip?: boolean;
};
function SubscriptAvatar({mainAvatar, secondaryAvatar, size = CONST.AVATAR_SIZE.DEFAULT, backgroundColor, noMargin = false, showTooltip = true}: SubscriptAvatarProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const isSmall = size === CONST.AVATAR_SIZE.SMALL;
const subscriptStyle = size === CONST.AVATAR_SIZE.SMALL_NORMAL ? styles.secondAvatarSubscriptSmallNormal : styles.secondAvatarSubscript;
const containerStyle = StyleUtils.getContainerStyles(size);
return (
<View style={[containerStyle, noMargin ? styles.mr0 : {}]}>
<UserDetailsTooltip
shouldRender={showTooltip}
accountID={Number(mainAvatar?.id ?? -1)}
icon={mainAvatar}
>
<View>
<Avatar
containerStyles={StyleUtils.getWidthAndHeightStyle(StyleUtils.getAvatarSize(size || CONST.AVATAR_SIZE.DEFAULT))}
source={mainAvatar?.source}
size={size}
name={mainAvatar?.name}
type={mainAvatar?.type}
fallbackIcon={mainAvatar?.fallbackIcon}
/>
</View>
</UserDetailsTooltip>
<UserDetailsTooltip
shouldRender={showTooltip}
accountID={Number(secondaryAvatar?.id ?? -1)}
icon={secondaryAvatar}
>
<View
style={[size === CONST.AVATAR_SIZE.SMALL_NORMAL ? styles.flex1 : {}, isSmall ? styles.secondAvatarSubscriptCompact : subscriptStyle]}
// Hover on overflowed part of icon will not work on Electron if dragArea is true
// https://stackoverflow.com/questions/56338939/hover-in-css-is-not-working-with-electron
dataSet={{dragArea: false}}
>
<Avatar
iconAdditionalStyles={[
StyleUtils.getAvatarBorderWidth(isSmall ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT),
StyleUtils.getBorderColorStyle(backgroundColor ?? theme.componentBG),
]}
source={secondaryAvatar?.source}
size={isSmall ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT}
name={secondaryAvatar?.name}
type={secondaryAvatar?.type}
fallbackIcon={secondaryAvatar?.fallbackIcon}
/>
</View>
</UserDetailsTooltip>
</View>
);
}
SubscriptAvatar.displayName = 'SubscriptAvatar';
export default memo(SubscriptAvatar);
export type {SubscriptAvatarProps};