|
| 1 | +import { FC } from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { Flex } from '../Flex'; |
| 4 | +import { polyIcons } from '../../theme/icons'; |
| 5 | +import { Icon } from '../Icon'; |
| 6 | + |
| 7 | +export type ProfilePictureVariant = 'text' | 'icon' | 'image'; |
| 8 | + |
| 9 | +export type ProfilePictureProps = { |
| 10 | + text?: string; |
| 11 | + image?: string; |
| 12 | + variant?: ProfilePictureVariant; |
| 13 | + size?: 's' | 'm' | 'l'; |
| 14 | +}; |
| 15 | + |
| 16 | +const iconSizeMap: Record<string, string> = { |
| 17 | + s: '16px', |
| 18 | + m: '26px', |
| 19 | + l: '36px', |
| 20 | +}; |
| 21 | + |
| 22 | +const textSizeMap: Record<string, Record<string, string>> = { |
| 23 | + s: { |
| 24 | + fontWeight: '500', |
| 25 | + fontSize: '14px', |
| 26 | + lineHeight: '24px', |
| 27 | + }, |
| 28 | + m: { |
| 29 | + fontWeight: '500', |
| 30 | + fontSize: '24px', |
| 31 | + lineHeight: '32px', |
| 32 | + }, |
| 33 | + l: { |
| 34 | + fontWeight: '500', |
| 35 | + fontSize: '34px', |
| 36 | + lineHeight: '44px', |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +const ComponentSizeMap: Record<string, Record<string, string>> = { |
| 41 | + s: { |
| 42 | + width: '40px', |
| 43 | + height: '40px', |
| 44 | + }, |
| 45 | + m: { |
| 46 | + width: '88px', |
| 47 | + height: '88px', |
| 48 | + }, |
| 49 | + l: { |
| 50 | + width: '128px', |
| 51 | + height: '128px', |
| 52 | + }, |
| 53 | +}; |
| 54 | + |
| 55 | +const Component = styled(Flex)<any>(({ theme, size, variant, image }) => ({ |
| 56 | + ...ComponentSizeMap[size], |
| 57 | + ...theme.PROFILE_PICTURE, |
| 58 | + ...(variant === 'image' && { backgroundImage: `url(${image})` }), |
| 59 | +})); |
| 60 | + |
| 61 | +const StyledText = styled.p<any>(({ size }) => ({ |
| 62 | + ...textSizeMap[size], |
| 63 | +})); |
| 64 | + |
| 65 | +const renderChildren = ( |
| 66 | + variant: string, |
| 67 | + text: string | undefined, |
| 68 | + size: string, |
| 69 | +) => { |
| 70 | + if (variant === 'icon') { |
| 71 | + return ( |
| 72 | + <Icon |
| 73 | + size={iconSizeMap[size]} |
| 74 | + color="brandDarkest" |
| 75 | + icon={polyIcons.Account} |
| 76 | + variant="basic" |
| 77 | + margin="0" |
| 78 | + /> |
| 79 | + ); |
| 80 | + } else if (variant === 'text') { |
| 81 | + return <StyledText size={size}>{text}</StyledText>; |
| 82 | + } else if (variant === 'image') { |
| 83 | + return <StyledText size={size}>{text}</StyledText>; |
| 84 | + } |
| 85 | +}; |
| 86 | + |
| 87 | +export const ProfilePicture: FC<ProfilePictureProps> = (props) => { |
| 88 | + const { text, variant = 'icon', size = 'm', image } = props; |
| 89 | + return ( |
| 90 | + <Component |
| 91 | + size={size} |
| 92 | + image={image} |
| 93 | + variant={variant} |
| 94 | + align="center" |
| 95 | + justify="center" |
| 96 | + {...props} |
| 97 | + > |
| 98 | + {renderChildren(variant, text, size)} |
| 99 | + </Component> |
| 100 | + ); |
| 101 | +}; |
0 commit comments