Files
cinny/src/app/molecules/sidebar-avatar/SidebarAvatar.jsx
T

81 lines
2.0 KiB
React
Raw Normal View History

2021-07-28 18:45:52 +05:30
import React from 'react';
import PropTypes from 'prop-types';
import './SidebarAvatar.scss';
2021-11-23 16:33:35 +05:30
import { twemojify } from '../../../util/twemojify';
2021-07-28 18:45:52 +05:30
import Avatar from '../../atoms/avatar/Avatar';
import Text from '../../atoms/text/Text';
import Tooltip from '../../atoms/tooltip/Tooltip';
2021-07-28 18:45:52 +05:30
import NotificationBadge from '../../atoms/badge/NotificationBadge';
import { blurOnBubbling } from '../../atoms/button/script';
const SidebarAvatar = React.forwardRef(({
tooltip, text, bgColor, imageSrc,
iconSrc, active, onClick, onContextMenu,
isUnread, notificationCount, isAlert,
2021-07-28 18:45:52 +05:30
}, ref) => {
let activeClass = '';
if (active) activeClass = ' sidebar-avatar--active';
return (
<Tooltip
2021-11-23 16:33:35 +05:30
content={<Text variant="b1">{twemojify(tooltip)}</Text>}
2021-07-28 18:45:52 +05:30
placement="right"
>
<button
ref={ref}
className={`sidebar-avatar${activeClass}`}
type="button"
onMouseUp={(e) => blurOnBubbling(e, '.sidebar-avatar')}
onClick={onClick}
onContextMenu={onContextMenu}
2021-07-28 18:45:52 +05:30
>
<Avatar
text={text}
bgColor={bgColor}
imageSrc={imageSrc}
iconSrc={iconSrc}
size="normal"
/>
{ isUnread && (
<NotificationBadge
alert={isAlert}
content={notificationCount !== 0 ? notificationCount : null}
/>
)}
2021-07-28 18:45:52 +05:30
</button>
</Tooltip>
2021-07-28 18:45:52 +05:30
);
});
SidebarAvatar.defaultProps = {
text: null,
bgColor: 'transparent',
iconSrc: null,
imageSrc: null,
active: false,
onClick: null,
onContextMenu: null,
isUnread: false,
notificationCount: 0,
isAlert: false,
2021-07-28 18:45:52 +05:30
};
SidebarAvatar.propTypes = {
tooltip: PropTypes.string.isRequired,
text: PropTypes.string,
bgColor: PropTypes.string,
imageSrc: PropTypes.string,
iconSrc: PropTypes.string,
active: PropTypes.bool,
onClick: PropTypes.func,
onContextMenu: PropTypes.func,
isUnread: PropTypes.bool,
notificationCount: PropTypes.oneOfType([
2021-07-28 18:45:52 +05:30
PropTypes.string,
PropTypes.number,
]),
isAlert: PropTypes.bool,
2021-07-28 18:45:52 +05:30
};
export default SidebarAvatar;