bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/menu/component.jsx

161 lines
4.6 KiB
React
Raw Normal View History

2021-07-08 19:41:03 +08:00
import React from "react";
import PropTypes from "prop-types";
import { defineMessages, injectIntl } from "react-intl";
import Menu from "@material-ui/core/Menu";
import MenuItem from "@material-ui/core/MenuItem";
import { Divider } from "@material-ui/core";
import Icon from "/imports/ui/components/icon/component";
import Button from "/imports/ui/components/button/component";
import { styles } from "./styles";
const intlMessages = defineMessages({
close: {
id: 'app.dropdown.close',
description: 'Close button label',
},
});
//Used to switch to mobile view
2021-07-08 19:41:03 +08:00
const MAX_WIDTH = 640;
class BBBMenu extends React.Component {
constructor(props) {
super(props);
this.state = {
anchorEl: null,
};
this.setAnchorEl = this.setAnchorEl.bind(this);
this.handleClick = this.handleClick.bind(this);
this.handleClose = this.handleClose.bind(this);
}
handleClick(event) {
this.setState({ anchorEl: event.currentTarget });
2021-07-08 19:41:03 +08:00
};
2021-07-08 19:41:03 +08:00
handleClose() {
const { onCloseCallback } = this.props;
this.setState({ anchorEl: null }, onCloseCallback());
2021-07-08 19:41:03 +08:00
};
setAnchorEl(el) {
console.log(el)
debugger
2021-07-08 19:41:03 +08:00
this.setState({ anchorEl: el });
};
makeMenuItems() {
const { actions, selectedEmoji } = this.props;
2021-07-08 19:41:03 +08:00
return actions?.map(a => {
const { dataTest, label, onClick, key, disabled } = a;
const itemClasses = [styles.menuitem, a?.className];
if (key?.toLowerCase()?.includes(selectedEmoji?.toLowerCase())) itemClasses.push(styles.emojiSelected);
return [
a.dividerTop && <Divider disabled />,
<MenuItem
key={label}
data-test={dataTest}
className={itemClasses.join(' ')}
disableRipple={true}
disableGutters={true}
disabled={disabled}
style={{ paddingLeft: '4px',paddingRight: '4px',paddingTop: '8px', paddingBottom: '8px', marginLeft: '4px', marginRight: '4px' }}
onClick={() => {
onClick();
const close = !key.includes('setstatus') && !key.includes('back');
// prevent menu close for sub menu actions
if (close) this.handleClose();
}}>
2021-07-08 19:41:03 +08:00
<div style={{ display: 'flex', flexFlow: 'row', width: '100%'}}>
{a.icon ? <Icon iconName={a.icon} key="icon" /> : null}
2021-07-21 01:48:08 +08:00
<div className={styles.option}>{label}</div>
2021-07-08 19:41:03 +08:00
{a.iconRight ? <Icon iconName={a.iconRight} key="iconRight" className={styles.iRight} /> : null}
</div>
</MenuItem>,
a.divider && <Divider disabled />
];
2021-07-08 19:41:03 +08:00
});
}
2021-07-08 19:41:03 +08:00
render() {
const { anchorEl } = this.state;
const { trigger, intl, opts, wide, classes } = this.props;
2021-07-08 19:41:03 +08:00
const actionsItems = this.makeMenuItems();
const menuClasses = classes || [];
menuClasses.push(styles.menu);
2021-08-09 01:22:01 +08:00
if (wide) menuClasses.push(styles.wide);
2021-07-08 19:41:03 +08:00
return (
<div>
2021-08-09 01:22:01 +08:00
<div onClick={this.handleClick} accessKey={this.props?.accessKey}>{trigger}</div>
2021-07-08 19:41:03 +08:00
<Menu
{...opts}
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={this.handleClose}
className={menuClasses.join(' ')}
2021-07-08 19:41:03 +08:00
>
{actionsItems}
{anchorEl && window.innerWidth < MAX_WIDTH &&
2021-07-08 19:41:03 +08:00
<Button
className={styles.closeBtn}
label={intl.formatMessage(intlMessages.close)}
size="lg"
color="default"
onClick={this.handleClose}
/>
}
</Menu>
</div>
);
}
}
export default injectIntl(BBBMenu);
BBBMenu.defaultProps = {
opts: {
id: "default-dropdown-menu",
keepMounted: true,
transitionDuration: 0,
elevation: 3,
getContentAnchorEl: null,
fullwidth: "true",
anchorOrigin: { vertical: 'top', horizontal: 'right' },
transformorigin: { vertical: 'top', horizontal: 'right' },
2021-07-08 19:41:03 +08:00
},
onCloseCallback: () => {},
wide: false,
2021-07-08 19:41:03 +08:00
};
BBBMenu.propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
trigger: PropTypes.element.isRequired,
actions: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
icon: PropTypes.string,
iconRight: PropTypes.string,
disabled: PropTypes.bool,
2021-07-08 19:41:03 +08:00
divider: PropTypes.bool,
dividerTop: PropTypes.bool,
2021-08-09 01:22:01 +08:00
accessKey: PropTypes.string,
2021-07-08 19:41:03 +08:00
})).isRequired,
onCloseCallback: PropTypes.func,
wide: PropTypes.bool,
2021-07-08 19:41:03 +08:00
};