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

96 lines
2.5 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
2021-11-03 01:27:25 +08:00
import Styled 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);
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 {
customIcon,
icon,
label,
2021-11-03 04:05:49 +08:00
toolbarActive,
} = this.props;
2017-12-08 21:28:02 +08:00
return (
2021-11-03 01:27:25 +08:00
<Styled.ButtonWrapper>
<Styled.SubmenuButton
2021-11-03 04:05:49 +08:00
state={toolbarActive ? 'selected' : 'unselected'}
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}
setRef={this.setRef}
/>
2021-11-03 01:27:25 +08:00
</Styled.ButtonWrapper>
);
}
}
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,
2021-11-03 01:27:25 +08:00
selected: PropTypes.bool,
};
2017-09-23 14:27:55 +08:00
ToolbarSubmenuItem.defaultProps = {
icon: null,
customIcon: null,
2021-11-03 01:27:25 +08:00
selected: false,
};