jiti-meet/react/features/toolbox/components/web/OverflowMenuProfileItem.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-03-19 15:42:25 +00:00
// @flow
import React, { Component } from 'react';
2019-03-21 16:38:29 +00:00
2019-06-26 14:08:23 +00:00
import { Avatar } from '../../../base/avatar';
import { getLocalParticipant } from '../../../base/participants';
2019-03-21 16:38:29 +00:00
import { connect } from '../../../base/redux';
declare var interfaceConfig: Object;
/**
* The type of the React {@code Component} props of
* {@link OverflowMenuProfileItem}.
*/
type Props = {
/**
* The redux representation of the local participant.
*/
_localParticipant: Object,
/**
* Whether the button support clicking or not.
*/
_unclickable: boolean,
/**
* The callback to invoke when {@code OverflowMenuProfileItem} is
* clicked.
*/
onClick: Function
};
/**
* A React {@code Component} for displaying a link with a profile avatar as an
* icon.
*
* @extends Component
*/
class OverflowMenuProfileItem extends Component<Props> {
/**
* Initializes a new {@code OverflowMenuProfileItem} instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
*/
constructor(props: Props) {
super(props);
// Bind event handler so it is only bound once for every instance.
this._onClick = this._onClick.bind(this);
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { _localParticipant, _unclickable } = this.props;
const classNames = `overflow-menu-item ${
_unclickable ? 'unclickable' : ''}`;
let displayName;
if (_localParticipant && _localParticipant.name) {
displayName = _localParticipant.name;
} else {
displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
}
return (
<li
fix(i18n) Accessiblity labels translations (#3071) * fix(toolbar): accessibilityLabel should be translatable. This commit adds a helper property to get the accessibilityLabel of an item, providing a translation if one is available. This mimics the behavior of label and tooltip. * fix(toolbar) 'hangup' button accessibilityLabel i18n * fix(toolbar) 'mute' button accessibilityLabel i18n * fix(toolbar) 'videomute' button accessibilityLabel i18n * fix(toolbar) 'moreActions' button accessibilityLabel i18n * fix(toolbar) 'shareRoom' button accessibilityLabel i18n * fix(toolbar) 'audioRoute' button accessibilityLabel i18n * fix(toolbar) 'toggleCamera' button accessibilityLabel i18n * fix(toolbar) 'audioOnly' button accessibilityLabel i18n * fix(toolbar) 'roomLock' button accessibilityLabel i18n * fix(toolbar) 'pip' button accessibilityLabel i18n * fix(toolbar) 'invite' button accessibilityLabel i18n * fix(toolbar) 'raiseHand' button accessibilityLabel i18n * fix(toolbar) 'chat' button accessibilityLabel i18n * fix(toolbar) 'shareYourScreen' button accessibilityLabel i18n * fix(toolbar) 'fullScreen' button accessibilityLabel i18n * fix(toolbar) 'sharedvideo' button accessibilityLabel i18n * fix(toolbar) 'document' button accessibilityLabel i18n * fix(toolbar) 'speakerStats' button accessibilityLabel i18n * fix(toolbar) 'feedback' button accessibilityLabel i18n * fix(toolbar) 'shortcuts' button accessibilityLabel i18n * fix(toolbar) 'recording' button accessibilityLabel i18n * fix(toolbar) 'settings' button accessibilityLabel i18n * fix(welcomepage) accessibilityLabels i18n * fix(toolbar) 'info' button accessibilityLabel i18n * fix(i18n): Add translation to various aria-label property values. * fix(i18n): Differentiate between overflow menu and button.
2018-06-07 20:32:18 +00:00
aria-label = 'Edit your profile'
className = { classNames }
onClick = { this._onClick }>
<span className = 'overflow-menu-item-icon'>
2019-06-26 14:08:23 +00:00
<Avatar
participantId = { _localParticipant.id }
size = { 24 } />
</span>
<span className = 'profile-text'>
{ displayName }
</span>
</li>
);
}
_onClick: () => void;
/**
* Invokes an on click callback if clicking is allowed.
*
* @returns {void}
*/
_onClick() {
if (!this.props._unclickable) {
this.props.onClick();
}
}
}
/**
* Maps (parts of) the Redux state to the associated
* {@code OverflowMenuProfileItem} component's props.
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
* _localParticipant: Object,
* _unclickable: boolean
* }}
*/
function _mapStateToProps(state) {
return {
_localParticipant: getLocalParticipant(state),
_unclickable: !state['features/base/jwt'].isGuest
|| !interfaceConfig.SETTINGS_SECTIONS.includes('profile')
};
}
export default connect(_mapStateToProps)(OverflowMenuProfileItem);