mattermost-mobile/app/components/server_icon/index.tsx
Joseph Baylon 1d9c371bfb
Detox/E2E: Migrate e2e javascript to typescript (#6059)
* Detox/E2E: Migrate to typescript

* Add jest.config.js

* Add moduleMapper to config.json

* Add cookie jar to axios client, fix tsconfig.json and default_config.json

* Take keyboard into consideration; clean test for now for this migration PR

* Revert changes on path_builder

* Attempt to fix dep issues

* Update detox dep

* Added missing @type dev dependencies

* Fix dep order

* Fix unit tests

* Added dynamic year to email.ts
2022-03-17 17:35:26 -07:00

86 lines
2.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useMemo} from 'react';
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native';
import Badge from '@components/badge';
import CompassIcon from '@components/compass_icon';
import TouchableWithFeedback from '@components/touchable_with_feedback';
import {useTheme} from '@context/theme';
import {changeOpacity} from '@utils/theme';
type Props = {
badgeBackgroundColor?: string;
badgeBorderColor?: string;
badgeColor?: string;
badgeStyle?: StyleProp<ViewStyle>;
hasUnreads: boolean;
iconColor?: string;
mentionCount: number;
onPress?: () => void;
size?: number;
style?: StyleProp<ViewStyle>;
testID?: string;
unreadStyle?: StyleProp<ViewStyle>;
}
const styles = StyleSheet.create({
badge: {
left: 13,
top: -8,
},
unread: {
left: 18,
top: -5,
},
});
export default function ServerIcon({
badgeBackgroundColor,
badgeBorderColor,
badgeColor,
badgeStyle,
hasUnreads,
iconColor,
mentionCount,
onPress,
size = 24,
style,
testID,
unreadStyle,
}: Props) {
const theme = useTheme();
const hasBadge = Boolean(mentionCount || hasUnreads);
const count = mentionCount || (hasUnreads ? -1 : 0);
const memoizedStyle = useMemo(() => {
return [(badgeStyle || styles.badge), count > -1 ? undefined : (unreadStyle || styles.unread)];
}, [badgeStyle, count, unreadStyle]);
return (
<View style={style}>
<TouchableWithFeedback
disabled={onPress === undefined}
onPress={onPress}
type='opacity'
testID={testID}
>
<CompassIcon
size={size}
name='server-variant'
color={iconColor || changeOpacity(theme.sidebarHeaderTextColor, 0.56)}
/>
<Badge
borderColor={badgeBorderColor || theme.sidebarTeamBarBg}
backgroundColor={badgeBackgroundColor}
color={badgeColor}
visible={hasBadge}
style={memoizedStyle}
testID={`${testID}.badge`}
value={count}
/>
</TouchableWithFeedback>
</View>
);
}