2021-07-28 22:15:52 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import './ChannelSelector.scss';
|
|
|
|
|
|
|
|
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-29 17:27:55 +09:00
|
|
|
function ChannelSelectorWrapper({
|
|
|
|
isSelected, onClick, content, options,
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div className={`channel-selector${isSelected ? ' channel-selector--selected' : ''}`}>
|
|
|
|
<button
|
|
|
|
className="channel-selector__content"
|
|
|
|
type="button"
|
|
|
|
onClick={onClick}
|
2021-08-31 00:42:24 +09:00
|
|
|
onMouseUp={(e) => blurOnBubbling(e, '.channel-selector')}
|
2021-08-29 17:27:55 +09:00
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</button>
|
|
|
|
<div className="channel-selector__options">{options}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
ChannelSelectorWrapper.defaultProps = {
|
|
|
|
options: null,
|
|
|
|
};
|
|
|
|
ChannelSelectorWrapper.propTypes = {
|
|
|
|
isSelected: PropTypes.bool.isRequired,
|
|
|
|
onClick: PropTypes.func.isRequired,
|
|
|
|
content: PropTypes.node.isRequired,
|
|
|
|
options: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
2021-07-28 22:15:52 +09:00
|
|
|
function ChannelSelector({
|
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-29 17:27:55 +09:00
|
|
|
<ChannelSelectorWrapper
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
ChannelSelector.defaultProps = {
|
|
|
|
imageSrc: null,
|
2021-08-29 17:27:55 +09:00
|
|
|
iconSrc: null,
|
|
|
|
options: null,
|
2021-07-28 22:15:52 +09:00
|
|
|
};
|
|
|
|
ChannelSelector.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,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChannelSelector;
|