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

89 lines
2.3 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
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-08-29 13:57:55 +05:30
isSelected, onClick, content, options,
}) {
return (
2021-08-31 18:43:31 +05:30
<div className={`room-selector${isSelected ? ' room-selector--selected' : ''}`}>
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,
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}
content={(
<>
2021-07-28 18:45:52 +05:30
<Avatar
2021-08-29 13:57:55 +05:30
text={name.slice(0, 1)}
2021-07-28 18:45:52 +05:30
bgColor={colorMXID(roomId)}
imageSrc={imageSrc}
iconSrc={iconSrc}
size="extra-small"
/>
2021-08-29 13:57:55 +05:30
<Text variant="b1">{name}</Text>
{ 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-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,
isSelected: PropTypes.bool.isRequired,
isUnread: PropTypes.bool.isRequired,
notificationCount: PropTypes.number.isRequired,
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;