Files
cinny/src/app/atoms/avatar/Avatar.jsx
T

63 lines
1.6 KiB
React
Raw Normal View History

2022-01-09 16:22:04 +05:30
import React from 'react';
2021-07-28 18:45:52 +05:30
import PropTypes from 'prop-types';
import './Avatar.scss';
2021-11-23 11:56:02 +05:30
import { twemojify } from '../../../util/twemojify';
2021-07-28 18:45:52 +05:30
import Text from '../text/Text';
import RawIcon from '../system-icons/RawIcon';
function Avatar({
2021-12-17 11:32:21 +05:30
text, bgColor, iconSrc, iconColor, imageSrc, size,
2021-07-28 18:45:52 +05:30
}) {
let textSize = 's1';
if (size === 'large') textSize = 'h1';
if (size === 'small') textSize = 'b1';
if (size === 'extra-small') textSize = 'b3';
return (
<div className={`avatar-container avatar-container__${size} noselect`}>
{
2022-01-09 16:22:04 +05:30
imageSrc !== null
? <img draggable="false" src={imageSrc} alt="avatar" />
2021-07-28 18:45:52 +05:30
: (
<span
style={{ backgroundColor: iconSrc === null ? bgColor : 'transparent' }}
2021-12-19 10:28:41 +05:30
className={`avatar__border${iconSrc !== null ? '--active' : ''}`}
2021-07-28 18:45:52 +05:30
>
{
iconSrc !== null
2021-12-17 11:32:21 +05:30
? <RawIcon size={size} src={iconSrc} color={iconColor} />
2021-11-23 11:56:02 +05:30
: text !== null && (
2021-12-18 10:10:23 +05:30
<Text variant={textSize} primary>
2021-11-23 11:56:02 +05:30
{twemojify([...text][0])}
</Text>
)
2021-07-28 18:45:52 +05:30
}
</span>
)
}
</div>
);
}
Avatar.defaultProps = {
text: null,
bgColor: 'transparent',
iconSrc: null,
2021-12-17 11:32:21 +05:30
iconColor: null,
2021-07-28 18:45:52 +05:30
imageSrc: null,
size: 'normal',
};
Avatar.propTypes = {
text: PropTypes.string,
bgColor: PropTypes.string,
iconSrc: PropTypes.string,
2021-12-17 11:32:21 +05:30
iconColor: PropTypes.string,
2021-07-28 18:45:52 +05:30
imageSrc: PropTypes.string,
size: PropTypes.oneOf(['large', 'normal', 'small', 'extra-small']),
};
export default Avatar;