Files
cinny/src/app/molecules/room-selector/RoomSelector.jsx
T

98 lines
2.5 KiB
React
Raw Normal View History

2021-07-28 18:45:52 +05:30
import React from 'react';
import PropTypes from 'prop-types';
2021-08-31 18:43:31 +05:30
import './RoomSelector.scss';
2021-07-28 18:45:52 +05:30
2021-11-23 11:56:02 +05:30
import { twemojify } from '../../../util/twemojify';
2021-07-28 18:45:52 +05:30
import colorMXID from '../../../util/colorMXID';
import Text from '../../atoms/text/Text';
import Avatar from '../../atoms/avatar/Avatar';
import NotificationBadge from '../../atoms/badge/NotificationBadge';
import { blurOnBubbling } from '../../atoms/button/script';
2021-08-31 18:43:31 +05:30
function RoomSelectorWrapper({
2021-09-09 17:35:39 +05:30
isSelected, isUnread, onClick, content, options,
2021-08-29 13:57:55 +05:30
}) {
2021-09-09 17:35:39 +05:30
let myClass = isUnread ? ' room-selector--unread' : '';
myClass += isSelected ? ' room-selector--selected' : '';
2021-08-29 13:57:55 +05:30
return (
2021-09-09 17:35:39 +05:30
<div className={`room-selector${myClass}`}>
2021-08-29 13:57:55 +05:30
<button
2021-08-31 18:43:31 +05:30
className="room-selector__content"
2021-08-29 13:57:55 +05:30
type="button"
onClick={onClick}
2021-08-31 18:43:31 +05:30
onMouseUp={(e) => blurOnBubbling(e, '.room-selector')}
2021-08-29 13:57:55 +05:30
>
{content}
</button>
2021-08-31 18:43:31 +05:30
<div className="room-selector__options">{options}</div>
2021-08-29 13:57:55 +05:30
</div>
);
}
2021-08-31 18:43:31 +05:30
RoomSelectorWrapper.defaultProps = {
2021-08-29 13:57:55 +05:30
options: null,
};
2021-08-31 18:43:31 +05:30
RoomSelectorWrapper.propTypes = {
2021-08-29 13:57:55 +05:30
isSelected: PropTypes.bool.isRequired,
2021-09-09 17:35:39 +05:30
isUnread: PropTypes.bool.isRequired,
2021-08-29 13:57:55 +05:30
onClick: PropTypes.func.isRequired,
content: PropTypes.node.isRequired,
options: PropTypes.node,
};
2021-08-31 18:43:31 +05:30
function RoomSelector({
2021-08-29 13:57:55 +05:30
name, roomId, imageSrc, iconSrc,
isSelected, isUnread, notificationCount, isAlert,
options, onClick,
2021-07-28 18:45:52 +05:30
}) {
return (
2021-08-31 18:43:31 +05:30
<RoomSelectorWrapper
2021-08-29 13:57:55 +05:30
isSelected={isSelected}
2021-09-09 17:35:39 +05:30
isUnread={isUnread}
2021-08-29 13:57:55 +05:30
content={(
<>
2021-07-28 18:45:52 +05:30
<Avatar
text={name}
2021-07-28 18:45:52 +05:30
bgColor={colorMXID(roomId)}
imageSrc={imageSrc}
iconSrc={iconSrc}
size="extra-small"
/>
2021-11-23 11:56:02 +05:30
<Text variant="b1">{twemojify(name)}</Text>
2021-08-29 13:57:55 +05:30
{ isUnread && (
2021-08-28 18:16:20 +05:30
<NotificationBadge
2021-08-29 13:57:55 +05:30
alert={isAlert}
2021-08-28 18:16:20 +05:30
content={notificationCount !== 0 ? notificationCount : null}
/>
)}
2021-08-29 13:57:55 +05:30
</>
)}
options={options}
onClick={onClick}
/>
2021-07-28 18:45:52 +05:30
);
}
2021-08-31 18:43:31 +05:30
RoomSelector.defaultProps = {
2021-09-09 17:35:39 +05:30
isSelected: false,
2021-07-28 18:45:52 +05:30
imageSrc: null,
2021-08-29 13:57:55 +05:30
iconSrc: null,
options: null,
2021-07-28 18:45:52 +05:30
};
2021-08-31 18:43:31 +05:30
RoomSelector.propTypes = {
2021-08-29 13:57:55 +05:30
name: PropTypes.string.isRequired,
2021-07-28 18:45:52 +05:30
roomId: PropTypes.string.isRequired,
2021-08-29 13:57:55 +05:30
imageSrc: PropTypes.string,
iconSrc: PropTypes.string,
2021-09-09 17:35:39 +05:30
isSelected: PropTypes.bool,
2021-08-29 13:57:55 +05:30
isUnread: PropTypes.bool.isRequired,
notificationCount: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
2021-08-29 13:57:55 +05:30
isAlert: PropTypes.bool.isRequired,
options: PropTypes.node,
2021-07-28 18:45:52 +05:30
onClick: PropTypes.func.isRequired,
};
2021-08-31 18:43:31 +05:30
export default RoomSelector;