bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/user-avatar/component.jsx

116 lines
2.9 KiB
React
Raw Normal View History

import React, { Component, PropTypes } from 'react';
2016-07-06 00:54:45 +08:00
import Icon from '/imports/ui/components/icon/component';
import styles from './styles.scss';
import cx from 'classnames';
import generateColor from './color-generator';
const propTypes = {
user: React.PropTypes.shape({
name: React.PropTypes.string.isRequired,
isPresenter: React.PropTypes.bool.isRequired,
isVoiceUser: React.PropTypes.bool.isRequired,
isModerator: React.PropTypes.bool.isRequired,
image: React.PropTypes.string,
}).isRequired,
};
const defaultProps = {
};
export default class UserAvatar extends Component {
render() {
2016-07-09 03:09:16 +08:00
const {
user,
2016-07-09 03:09:16 +08:00
} = this.props;
2016-07-05 04:44:29 +08:00
const avatarColor = !user.isLoggedOut ? generateColor(user.name) : '#fff';
2016-07-05 04:44:29 +08:00
let avatarStyles = {
backgroundColor: avatarColor,
boxShadow: user.isTalking ? `0 0 .5rem ${avatarColor}` : 'none',
2016-07-05 04:44:29 +08:00
};
return (
<div className={!user.isLoggedOut ? styles.userAvatar : styles.userLogout}
2017-04-15 02:46:56 +08:00
style={avatarStyles}>
<div>{this.renderAvatarContent()}</div>
2016-07-09 03:09:16 +08:00
{this.renderUserStatus()}
{this.renderUserMediaStatus()}
</div>
);
}
2016-07-06 00:54:45 +08:00
renderAvatarContent() {
2016-07-09 03:09:16 +08:00
const user = this.props.user;
2016-07-06 00:54:45 +08:00
2017-04-15 02:46:56 +08:00
let content = <span aria-hidden="true">{user.name.slice(0, 2)}</span>;
2016-07-06 00:54:45 +08:00
if (user.emoji.status !== 'none') {
2017-04-06 22:42:01 +08:00
let iconEmoji = undefined;
switch (user.emoji.status) {
case 'thumbsUp':
iconEmoji = 'thumbs_up';
break;
case 'thumbsDown':
iconEmoji = 'thumbs_down';
break;
case 'raiseHand':
iconEmoji = 'hand';
break;
case 'away':
iconEmoji = 'time';
break;
case 'neutral':
iconEmoji = 'undecided';
break;
default:
iconEmoji = user.emoji.status;
}
2017-04-15 02:46:56 +08:00
content = <span aria-label={user.emoji.status}><Icon iconName={iconEmoji}/></span>;
2016-07-06 00:54:45 +08:00
}
return content;
}
2016-07-09 03:09:16 +08:00
renderUserStatus() {
const user = this.props.user;
let userStatus;
let userStatusClasses = {};
userStatusClasses[styles.moderator] = user.isModerator;
userStatusClasses[styles.presenter] = user.isPresenter;
if (user.isModerator || user.isPresenter) {
userStatus = (
<span className={cx(styles.userStatus, userStatusClasses)}>
</span>
);
}
return userStatus;
}
renderUserMediaStatus() {
const user = this.props.user;
let userMediaStatus;
let userMediaClasses = {};
userMediaClasses[styles.voiceOnly] = user.isListenOnly;
userMediaClasses[styles.microphone] = user.isVoiceUser;
if (user.isListenOnly || user.isVoiceUser) {
userMediaStatus = (
<span className={cx(styles.userMediaStatus, userMediaClasses)}>
{user.isMuted ? <div className={styles.microphoneMuted}/> : null}
</span>
);
}
return userMediaStatus;
}
}
UserAvatar.propTypes = propTypes;
UserAvatar.defaultProps = defaultProps;