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 Text from '../../atoms/text/Text';
|
2021-09-12 20:44:13 +05:30
|
|
|
import Tooltip from '../../atoms/tooltip/Tooltip';
|
2021-07-28 18:45:52 +05:30
|
|
|
import { blurOnBubbling } from '../../atoms/button/script';
|
|
|
|
|
|
|
|
|
|
const SidebarAvatar = React.forwardRef(({
|
2022-04-24 15:42:24 +05:30
|
|
|
className, tooltip, active, onClick,
|
|
|
|
|
onContextMenu, avatar, notificationBadge,
|
2021-07-28 18:45:52 +05:30
|
|
|
}, ref) => {
|
2022-04-24 15:42:24 +05:30
|
|
|
const classes = ['sidebar-avatar'];
|
|
|
|
|
if (active) classes.push('sidebar-avatar--active');
|
|
|
|
|
if (className) classes.push(className);
|
2021-07-28 18:45:52 +05:30
|
|
|
return (
|
2021-09-12 20:44:13 +05:30
|
|
|
<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}
|
2022-04-24 15:42:24 +05:30
|
|
|
className={classes.join(' ')}
|
2021-07-28 18:45:52 +05:30
|
|
|
type="button"
|
|
|
|
|
onMouseUp={(e) => blurOnBubbling(e, '.sidebar-avatar')}
|
|
|
|
|
onClick={onClick}
|
2022-01-29 14:30:42 +05:30
|
|
|
onContextMenu={onContextMenu}
|
2021-07-28 18:45:52 +05:30
|
|
|
>
|
2022-03-07 21:05:47 +05:30
|
|
|
{avatar}
|
|
|
|
|
{notificationBadge}
|
2021-07-28 18:45:52 +05:30
|
|
|
</button>
|
2021-09-12 20:44:13 +05:30
|
|
|
</Tooltip>
|
2021-07-28 18:45:52 +05:30
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
SidebarAvatar.defaultProps = {
|
2022-04-24 15:42:24 +05:30
|
|
|
className: null,
|
2021-07-28 18:45:52 +05:30
|
|
|
active: false,
|
|
|
|
|
onClick: null,
|
2022-01-29 14:30:42 +05:30
|
|
|
onContextMenu: null,
|
2022-03-07 21:05:47 +05:30
|
|
|
notificationBadge: null,
|
2021-07-28 18:45:52 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SidebarAvatar.propTypes = {
|
2022-04-24 15:42:24 +05:30
|
|
|
className: PropTypes.string,
|
2021-07-28 18:45:52 +05:30
|
|
|
tooltip: PropTypes.string.isRequired,
|
|
|
|
|
active: PropTypes.bool,
|
|
|
|
|
onClick: PropTypes.func,
|
2022-01-29 14:30:42 +05:30
|
|
|
onContextMenu: PropTypes.func,
|
2022-03-07 21:05:47 +05:30
|
|
|
avatar: PropTypes.node.isRequired,
|
|
|
|
|
notificationBadge: PropTypes.node,
|
2021-07-28 18:45:52 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SidebarAvatar;
|