2017-11-30 01:03:10 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const { themeStyle } = require('../theme.js');
|
|
|
|
const ToolbarButton = require('./ToolbarButton.min.js');
|
2018-06-14 09:52:12 +02:00
|
|
|
const ToolbarSpace = require('./ToolbarSpace.min.js');
|
2017-11-30 01:03:10 +02:00
|
|
|
|
|
|
|
class ToolbarComponent extends React.Component {
|
|
|
|
render() {
|
|
|
|
const style = this.props.style;
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
style.height = theme.toolbarHeight;
|
|
|
|
style.display = 'flex';
|
2019-07-29 14:13:23 +02:00
|
|
|
style.flexDirection = 'row';
|
2017-11-30 01:03:10 +02:00
|
|
|
style.borderBottom = '1px solid ' + theme.dividerColor;
|
|
|
|
style.boxSizing = 'border-box';
|
|
|
|
|
|
|
|
const itemComps = [];
|
|
|
|
|
|
|
|
if (this.props.items) {
|
|
|
|
for (let i = 0; i < this.props.items.length; i++) {
|
|
|
|
const o = this.props.items[i];
|
|
|
|
let key = o.iconName ? o.iconName : '';
|
|
|
|
key += o.title ? o.title : '';
|
|
|
|
const itemType = !('type' in o) ? 'button' : o.type;
|
|
|
|
|
2018-06-14 09:52:12 +02:00
|
|
|
if (!key) key = o.type + '_' + i;
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
const props = Object.assign(
|
|
|
|
{
|
|
|
|
key: key,
|
|
|
|
theme: this.props.theme,
|
|
|
|
},
|
|
|
|
o
|
|
|
|
);
|
2017-11-30 01:03:10 +02:00
|
|
|
|
|
|
|
if (itemType === 'button') {
|
2018-06-14 09:52:12 +02:00
|
|
|
itemComps.push(<ToolbarButton {...props} />);
|
|
|
|
} else if (itemType === 'separator') {
|
|
|
|
itemComps.push(<ToolbarSpace {...props} />);
|
2017-11-30 01:03:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="editor-toolbar" style={style}>
|
2019-07-29 14:13:23 +02:00
|
|
|
{itemComps}
|
2017-11-30 01:03:10 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
const mapStateToProps = state => {
|
2017-11-30 01:03:10 +02:00
|
|
|
return { theme: state.settings.theme };
|
|
|
|
};
|
|
|
|
|
|
|
|
const Toolbar = connect(mapStateToProps)(ToolbarComponent);
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
module.exports = Toolbar;
|