import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import './Avatar.scss'; import { twemojify } from '../../../util/twemojify'; import Text from '../text/Text'; import RawIcon from '../system-icons/RawIcon'; function Avatar({ text, bgColor, iconSrc, imageSrc, size, }) { const [image, updateImage] = useState(imageSrc); let textSize = 's1'; if (size === 'large') textSize = 'h1'; if (size === 'small') textSize = 'b1'; if (size === 'extra-small') textSize = 'b3'; useEffect(() => updateImage(imageSrc), [imageSrc]); return (
{ image !== null ? updateImage(null)} alt="avatar" /> : ( { iconSrc !== null ? : text !== null && ( {twemojify([...text][0])} ) } ) }
); } Avatar.defaultProps = { text: null, bgColor: 'transparent', iconSrc: null, imageSrc: null, size: 'normal', }; Avatar.propTypes = { text: PropTypes.string, bgColor: PropTypes.string, iconSrc: PropTypes.string, imageSrc: PropTypes.string, size: PropTypes.oneOf(['large', 'normal', 'small', 'extra-small']), }; export default Avatar;