bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/modals/settings/SettingsModal.jsx

141 lines
4.9 KiB
React
Raw Normal View History

2016-05-06 05:14:39 +08:00
import React from 'react';
import Modal from 'react-modal';
import Icon from '/imports/ui/components/icon/component';
import Button from '/imports/ui/components/button/component';
import BaseModal from '../BaseModal';
import AudioMenu from './submenus/AudioMenu';
import VideoMenu from './submenus/VideoMenu';
import ApplicationMenu from './submenus/ApplicationMenu';
import UsersMenu from './submenus/UsersMenu';
import SessionMenu from './submenus/SessionMenu';
2016-05-06 05:14:39 +08:00
import classNames from 'classnames';
2016-05-07 01:46:14 +08:00
import ReactDOM from 'react-dom';
import styles from './styles';
2016-05-06 05:14:39 +08:00
export default class SettingsModal extends BaseModal {
constructor(props) {
super(props);
this.submenus = [];
}
componentWillMount() {
this.setState({ activeSubmenu: 0 });
this.submenus.push({ className: AudioMenu,
props: { title: 'Audio', prependIconName: 'icon-', icon: 'bbb-audio', }, tabIndex: 3, });
2016-05-06 05:14:39 +08:00
this.submenus.push({ className: VideoMenu,
props: { title: 'Video', prependIconName: 'icon-', icon: 'bbb-video', }, tabIndex: 4, });
2016-05-06 05:14:39 +08:00
this.submenus.push({ className: ApplicationMenu,
props: { title: 'Application', prependIconName: 'icon-', icon: 'bbb-application', }, tabIndex: 5, });
2016-05-06 05:14:39 +08:00
this.submenus.push({ className: UsersMenu,
props: { title: 'Participants', prependIconName: 'icon-', icon: 'bbb-user', }, tabIndex: 6, });
2016-05-06 05:14:39 +08:00
this.submenus.push({ className: SessionMenu,
props: { title: 'Leave session', prependIconName: 'icon-', icon: 'bbb-logout', }, tabIndex: 7, });
2016-05-06 05:14:39 +08:00
}
componentDidMount() {
ReactDOM.render(
<Button style={{ transform: 'rotate(90deg)' }}
onClick={this.openModal}
icon={'more'}
ghost={true}
circle={true}
hideLabel={true}
label={'Settings'}
aria-haspopup={'true'}
aria-labelledby={'settingsLabel'}
aria-describedby={'settingsDesc'}
/>
, document.getElementById('settingsButtonPlaceHolder'));
2016-05-06 05:14:39 +08:00
}
createMenu() {
const curr = this.state.activeSubmenu === undefined ? 0 : this.state.activeSubmenu;
let props = {
title: this.submenus[curr].props.title,
prependIconName: this.submenus[curr].props.prependIconName,
icon: this.submenus[curr].props.icon,
};
const Submenu = this.submenus[curr].className;
return <Submenu {...props}/>;
}
clickSubmenu(i) {
if (i <= 0) {
this.setState({ activeSubmenu: 0 });
}
if (i >= this.submenus.length) {
this.setState({ activeSubmenu: this.submenus.length - 1});
} else {
2016-05-06 05:14:39 +08:00
this.setState({ activeSubmenu: i });
2016-06-25 07:09:32 +08:00
if (this.submenus[i].className != SessionMenu) {
this.setState({ activeSubmenu: i });
};
2016-06-24 22:48:09 +08:00
}
doubleClickSubmenu(i) {
2016-06-25 07:09:32 +08:00
if (this.submenus[i].className == SessionMenu) {
this.setState({ activeSubmenu: i });
2016-06-24 22:48:09 +08:00
}
2016-05-06 05:14:39 +08:00
}
2016-07-12 01:43:42 +08:00
handleKeyDown(event) {
console.log(event.activeSubmenu);
if (event.keyCode == '38') { // up arrow
// if (this.state.activeSubmenu <= 0) {
// this.state.activeSubmenu = this.submenus.length - 1;
// this.clickSubmenu(this.state.activeSubmenu);
// } else {
// this.clickSubmenu(this.state.activeSubmenu - 1);
// }
if (this.state.activeSubmenu <= 0) {
this.state.activeSubmenu = this.submenus.length - 1;
this.refs.focus();
} else {
this.state.activeSubmenu - 1;
this.state.activeSubmenu.focus();
}
}
if (event.keyCode == '40') { // down arrow
if (this.state.activeSubmenu >= this.submenus.length - 1) {
this.state.activeSubmenu = 0;
this.clickSubmenu(this.state.activeSubmenu);
} else {
this.clickSubmenu(this.state.activeSubmenu + 1);
}
}
if (event.keyCode == '32' || event.keyCode == '13') { // space or enter key
alert("Enter key pressed.");
this.clickSubmenu(this.state.activeSubmenu);
}
}
2016-05-06 05:14:39 +08:00
getContent() {
return (
<div style={{ clear: 'both', height: '100%' }} role='presentation'>
2016-05-07 01:46:14 +08:00
<div className={styles.settingsMenuLeft}>
<ul style={{ listStyleType: 'none', paddingLeft: '0px' }} role='menu'>
2016-05-06 05:14:39 +08:00
{this.submenus.map((value, index) => (
<li key={index} onClick={this.clickSubmenu.bind(this, index)}
tabIndex={value.tabIndex} role='menuitem'
2016-06-24 22:48:09 +08:00
onDoubleClick={this.doubleClickSubmenu.bind(this, index)}
2016-05-07 01:46:14 +08:00
className={classNames(styles.settingsSubmenuItem,
2016-05-13 00:10:43 +08:00
index == this.state.activeSubmenu ? styles.settingsSubmenuItemActive : null)}>
2016-05-06 05:14:39 +08:00
<Icon key={index} prependIconName={value.props.prependIconName}
iconName={value.props.icon} title={value.props.title}/>
<span className={styles.settingsSubmenuItemText}>{value.props.title}</span>
2016-05-06 05:14:39 +08:00
</li>
))}
</ul>
</div>
<div className={styles.settingsMenuRight} role='presentation'>
{this.createMenu()}
</div>
2016-05-06 05:14:39 +08:00
</div>
);
}
};
2016-05-07 01:46:14 +08:00
SettingsModal.defaultProps = { title: 'Settings' };