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 theme = themeStyle(this.props.theme);
|
2020-05-03 19:44:49 +02:00
|
|
|
|
|
|
|
const style = Object.assign({
|
2020-05-17 15:01:42 +02:00
|
|
|
// height: theme.toolbarHeight,
|
2020-05-03 19:44:49 +02:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderBottom: `1px solid ${theme.dividerColor}`,
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
}, this.props.style);
|
2017-11-30 01:03:10 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!key) key = `${o.type}_${i}`;
|
2018-06-14 09:52:12 +02:00
|
|
|
|
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
|
|
|
|
2020-06-01 23:01:10 +02:00
|
|
|
if (this.props.disabled) props.disabled = true;
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 10:14:33 +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;
|