import { Text, StyleSheet, View, Image, TextStyle, ViewStyle, ImageStyle, StyleProp } from 'react-native'; import React from 'react'; import { ThemeType } from '../themes/hero/index'; import { useTheme } from './ThemeContext'; export type size = 'small' | 'medium' | 'large'; const getStylesBySize = ( size: null | undefined | size, styles: ThemeType['avatar'], ): { wrapper: StyleProp; titleWrapper: StyleProp; title: StyleProp; image: StyleProp; } => { switch (size) { case 'large': { return { wrapper: styles.largeWrapper, titleWrapper: styles.largeTitleWrapper, title: styles.largeTitle, image: styles.largeImage, }; } case 'small': { return { wrapper: styles.smallWrapper, titleWrapper: styles.smallTitleWrapper, title: styles.smallTitle, image: styles.smallImage, }; } default: { return { wrapper: styles.mediumWrapper, titleWrapper: styles.mediumTitleWrapper, title: styles.mediumTitle, image: styles.mediumImage, }; } } }; export type Props = { readonly size?: size; readonly source?: string; readonly testID?: string; readonly title?: string; readonly titleStyle?: StyleProp; readonly wrapperStyle?: StyleProp; }; const Avatar: React.ComponentType = ({ size, source, testID, title = '', titleStyle, wrapperStyle }: Props) => { const theme = useTheme(); const styles = getStylesBySize(size, theme.avatar); return ( {title} {source !== undefined && ( )} ); }; export default Avatar;