2021-07-28 22:15:52 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-08-31 22:13:31 +09:00
|
|
|
import './RoomSelector.scss';
|
2021-07-28 22:15:52 +09:00
|
|
|
|
|
|
|
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 22:13:31 +09:00
|
|
|
function RoomSelectorWrapper({
|
2021-08-29 17:27:55 +09:00
|
|
|
isSelected, onClick, content, options,
|
|
|
|
}) {
|
|
|
|
return (
|
2021-08-31 22:13:31 +09:00
|
|
|
<div className={`room-selector${isSelected ? ' room-selector--selected' : ''}`}>
|
2021-08-29 17:27:55 +09:00
|
|
|
<button
|
2021-08-31 22:13:31 +09:00
|
|
|
className="room-selector__content"
|
2021-08-29 17:27:55 +09:00
|
|
|
type="button"
|
|
|
|
onClick={onClick}
|
2021-08-31 22:13:31 +09:00
|
|
|
onMouseUp={(e) => blurOnBubbling(e, '.room-selector')}
|
2021-08-29 17:27:55 +09:00
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</button>
|
2021-08-31 22:13:31 +09:00
|
|
|
<div className="room-selector__options">{options}</div>
|
2021-08-29 17:27:55 +09:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-08-31 22:13:31 +09:00
|
|
|
RoomSelectorWrapper.defaultProps = {
|
2021-08-29 17:27:55 +09:00
|
|
|
options: null,
|
|
|
|
};
|
2021-08-31 22:13:31 +09:00
|
|
|
RoomSelectorWrapper.propTypes = {
|
2021-08-29 17:27:55 +09:00
|
|
|
isSelected: PropTypes.bool.isRequired,
|
|
|
|
onClick: PropTypes.func.isRequired,
|
|
|
|
content: PropTypes.node.isRequired,
|
|
|
|
options: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
2021-08-31 22:13:31 +09:00
|
|
|
function RoomSelector({
|
2021-08-29 17:27:55 +09:00
|
|
|
name, roomId, imageSrc, iconSrc,
|
|
|
|
isSelected, isUnread, notificationCount, isAlert,
|
|
|
|
options, onClick,
|
2021-07-28 22:15:52 +09:00
|
|
|
}) {
|
|
|
|
return (
|
2021-08-31 22:13:31 +09:00
|
|
|
<RoomSelectorWrapper
|
2021-08-29 17:27:55 +09:00
|
|
|
isSelected={isSelected}
|
|
|
|
content={(
|
|
|
|
<>
|
2021-07-28 22:15:52 +09:00
|
|
|
<Avatar
|
2021-08-29 17:27:55 +09:00
|
|
|
text={name.slice(0, 1)}
|
2021-07-28 22:15:52 +09:00
|
|
|
bgColor={colorMXID(roomId)}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
iconSrc={iconSrc}
|
|
|
|
size="extra-small"
|
|
|
|
/>
|
2021-08-29 17:27:55 +09:00
|
|
|
<Text variant="b1">{name}</Text>
|
|
|
|
{ isUnread && (
|
2021-08-28 21:46:20 +09:00
|
|
|
<NotificationBadge
|
2021-08-29 17:27:55 +09:00
|
|
|
alert={isAlert}
|
2021-08-28 21:46:20 +09:00
|
|
|
content={notificationCount !== 0 ? notificationCount : null}
|
|
|
|
/>
|
|
|
|
)}
|
2021-08-29 17:27:55 +09:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
options={options}
|
|
|
|
onClick={onClick}
|
|
|
|
/>
|
2021-07-28 22:15:52 +09:00
|
|
|
);
|
|
|
|
}
|
2021-08-31 22:13:31 +09:00
|
|
|
RoomSelector.defaultProps = {
|
2021-07-28 22:15:52 +09:00
|
|
|
imageSrc: null,
|
2021-08-29 17:27:55 +09:00
|
|
|
iconSrc: null,
|
|
|
|
options: null,
|
2021-07-28 22:15:52 +09:00
|
|
|
};
|
2021-08-31 22:13:31 +09:00
|
|
|
RoomSelector.propTypes = {
|
2021-08-29 17:27:55 +09:00
|
|
|
name: PropTypes.string.isRequired,
|
2021-07-28 22:15:52 +09:00
|
|
|
roomId: PropTypes.string.isRequired,
|
2021-08-29 17:27:55 +09:00
|
|
|
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 22:15:52 +09:00
|
|
|
onClick: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-08-31 22:13:31 +09:00
|
|
|
export default RoomSelector;
|