bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/whiteboard-toolbar/toolbar-submenu-item/component.jsx

99 lines
2.6 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Button from '/imports/ui/components/button/component';
import _ from 'lodash';
2018-01-08 14:17:18 +08:00
import { styles } from '../styles';
2017-09-23 14:27:55 +08:00
export default class ToolbarSubmenuItem extends Component {
constructor() {
super();
this.handleTouchStart = this.handleTouchStart.bind(this);
this.handleOnMouseUp = this.handleOnMouseUp.bind(this);
this.setRef = this.setRef.bind(this);
}
// generating a unique ref string for the toolbar-item
componentWillMount() {
this.uniqueRef = _.uniqueId('toolbar-submenu-item');
}
componentDidMount() {
// adding and removing touchstart events can be done via standard React way
// by passing onTouchStart={this.funcName} once they stop triggering mousedown events
// see https://github.com/facebook/react/issues/9809
this[this.uniqueRef].addEventListener('touchstart', this.handleTouchStart);
}
componentWillUnmount() {
this[this.uniqueRef].removeEventListener('touchstart', this.handleTouchStart);
}
setRef(ref) {
this[this.uniqueRef] = ref;
}
// we have to use touchStart and on mouseUp in order to be able to use the toolbar
// with the text shape on mobile devices
// (using the toolbar while typing text shouldn't move focus out of the textarea)
handleTouchStart(event) {
event.preventDefault();
const { objectToReturn, onItemClick } = this.props;
// returning the selected object
onItemClick(objectToReturn);
}
handleOnMouseUp() {
const { objectToReturn, onItemClick } = this.props;
// returning the selected object
2017-09-21 05:05:17 +08:00
onItemClick(objectToReturn);
}
render() {
const {
className,
customIcon,
icon,
label,
} = this.props;
2017-12-08 21:28:02 +08:00
return (
<div className={styles.buttonWrapper}>
<Button
hideLabel
role="button"
color="default"
size="md"
2017-12-08 21:28:02 +08:00
label={label}
aria-label={label}
icon={icon}
customIcon={customIcon}
onMouseUp={this.handleOnMouseUp}
onKeyPress={this.handleOnMouseUp}
2017-12-08 21:28:02 +08:00
className={className}
setRef={this.setRef}
/>
</div>
);
}
}
2017-09-23 14:27:55 +08:00
ToolbarSubmenuItem.propTypes = {
label: PropTypes.string.isRequired,
icon: PropTypes.string,
customIcon: PropTypes.node,
onItemClick: PropTypes.func.isRequired,
objectToReturn: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.number,
2017-09-23 14:27:55 +08:00
]).isRequired,
className: PropTypes.string.isRequired,
};
2017-09-23 14:27:55 +08:00
ToolbarSubmenuItem.defaultProps = {
icon: null,
customIcon: null,
};