1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ElectronClient/gui/ToolbarBase.tsx

92 lines
2.4 KiB
TypeScript
Raw Normal View History

const React = require('react');
const { connect } = require('react-redux');
const { themeStyle } = require('lib/theme');
2020-09-15 15:01:07 +02:00
const ToolbarButton = require('./ToolbarButton/ToolbarButton.js').default;
const ToolbarSpace = require('./ToolbarSpace.min.js');
2020-09-15 15:01:07 +02:00
const ToggleEditorsButton = require('./ToggleEditorsButton/ToggleEditorsButton.js').default;
interface Props {
themeId: number,
style: any,
items: any[],
}
class ToolbarBaseComponent extends React.Component<Props, any> {
render() {
2020-09-15 15:01:07 +02:00
const theme = themeStyle(this.props.themeId);
const style:any = Object.assign({
display: 'flex',
flexDirection: 'row',
boxSizing: 'border-box',
2020-09-15 15:01:07 +02:00
backgroundColor: theme.backgroundColor3,
padding: theme.toolbarPadding,
paddingRight: theme.mainPadding,
}, this.props.style);
const groupStyle:any = {
2020-09-15 15:01:07 +02:00
display: 'flex',
flexDirection: 'row',
boxSizing: 'border-box',
};
const leftItemComps:any[] = [];
const centerItemComps:any[] = [];
const rightItemComps:any[] = [];
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}`;
const props = Object.assign(
{
key: key,
2020-09-15 15:01:07 +02:00
themeId: this.props.themeId,
},
o
);
2020-09-15 15:01:07 +02:00
if (o.name === 'toggleEditors') {
rightItemComps.push(<ToggleEditorsButton
key={o.name}
value={'markdown'}
themeId={this.props.themeId}
toolbarButtonInfo={o}
/>);
} else if (itemType === 'button') {
const target = ['historyForward', 'historyBackward', 'toggleExternalEditing'].includes(o.name) ? leftItemComps : centerItemComps;
2020-09-15 15:01:07 +02:00
target.push(<ToolbarButton {...props} />);
} else if (itemType === 'separator') {
2020-09-15 15:01:07 +02:00
centerItemComps.push(<ToolbarSpace {...props} />);
}
}
}
return (
<div className="editor-toolbar" style={style}>
2020-09-15 15:01:07 +02:00
<div style={groupStyle}>
{leftItemComps}
</div>
<div style={groupStyle}>
{centerItemComps}
</div>
<div style={Object.assign({}, groupStyle, { flex: 1, justifyContent: 'flex-end' })}>
{rightItemComps}
</div>
</div>
);
}
}
const mapStateToProps = (state:any) => {
2020-09-15 15:01:07 +02:00
return { themeId: state.settings.theme };
};
export default connect(mapStateToProps)(ToolbarBaseComponent);