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

251 lines
6.5 KiB
React
Raw Normal View History

2017-09-23 14:27:55 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
2018-01-11 03:22:42 +08:00
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import _ from 'lodash';
2018-01-08 14:17:18 +08:00
import { styles } from '../styles';
2017-09-23 14:27:55 +08:00
import ToolbarSubmenuItem from '../toolbar-submenu-item/component';
2017-12-08 21:28:02 +08:00
const intlMessages = defineMessages({
2018-09-06 03:28:10 +08:00
toolHand: {
id: 'app.whiteboard.toolbar.tools.hand',
description: 'Tool submenu hand item',
2017-12-08 21:28:02 +08:00
},
toolPencil: {
id: 'app.whiteboard.toolbar.tools.pencil',
description: 'Tool submenu pencil annotation',
2017-12-08 21:28:02 +08:00
},
toolRectangle: {
id: 'app.whiteboard.toolbar.tools.rectangle',
description: 'Tool submenu rectangle annotation',
2017-12-08 21:28:02 +08:00
},
toolTriangle: {
id: 'app.whiteboard.toolbar.tools.triangle',
description: 'Tool submenu triangle annotation',
2017-12-08 21:28:02 +08:00
},
toolEllipse: {
id: 'app.whiteboard.toolbar.tools.ellipse',
description: 'Tool submenu ellipse annotation',
2017-12-08 21:28:02 +08:00
},
toolLine: {
id: 'app.whiteboard.toolbar.tools.line',
description: 'Tool submenu line annotation',
2017-12-08 21:28:02 +08:00
},
toolText: {
id: 'app.whiteboard.toolbar.tools.text',
description: 'Tool submenu text annotation',
2017-12-08 21:28:02 +08:00
},
colorBlack: {
id: 'app.whiteboard.toolbar.color.black',
description: 'Color submenu black color',
2017-12-08 21:28:02 +08:00
},
colorWhite: {
id: 'app.whiteboard.toolbar.color.white',
description: 'Color submenu white color',
2017-12-08 21:28:02 +08:00
},
colorRed: {
id: 'app.whiteboard.toolbar.color.red',
description: 'Color submenu red color',
2017-12-08 21:28:02 +08:00
},
colorOrange: {
id: 'app.whiteboard.toolbar.color.orange',
description: 'Color submenu orange color',
2017-12-08 21:28:02 +08:00
},
colorEletricLime: {
id: 'app.whiteboard.toolbar.color.eletricLime',
description: 'Color submenu eletric lime color',
2017-12-08 21:28:02 +08:00
},
colorLime: {
id: 'app.whiteboard.toolbar.color.lime',
description: 'Color submenu lime color',
2017-12-08 21:28:02 +08:00
},
colorCyan: {
id: 'app.whiteboard.toolbar.color.cyan',
description: 'Color submenu cyan color',
2017-12-08 21:28:02 +08:00
},
colorDodgerBlue: {
id: 'app.whiteboard.toolbar.color.dodgerBlue',
description: 'Color submenu dodger blue color',
2017-12-08 21:28:02 +08:00
},
colorBlue: {
id: 'app.whiteboard.toolbar.color.blue',
description: 'Color submenu blue color',
2017-12-08 21:28:02 +08:00
},
colorViolet: {
id: 'app.whiteboard.toolbar.color.violet',
description: 'Color submenu violet color',
2017-12-08 21:28:02 +08:00
},
colorMagenta: {
id: 'app.whiteboard.toolbar.color.magenta',
description: 'Color submenu magenta color',
2017-12-08 21:28:02 +08:00
},
colorSilver: {
id: 'app.whiteboard.toolbar.color.silver',
description: 'Color submenu silver color',
2017-12-08 21:28:02 +08:00
},
});
class ToolbarSubmenu extends Component {
2017-09-23 14:27:55 +08:00
static getCustomIcon(type, obj) {
if (type === 'color') {
return (
<svg className={styles.customSvgIcon}>
<rect x="20%" y="20%" width="60%" height="60%" fill={obj.value} />
</svg>
);
2018-12-06 01:42:31 +08:00
} if (type === 'thickness') {
2017-09-23 14:27:55 +08:00
return (
<svg className={styles.customSvgIcon}>
<circle cx="50%" cy="50%" r={obj.value} />
2017-09-23 14:27:55 +08:00
</svg>
);
2018-12-06 01:42:31 +08:00
} if (type === 'font-size') {
2017-09-23 14:27:55 +08:00
return (
<p className={styles.textThickness} style={{ fontSize: obj.value }}>
Aa
</p>
);
}
return null;
}
static getWrapperClassNames(type) {
2018-12-06 01:42:31 +08:00
if (type === 'font-size') {
2017-09-23 14:27:55 +08:00
return cx(styles.fontSizeList, styles.toolbarList);
2018-12-06 01:42:31 +08:00
} if (
type === 'annotations'
|| type === 'thickness'
|| type === 'color'
) {
return styles.toolbarList;
2017-09-23 14:27:55 +08:00
}
return null;
}
2018-12-06 01:42:31 +08:00
2017-09-23 14:27:55 +08:00
constructor() {
super();
this.handleMouseEnter = this.handleMouseEnter.bind(this);
this.handleMouseLeave = this.handleMouseLeave.bind(this);
this.onItemClick = this.onItemClick.bind(this);
}
componentDidMount() {
const { handleMouseEnter } = this.props;
if (handleMouseEnter) {
handleMouseEnter();
}
}
2017-09-23 14:27:55 +08:00
onItemClick(objectToReturn) {
const { onItemClick } = this.props;
if (onItemClick) {
onItemClick(objectToReturn);
2017-09-23 14:27:55 +08:00
}
}
handleMouseEnter() {
const { handleMouseEnter } = this.props;
if (handleMouseEnter) {
handleMouseEnter();
2017-09-23 14:27:55 +08:00
}
}
handleMouseLeave() {
const { handleMouseLeave } = this.props;
if (handleMouseLeave) {
handleMouseLeave();
2017-09-23 14:27:55 +08:00
}
}
2017-12-08 21:28:02 +08:00
formatSubmenuLabel(type, obj) {
const { intl } = this.props;
2017-12-08 21:28:02 +08:00
if (type === 'annotations') {
const intlLabel = `tool${_.upperFirst(obj.value)}`;
2017-12-08 21:28:02 +08:00
return intl.formatMessage(intlMessages[intlLabel]);
}
if (type === 'color') {
const intlLabel = `color${_.upperFirst(obj.label)}`;
2017-12-08 21:28:02 +08:00
return intl.formatMessage(intlMessages[intlLabel]);
}
if (type === 'thickness' || type === 'font-size') {
2018-01-11 03:22:42 +08:00
return obj.value.toString();
}
return '';
2017-12-08 21:28:02 +08:00
}
2017-09-23 14:27:55 +08:00
render() {
const {
type,
objectsToRender,
objectSelected,
customIcon,
} = this.props;
2017-09-23 14:27:55 +08:00
return (
<div
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
className={ToolbarSubmenu.getWrapperClassNames(type)}
>
2018-12-06 01:42:31 +08:00
{objectsToRender ? objectsToRender.map(obj => (
<ToolbarSubmenuItem
label={this.formatSubmenuLabel(type, obj)}
icon={!customIcon ? obj.icon : null}
customIcon={customIcon ? ToolbarSubmenu.getCustomIcon(type, obj) : null}
onItemClick={this.onItemClick}
objectToReturn={obj}
className={cx(
styles.toolbarListButton,
objectSelected.value === obj.value ? styles.selectedListButton : '',
)}
key={obj.value}
/>
)) : null}
2017-09-23 14:27:55 +08:00
</div>
);
}
}
ToolbarSubmenu.propTypes = {
onItemClick: PropTypes.func.isRequired,
handleMouseEnter: PropTypes.func.isRequired,
handleMouseLeave: PropTypes.func.isRequired,
type: PropTypes.string.isRequired,
objectsToRender: PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.shape({
value: PropTypes.string.isRequired,
}),
PropTypes.shape({
value: PropTypes.number.isRequired,
}),
PropTypes.shape({
value: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
}),
]).isRequired).isRequired,
2017-09-23 14:27:55 +08:00
objectSelected: PropTypes.oneOfType([
PropTypes.shape({
value: PropTypes.string.isRequired,
}),
PropTypes.shape({
value: PropTypes.number.isRequired,
}),
PropTypes.shape({
value: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
}),
]).isRequired,
customIcon: PropTypes.bool.isRequired,
2018-01-11 03:22:42 +08:00
intl: intlShape.isRequired,
2017-09-23 14:27:55 +08:00
};
2017-12-08 21:28:02 +08:00
export default injectIntl(ToolbarSubmenu);