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';
|
2017-12-16 01:14:21 +08:00
|
|
|
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',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu pencil annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
toolRectangle: {
|
|
|
|
id: 'app.whiteboard.toolbar.tools.rectangle',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu rectangle annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
toolTriangle: {
|
|
|
|
id: 'app.whiteboard.toolbar.tools.triangle',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu triangle annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
toolEllipse: {
|
|
|
|
id: 'app.whiteboard.toolbar.tools.ellipse',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu ellipse annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
toolLine: {
|
|
|
|
id: 'app.whiteboard.toolbar.tools.line',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu line annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
toolText: {
|
|
|
|
id: 'app.whiteboard.toolbar.tools.text',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Tool submenu text annotation',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorBlack: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.black',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu black color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorWhite: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.white',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu white color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorRed: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.red',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu red color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorOrange: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.orange',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu orange color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorEletricLime: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.eletricLime',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu eletric lime color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorLime: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.lime',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu lime color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorCyan: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.cyan',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu cyan color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorDodgerBlue: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.dodgerBlue',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu dodger blue color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorBlue: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.blue',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu blue color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorViolet: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.violet',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu violet color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorMagenta: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.magenta',
|
2017-12-16 01:14:21 +08:00
|
|
|
description: 'Color submenu magenta color',
|
2017-12-08 21:28:02 +08:00
|
|
|
},
|
|
|
|
colorSilver: {
|
|
|
|
id: 'app.whiteboard.toolbar.color.silver',
|
2017-12-16 01:14:21 +08:00
|
|
|
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}>
|
2018-04-05 02:18:46 +08:00
|
|
|
<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);
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemClick(objectToReturn) {
|
|
|
|
if (this.props.onItemClick) {
|
|
|
|
this.props.onItemClick(objectToReturn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseEnter() {
|
|
|
|
if (this.props.handleMouseEnter) {
|
|
|
|
this.props.handleMouseEnter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseLeave() {
|
|
|
|
if (this.props.handleMouseLeave) {
|
|
|
|
this.props.handleMouseLeave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 21:28:02 +08:00
|
|
|
formatSubmenuLabel(type, obj) {
|
2017-12-16 01:14:21 +08:00
|
|
|
const { intl } = this.props;
|
2017-12-08 21:28:02 +08:00
|
|
|
|
|
|
|
if (type === 'annotations') {
|
2017-12-16 01:14:21 +08:00
|
|
|
const intlLabel = `tool${_.upperFirst(obj.value)}`;
|
2017-12-08 21:28:02 +08:00
|
|
|
return intl.formatMessage(intlMessages[intlLabel]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type === 'color') {
|
2017-12-16 01:14:21 +08:00
|
|
|
const intlLabel = `color${_.upperFirst(obj.label)}`;
|
2017-12-08 21:28:02 +08:00
|
|
|
return intl.formatMessage(intlMessages[intlLabel]);
|
|
|
|
}
|
|
|
|
|
2018-01-11 18:51:37 +08:00
|
|
|
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() {
|
2017-12-16 01:14:21 +08:00
|
|
|
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,
|
2018-04-05 02:18:46 +08:00
|
|
|
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,
|
|
|
|
label: PropTypes.string.isRequired,
|
2017-10-04 05:28:44 +08:00
|
|
|
customIcon: PropTypes.bool.isRequired,
|
2017-12-16 01:14:21 +08:00
|
|
|
|
2018-01-11 03:22:42 +08:00
|
|
|
intl: intlShape.isRequired,
|
2017-12-16 01:14:21 +08:00
|
|
|
|
2017-09-23 14:27:55 +08:00
|
|
|
};
|
2017-12-08 21:28:02 +08:00
|
|
|
|
|
|
|
export default injectIntl(ToolbarSubmenu);
|